From a62a0f3d511d8f4bfbe08c9c82c6f04fbd3fb9ac Mon Sep 17 00:00:00 2001 From: vermeul <swen@ethz.ch> Date: Thu, 7 Dec 2017 23:27:39 +0100 Subject: [PATCH] added separate space and project tests --- src/python/PyBis/tests/conftest.py | 19 +++++++++++++++- src/python/PyBis/tests/test_project.py | 30 ++++++++++++++++++++++++++ src/python/PyBis/tests/test_space.py | 23 ++++++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 src/python/PyBis/tests/test_project.py create mode 100644 src/python/PyBis/tests/test_space.py diff --git a/src/python/PyBis/tests/conftest.py b/src/python/PyBis/tests/conftest.py index 350aa052b47..ca95953bdc1 100644 --- a/src/python/PyBis/tests/conftest.py +++ b/src/python/PyBis/tests/conftest.py @@ -1,10 +1,11 @@ import pytest +import time from pybis import Openbis openbis_url = 'https://localhost:8443' admin_username = 'admin' -admin_password = '*****' +admin_password = 'tea4you2' @pytest.yield_fixture(scope="module") def openbis_instance(): @@ -14,3 +15,19 @@ def openbis_instance(): yield instance instance.logout() print("LOGGED OUT...") + + +@pytest.yield_fixture(scope="module") +def space(): + o = Openbis(url=openbis_url, verify_certificates=False) + o.login(admin_username, admin_password) + + timestamp = time.strftime('%a_%y%m%d_%H%M%S').upper() + space_name = 'test_space_' + timestamp + space = o.new_space(code=space_name) + space.save() + space_exists = o.get_space(code=space_name) + yield space_exists + + space.delete("testing on {}".format(timestamp)) + o.logout() diff --git a/src/python/PyBis/tests/test_project.py b/src/python/PyBis/tests/test_project.py new file mode 100644 index 00000000000..2b7d4f4429a --- /dev/null +++ b/src/python/PyBis/tests/test_project.py @@ -0,0 +1,30 @@ +import json +import random +import re + +import pytest +import time +from pybis import DataSet +from pybis import Openbis + + +def test_create_delete_project(space): + o=space.openbis + + timestamp = time.strftime('%a_%y%m%d_%H%M%S').upper() + project=o.new_project(space=space, code='illegal title contains spaces') + with pytest.raises(ValueError): + project.save() + assert "should not have been created" is None + + project_name = 'project_'+timestamp + project=o.new_project(space=space, code=project_name) + project.save() + + project_exists=o.get_project(project_name) + assert project_exists is not None + project_exists.delete('test project on '+timestamp) + + with pytest.raises(ValueError): + project_no_longer_exists=o.get_project(project_name) + assert "project {} should have been deleted".format(project_name) is None diff --git a/src/python/PyBis/tests/test_space.py b/src/python/PyBis/tests/test_space.py new file mode 100644 index 00000000000..4e1d49efcfa --- /dev/null +++ b/src/python/PyBis/tests/test_space.py @@ -0,0 +1,23 @@ +import json +import random +import re + +import pytest +import time +from pybis import DataSet +from pybis import Openbis + + +def test_create_delete_space(openbis_instance): + timestamp = time.strftime('%a_%y%m%d_%H%M%S').upper() + space_name = 'test_space_' + timestamp + 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 + + space.delete("test on {}".format(timestamp)) + + with pytest.raises(ValueError): + space_not_exists = openbis_instance.get_space(code=space_name) + assert space_not_exists is None -- GitLab