diff --git a/api-openbis-python3-pybis/src/python/CHANGELOG.md b/api-openbis-python3-pybis/src/python/CHANGELOG.md index 0e29be33aa520f8aa20a2d961d75b93028470923..a3f4e48a18038479b461f64a4399a4783e18782d 100644 --- a/api-openbis-python3-pybis/src/python/CHANGELOG.md +++ b/api-openbis-python3-pybis/src/python/CHANGELOG.md @@ -6,6 +6,7 @@ - Fixed v1 dataset upload - Fixed PropertyAssignment data frame creation - Improved property data type validation +- Improved get_project method ## Changes with pybis-1.36.3 diff --git a/api-openbis-python3-pybis/src/python/pybis/__init__.py b/api-openbis-python3-pybis/src/python/pybis/__init__.py index ad8be093f1fe5972ff963efd2e0d6ed020df3dd4..2e2203057b4cc8cd2907e61bc5fa1dbdea801741 100644 --- a/api-openbis-python3-pybis/src/python/pybis/__init__.py +++ b/api-openbis-python3-pybis/src/python/pybis/__init__.py @@ -15,7 +15,7 @@ name = "pybis" __author__ = "ID SIS • ETH Zürich" __email__ = "openbis-support@id.ethz.ch" -__version__ = "1.36.4-rc5" +__version__ = "1.36.4-rc6" from . import pybis from .pybis import DataSet diff --git a/api-openbis-python3-pybis/src/python/pybis/pybis.py b/api-openbis-python3-pybis/src/python/pybis/pybis.py index c9b71dd4659a2988c77caa05b61f8400149a955e..69b6b7a8ff0b4322d0399026cd4201e472f1e8fe 100644 --- a/api-openbis-python3-pybis/src/python/pybis/pybis.py +++ b/api-openbis-python3-pybis/src/python/pybis/pybis.py @@ -3206,6 +3206,8 @@ class Openbis: resp = self._post_request(self.as_v3, request) if len(resp["objects"]) == 0: raise ValueError("No such project: %s" % projectId) + elif len(resp["objects"]) > 1: + raise ValueError("There is more than one project with code '%s'" % projectId) if only_data: return resp["objects"][0] diff --git a/api-openbis-python3-pybis/src/python/setup.cfg b/api-openbis-python3-pybis/src/python/setup.cfg index aad3a9265209064a9443a8ecb912165e4ab77d30..899d293121ac4b926b520f68b50e56c4b9b40738 100644 --- a/api-openbis-python3-pybis/src/python/setup.cfg +++ b/api-openbis-python3-pybis/src/python/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = PyBIS -version = 1.36.4-rc5 +version = 1.36.4-rc6 author = ID SIS • ETH Zürich author_email = openbis-support@id.ethz.ch license = Apache Software License Version 2.0 diff --git a/api-openbis-python3-pybis/src/python/setup.py b/api-openbis-python3-pybis/src/python/setup.py index 84bab4b8d8922ae7b300848d8cd57f86f8856ed7..f5fdb5b6c523686199849098e4079ecd91ef4ce0 100644 --- a/api-openbis-python3-pybis/src/python/setup.py +++ b/api-openbis-python3-pybis/src/python/setup.py @@ -26,7 +26,7 @@ with open("README.md", "r", encoding="utf-8") as fh: setup( name="PyBIS", - version="1.36.4-rc5", + version="1.36.4-rc6", author="ID SIS • ETH Zürich", author_email="openbis-support@id.ethz.ch", description="openBIS connection and interaction, optimized for using with Jupyter", diff --git a/api-openbis-python3-pybis/src/python/tests/test_project.py b/api-openbis-python3-pybis/src/python/tests/test_project.py index 82a67c1582beae5456f25a6249af963ed258bf96..a7920343d83dc7a4d221bb6c7b3d52e014e70dc9 100644 --- a/api-openbis-python3-pybis/src/python/tests/test_project.py +++ b/api-openbis-python3-pybis/src/python/tests/test_project.py @@ -63,3 +63,39 @@ def test_create_project_with_attachment(space): project_exists = o.get_project(project_name) assert project_exists is not None assert project_exists.attachments is not None + + +def test_get_project_by_code(space): + o = space.openbis + + timestamp = time.strftime("%a_%y%m%d_%H%M%S").upper() + + space_code_1 = "space_1_" + timestamp + "_" + str(random.randint(0, 1000)) + project_code = "project_" + timestamp + + o.new_space(code=space_code_1).save() + + o.new_project(space=space_code_1, code=project_code).save() + project_exists = o.get_project(project_code) + assert project_exists is not None + + +def test_get_project_fail_because_of_multiple_projects_existing(space): + o = space.openbis + + timestamp = time.strftime("%a_%y%m%d_%H%M%S").upper() + + space_code_1 = "space_1_" + timestamp + "_" + str(random.randint(0, 1000)) + space_code_2 = "space_2_" + timestamp + "_" + str(random.randint(0, 1000)) + project_code = "project_" + timestamp + + o.new_space(code=space_code_1).save() + o.new_space(code=space_code_2).save() + + o.new_project(space=space_code_1, code=project_code).save() + o.new_project(space=space_code_2, code=project_code).save() + + with pytest.raises(ValueError): + project_exists = o.get_project(project_code) + +