diff --git a/api-openbis-python3-pybis/src/python/pybis/entity_type.py b/api-openbis-python3-pybis/src/python/pybis/entity_type.py index a17be6eb6b3a05c1d4ed396e581f7be514776655..b752dc666877b583a67ca1f43b56c1f4e6077daa 100644 --- a/api-openbis-python3-pybis/src/python/pybis/entity_type.py +++ b/api-openbis-python3-pybis/src/python/pybis/entity_type.py @@ -186,7 +186,10 @@ class EntityType: # assign plugin if plugin is not None: plugin_obj = self.openbis.get_plugin(plugin) - new_assignment["plugin"] = plugin_obj.permId + new_assignment["pluginId"] = { + "@type": 'as.dto.plugin.id.PluginPermId', + "permId": plugin_obj.permId + } request = self._get_request_for_pa(new_assignment, "Add") try: diff --git a/api-openbis-python3-pybis/src/python/tests/test_plugin.py b/api-openbis-python3-pybis/src/python/tests/test_plugin.py index b1707b6cccb555a0706dc5b25ad12211996b7f81..5aa0810be3d6c6b1d0ee4d416814ae826d2dce23 100644 --- a/api-openbis-python3-pybis/src/python/tests/test_plugin.py +++ b/api-openbis-python3-pybis/src/python/tests/test_plugin.py @@ -12,13 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import json -import re -import pytest import time -from pybis import DataSet -from pybis import Openbis +import uuid + +import pytest def test_create_delete_plugin(openbis_instance): @@ -50,6 +48,7 @@ def test_create_delete_plugin(openbis_instance): pl_not_exists = openbis_instance.get_plugin(plugin.name) assert pl_not_exists is None + def test_search_plugins(openbis_instance): plugins = openbis_instance.get_plugins(start_with=1, count=1) assert len(plugins) == 1 @@ -59,3 +58,59 @@ def test_search_plugins(openbis_instance): plugin = plugins[0] assert plugin.__class__.__name__ == 'Plugin' + +def test_assign_plugin_to_sample_type(openbis_instance): + + timestamp = time.strftime("%a_%y%m%d_%H%M%S").upper() + + plugin_name = 'TEST.NEW_PLUGIN_' + timestamp + "_" + str(uuid.uuid4()) + pl = openbis_instance.new_plugin( + name=plugin_name, + pluginType='DYNAMIC_PROPERTY', + entityKind='SAMPLE', + script='def validate(x, True):\n\treturn "OK"' + ) + pl.save() + + sample_type_code = 'SOME_TEST_SAMPLE_TYPE_' + timestamp + "_" + str(uuid.uuid4()) + sample_type = openbis_instance.new_sample_type( + code=sample_type_code, + generatedCodePrefix='STST-', + autoGeneratedCode=True + ) + sample_type.save() + + sample_type = openbis_instance.get_sample_type(sample_type_code) + assignments = sample_type.get_property_assignments().df + + assert len(assignments) == 0 + + property_code = 'SOME_TEST_PROPERTY_' + timestamp + "_" + str(uuid.uuid4()) + prop_type = openbis_instance.new_property_type( + code=property_code, + label='test property', + description='test property', + dataType='VARCHAR', + ) + prop_type.save() + + sample_type.assign_property(prop_type, section='General info', ordinal=2, + initialValueForExistingEntities='', plugin=plugin_name) + + assignments = sample_type.get_property_assignments().df + + assert len(assignments) == 1 + assert assignments.loc[0]['plugin'] == plugin_name + + sample = openbis_instance.new_sample( + type=sample_type.code, + space='DEFAULT', + experiment='/DEFAULT/DEFAULT/DEFAULT', + props={property_code.lower(): "some_value"} + ) + sample.save() + + sample_type.revoke_property(property_code, force=True) + + assignments = sample_type.get_property_assignments().df + assert len(assignments) == 0