Skip to content

Commit

Permalink
Merge pull request #39 from cloudfactory/fix-unit-tests
Browse files Browse the repository at this point in the history
[HT-6557] Adjusting tests after enabling them
  • Loading branch information
xeviknal-cf authored Apr 16, 2024
2 parents 83582fc + ac77cd1 commit 6b81ebb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
8 changes: 4 additions & 4 deletions hasty/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class Image(HastyObject):
endpoint = '/v1/projects/{project_id}/images'
endpoint_uploads = '/v1/projects/{project_id}/image_uploads'
endpoint_uploads = '/v1/projects/{project_id}/uploads'
endpoint_image = '/v1/projects/{project_id}/images/{image_id}'

def __repr__(self):
Expand Down Expand Up @@ -133,15 +133,15 @@ def _get_by_id(requester, project_id, image_id):

@staticmethod
def _generate_sign_url(requester, project_id):
data = requester.post(Image.endpoint_uploads.format(project_id=project_id), json_data={"count": 1})
data = requester.get(Image.endpoint_uploads.format(project_id=project_id), query_params={"count": 1})
return data["items"][0]

@staticmethod
def _upload_from_file(requester, project_id, dataset_id, filepath, external_id: Optional[str] = None):
filename = os.path.basename(filepath)
url_data = Image._generate_sign_url(requester, project_id)
with open(filepath, 'rb') as f:
requester.put(url_data['url'], data=f.read(), content_type="image/*")
requester.put(url_data['url'], data=f.read(), content_type="")
res = requester.post(Image.endpoint.format(project_id=project_id),
json_data={"dataset_id": dataset_id,
"filename": filename,
Expand Down Expand Up @@ -171,7 +171,7 @@ def get_labels(self):
obj_params={"project_id": self.project_id})

def create_label(self, label_class: Union[LabelClass, str], bbox: List[int] = None, polygon: List[List[int]] = None,
mask: List[int] = None, z_index: int = None, external_id: Optional[str] = None):
mask: List[int] = None, z_index: int = 0, external_id: Optional[str] = None):
"""
Create label
Expand Down
21 changes: 16 additions & 5 deletions tests/test_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,25 @@ def test_tag(self):
self.assertEqual(2, len(tags), 'Should be two tag class assigned')
# Assign same classes
self.image.add_tags([tc1, tc2])
tags = self.image.get_tags()
self.assertEqual(2, len(tags), 'Still should be two tag class assigned')
original_tags = self.image.get_tags()
self.assertEqual(2, len(original_tags), 'Still should be two tag class assigned')
# Delete one tag
self.image.delete_tags([tags[0]])
self.image.delete_tags([original_tags[0]])
tags = self.image.get_tags()
self.assertEqual(1, len(tags), 'Should be one tag class assigned')
# Delete another tag by tag_class
self.image.delete_tags([tc1, tc2])
tags = self.image.get_tags()
self.assertEqual(0, len(tags), 'Should not be any tags assigned')
# Assign same classes
tags = self.image.add_tags([tc1, tc2])
self.assertEqual(2, len(tags), 'Should be two tag class assigned')
# Delete via object: tag_class_id
self.image.delete_tags([{"tag_class_id": tc1.id}])
tags = self.image.get_tags()
self.assertEqual(1, len(tags), 'Should be one tag class assigned')
# Delete another one tag
self.image.delete_tags([{"tag_id": tags[0].id}])
# Delete via object: tag_id
self.image.delete_tags([{"tag_id": tag.id} for tag in tags])
tags = self.image.get_tags()
self.assertEqual(0, len(tags), 'Should not be any tags assigned')

Expand Down

0 comments on commit 6b81ebb

Please sign in to comment.