Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hasty/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = [
Expand Down
14 changes: 12 additions & 2 deletions hasty/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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
Expand All @@ -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"]

Expand Down
2 changes: 1 addition & 1 deletion hasty/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions tests/test_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down