Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pwalczysko committed Nov 19, 2024
1 parent efd4d1f commit dbd3ff8
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
1 change: 1 addition & 0 deletions molecule/ome-demoserver/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ scenario:
- destroy
verifier:
name: testinfra
directory: ../tests/
102 changes: 102 additions & 0 deletions molecule/tests/test_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import json
import os
import pytest
from time import sleep, time
import testinfra.utils.ansible_runner

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')


OMERO = '/opt/omero/server/OMERO.server/bin/omero'
ROOT_PASSWORD = 'ChangeMe'


def test_db_running_and_enabled(host):
if host.system_info.distribution == 'ubuntu':
service = host.service('postgresql@16-main')
else:
service = host.service('postgresql-16')
assert service.is_running
assert service.is_enabled


def test_srv_running_and_enabled(host):
service = host.service('omero-server')
assert service.is_running
assert service.is_enabled


def test_omero_login(host):
# Ubuntu sudo doesn't set HOME so it tries to write to /root
env = 'OMERO_USERDIR=/tmp/omero-{}'.format(time())
with host.sudo('omero-server'):
host.check_output(
'%s %s login -C -s localhost -u root -w %s' % (
env, OMERO, ROOT_PASSWORD))


@pytest.mark.parametrize('name', ['omero-web', 'nginx'])
def test_services_running_and_enabled(host, name):
service = host.service(name)
assert service.is_running
assert service.is_enabled


def test_omero_web_first_page(host):
out1 = host.check_output('curl -fsL http://localhost')
assert 'WEBCLIENT.active_group_id' in out1
out2 = host.check_output('curl -fsL http://localhost/webclient/login')
assert 'omero:4064' in out2


def get_cookie(cookietxt, name):
for line in cookietxt.splitlines():
tokens = line.split()
try:
if tokens[5] == name:
return tokens[6]
except IndexError:
pass


# https://github.com/openmicroscopy/omero-grid-docker/blob/0.1.0/test_login.sh
def test_omero_web_login(host):
LOGIN_URL = 'http://localhost/webclient/login/'
CURL = 'curl -f -i -k -s -c cookies.txt -b cookies.txt -e %s' % LOGIN_URL

for i in range(60):
sleep(2)
host.check_output('%s %s' % (CURL, LOGIN_URL))
csrf = get_cookie(host.file('cookies.txt').content_string, 'csrftoken')
if csrf:
break
assert csrf

data = '&'.join([
'csrfmiddlewaretoken=%s' % csrf,
'username=root',
'password=%s' % ROOT_PASSWORD,
'server=1',
'url=%2Fwebclient%2F',
])

for i in range(60):
sleep(2)
host.check_output('%s -d "%s" -X POST %s' % (
CURL, data, LOGIN_URL))
sessionid = get_cookie(
host.file('cookies.txt').content_string, 'sessionid')
if sessionid:
break
assert sessionid


def test_omero_web_public(host):
out = host.check_output(
'curl -f http://localhost/webclient/api/containers/')
r = json.loads(out)
assert r['screens'] == []
assert r['plates'] == []
assert r['projects'] == []
assert r['datasets'] == []

0 comments on commit dbd3ff8

Please sign in to comment.