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

tests added

parent 23b3ebdf
No related branches found
No related tags found
No related merge requests found
...@@ -2,14 +2,15 @@ import pytest ...@@ -2,14 +2,15 @@ import pytest
from pybis import Openbis from pybis import Openbis
openbis_url = 'https://localhost:8443'
admin_username = 'admin'
admin_password = '*****'
@pytest.yield_fixture(scope="module") @pytest.yield_fixture(scope="module")
def openbis_instance(): def openbis_instance():
# instance = Openbis("http://localhost:20000") instance = Openbis(url=openbis_url, verify_certificates=False)
# Test against a real instance
instance = Openbis("http://localhost:8888", verify_certificates=False)
print("\nLOGGING IN...") print("\nLOGGING IN...")
instance.login('admin', 'anypassword') instance.login(admin_username, admin_password)
yield instance yield instance
instance.logout() instance.logout()
print("LOGGED OUT...") print("LOGGED OUT...")
...@@ -9,32 +9,29 @@ from pybis import Openbis ...@@ -9,32 +9,29 @@ from pybis import Openbis
def test_token(openbis_instance): def test_token(openbis_instance):
assert openbis_instance.hostname is not None assert openbis_instance.token is not None
assert openbis_instance.is_token_valid(openbis_instance.token) is True
assert openbis_instance.is_session_active() is True
def test_wrong_login(openbis_instance):
new_instance = Openbis(openbis_instance.url, verify_certificates=openbis_instance.verify_certificates) new_instance = Openbis(openbis_instance.url, verify_certificates=openbis_instance.verify_certificates)
new_instance.login('admin', 'any_test_password') with pytest.raises(ValueError):
assert new_instance.token is not None new_instance.login('anyuser', 'any_test_password')
assert new_instance.is_token_valid() is True
new_instance.logout()
assert new_instance.is_token_valid() is False
invalid_connection = Openbis(openbis_instance.url, verify_certificates=openbis_instance.verify_certificates) assert new_instance.token is None
with pytest.raises(Exception): assert new_instance.is_session_active() is False
invalid_connection.login('invalid_username', 'invalid_password')
assert invalid_connection.token is None
assert invalid_connection.is_token_valid() is False
def test_create_delete_space(openbis_instance):
space_name = 'test_space_' + time.strftime('%a_%y%m%d_%H%M%S').upper()
space = openbis_instance.new_space(code=space_name)
space.save()
space_exists = openbis_instance.get_space(code=space_name)
assert space_exists is not None
def test_create_sample(openbis_instance): space.delete()
# given with pytest.raises(ValueError):
sample_code = 'test_create_' + time.strftime('%a_%y%m%d_%H%M%S').upper() space_not_exists = openbis_instance.get_space(code=space_name)
sample_type = 'UNKNOWN'
space = 'DEFAULT'
# when
sample = openbis_instance.new_sample(code=sample_code, type=sample_type, space=space)
# then
assert sample is not None
assert sample.space == space
assert sample.code == sample_code
def test_cached_token(openbis_instance): def test_cached_token(openbis_instance):
...@@ -49,6 +46,19 @@ def test_cached_token(openbis_instance): ...@@ -49,6 +46,19 @@ def test_cached_token(openbis_instance):
assert openbis_instance._get_cached_token() is None assert openbis_instance._get_cached_token() is None
def test_create_sample(openbis_instance):
# given
sample_code = 'test_create_' + time.strftime('%a_%y%m%d_%H%M%S').upper()
sample_type = 'UNKNOWN'
space = 'DEFAULT'
# when
sample = openbis_instance.new_sample(code=sample_code, type=sample_type, space=space)
# then
assert sample is not None
assert sample.space == space
assert sample.code == sample_code
def test_get_sample_by_id(openbis_instance): def test_get_sample_by_id(openbis_instance):
# given # given
sample_code = 'test_get_by_id_' + time.strftime('%a_%y%m%d_%H%M%S').upper() sample_code = 'test_get_by_id_' + time.strftime('%a_%y%m%d_%H%M%S').upper()
...@@ -164,10 +174,10 @@ def test_dataset_upload(openbis_instance): ...@@ -164,10 +174,10 @@ def test_dataset_upload(openbis_instance):
# analysis.save # start registering process # analysis.save # start registering process
def test_create_perm_id(openbis_instance): def test_create_permId(openbis_instance):
perm_id = openbis_instance.create_perm_id() permId = openbis_instance.create_permId()
assert perm_id is not None assert permId is not None
m = re.search('([0-9]){17}-([0-9]*)', perm_id) m = re.search('([0-9]){17}-([0-9]*)', permId)
ts = m.group(0) ts = m.group(0)
assert ts is not None assert ts is not None
count = m.group(1) count = m.group(1)
......
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