diff --git a/hasty/__init__.py b/hasty/__init__.py index 7b8e24c..9d3456a 100755 --- a/hasty/__init__.py +++ b/hasty/__init__.py @@ -21,7 +21,7 @@ def int_or_str(value): return value -__version__ = '0.3.10' +__version__ = '0.3.11' VERSION = tuple(map(int_or_str, __version__.split('.'))) __all__ = [ diff --git a/hasty/attribute.py b/hasty/attribute.py index 07b8a95..cf0a34a 100644 --- a/hasty/attribute.py +++ b/hasty/attribute.py @@ -12,8 +12,8 @@ class Attribute(HastyObject): def __repr__(self): return self.get__repr__(OrderedDict({"id": self._id, "name": self._name, "attribute_type": self._attribute_type, - "description": self._description, "norder": self._norder, - "values": self._values})) + "subject_type": self.subject_type, "description": self._description, + "norder": self._norder, "values": self._values})) @property def id(self): @@ -43,6 +43,13 @@ def attribute_type(self): """ return self._attribute_type + @property + def subject_type(self): + """ + :type: string + """ + return self._subject_type + @property def description(self): """ @@ -69,6 +76,7 @@ def _init_properties(self): self._name = None self._project_id = None self._attribute_type = None + self._subject_type = None self._description = None self._norder = None self._values = None @@ -86,6 +94,8 @@ def _set_prop_values(self, data): self._description = data["description"] if "norder" in data: self._norder = data["norder"] + if "subject_type" in data: + self._subject_type = data["subject_type"] if "values" in data: self._values = data["values"] diff --git a/hasty/project.py b/hasty/project.py index b599021..5859375 100644 --- a/hasty/project.py +++ b/hasty/project.py @@ -302,7 +302,7 @@ def get_attributes(self): Attribute.endpoint.format(project_id=self._id), obj_params={"project_id": self.id}) - def create_attribute(self, name: str, attribute_type: str, subject_type: str, description: Optional[str] = None, + def create_attribute(self, name: str, attribute_type: str, subject_type: Optional[str] = 'LABEL', description: Optional[str] = None, norder: Optional[float] = None, values: List[str] = None): """ Create attribute, returns :py:class:`~hasty.Attribute` object. diff --git a/tests/test_attribute.py b/tests/test_attribute.py index 03540ff..249619b 100644 --- a/tests/test_attribute.py +++ b/tests/test_attribute.py @@ -76,6 +76,17 @@ def test_label_attributes(self): self.assertEqual(1, len(lbl_attr)) self.assertEqual(lbl_attr[0].value, attr1.values[0]["id"]) + def test_create_attribute_default_subject_type(self): + attributes = self.project.get_attributes() + self.assertEqual(0, len(attributes), 'Should be no attributes for a new project') + # Create attribute without subject type + attr1 = self.project.create_attribute("attr1", "SELECTION", norder=4, values=["v1", "v2", "v3"]) + self.assertEqual(attr1.subject_type, "LABEL") + attributes = self.project.get_attributes() + self.assertEqual(1, len(attributes)) + self.assertEqual('LABEL', attributes[0].subject_type) + + def tearDown(self) -> None: projects = self.h.get_projects() for p in projects: