Skip to content
Snippets Groups Projects
Commit be1532d3 authored by Swen Vermeul's avatar Swen Vermeul
Browse files

added some tests

parent 813e441d
No related branches found
No related tags found
No related merge requests found
import pytest import pytest
import time import time
import random
from pybis import Openbis from pybis import Openbis
...@@ -7,10 +8,24 @@ openbis_url = 'https://localhost:8443' ...@@ -7,10 +8,24 @@ openbis_url = 'https://localhost:8443'
admin_username = 'admin' admin_username = 'admin'
admin_password = 'changeit' admin_password = 'changeit'
@pytest.yield_fixture(scope="module")
def url():
yield openbis_url
@pytest.yield_fixture(scope="module")
def username():
yield admin_username
@pytest.yield_fixture(scope="module")
def password():
yield admin_password
@pytest.yield_fixture(scope="module") @pytest.yield_fixture(scope="module")
def openbis_instance(): def openbis_instance():
instance = Openbis(url=openbis_url, verify_certificates=False) instance = Openbis(url=openbis_url, verify_certificates=False)
instance.login(admin_username, admin_password)
print("\nLOGGING IN...") print("\nLOGGING IN...")
print(instance.is_session_active())
timestamp = time.strftime('%a_%y%m%d_%H%M%S').upper() timestamp = time.strftime('%a_%y%m%d_%H%M%S').upper()
space_code = 'test_space_' + timestamp space_code = 'test_space_' + timestamp
...@@ -22,11 +37,20 @@ def openbis_instance(): ...@@ -22,11 +37,20 @@ def openbis_instance():
project.save() project.save()
experiment_code = "TEST-EXPERIMENT-{:04d}".format(random.randint(0, 9999)) experiment_code = "TEST-EXPERIMENT-{:04d}".format(random.randint(0, 9999))
experiment = instance.new_experiment(code=experiment_code, space=space, project=project) experiment = instance.new_experiment(
code=experiment_code,
type='DEFAULT_EXPERIMENT',
project=project,
)
experiment.save() experiment.save()
sample_code = "TEST-SAMPLE-{:04d}".format(random.randint(0, 9999)) sample_code = "TEST-SAMPLE-{:04d}".format(random.randint(0, 9999))
sample = instance.new_sample(code=sample_code, space=space, project=project) sample = instance.new_sample(
code=sample_code,
type='UNKNOWN',
space=space,
experiment=experiment,
)
sample.save() sample.save()
instance.login(admin_username, admin_password) instance.login(admin_username, admin_password)
......
import pytest import pytest
import importlib import importlib
jupyterserver = importlib.import_module("jupyter-openbis-extension") js = importlib.import_module("jupyter-openbis-extension")
def test_conn(): def test_conn(url, username, password):
pass
conn = js.connection.OpenBISConnection(
name = "test-conn",
url = url,
username = username,
password = password,
verify_certificates = False,
)
info = conn.get_info()
assert isinstance(info, dict)
assert info['name'] == 'test-conn'
assert info['url'] == url
assert info['username'] == username
assert info['password'] == password
assert conn.status == 'not connected'
try:
conn.login()
except Exception:
pass
assert conn.status == 'connected'
assert conn.is_session_active() == True
def test_conn_login(url, username, password):
conn = js.connection.OpenBISConnection(
name = "test-conn",
url = url,
verify_certificates = False,
)
assert conn.status == 'not connected'
try:
conn.login(username, password)
except Exception:
pass
assert conn.status == "connected"
def test_dataset(openbis_instance):
pass
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment