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
42 changes: 36 additions & 6 deletions tests/integration/items/test_copy_items.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import json
import os
import tempfile
from collections import Counter
from os.path import join
from pathlib import Path

from src.superannotate import AppException
Expand All @@ -13,12 +16,13 @@ class TestCopyItems(BaseTestCase):
PROJECT_NAME = "TestCopyItemsVector"
PROJECT_DESCRIPTION = "TestCopyItemsVector"
PROJECT_TYPE = "Vector"
IMAGE_NAME = "test_image"
IMAGE_NAME_2 = "test_image_2"
IMAGE_NAME = "example_image_1.jpg"
IMAGE_NAME_2 = "example_image_2.jpg"
FOLDER_1 = "folder_1"
FOLDER_2 = "folder_2"
CSV_PATH = "data_set/attach_urls.csv"
Attachment = [
TEST_FOLDER_PATH = "data_set/sample_project_vector"
ATTACHMENT = [
{
"url": "https://drive.google.com/uc?export=download&id=1vwfCpTzcjxoEA4hhDxqapPOVvLVeS7ZS",
"name": IMAGE_NAME,
Expand All @@ -29,6 +33,10 @@ class TestCopyItems(BaseTestCase):
},
]

@property
def folder_path(self):
return os.path.join(Path(__file__).parent.parent.parent, self.TEST_FOLDER_PATH)

@property
def scv_path(self):
return os.path.join(Path(__file__).parent.parent.parent, self.CSV_PATH)
Expand All @@ -43,6 +51,28 @@ def test_copy_items_from_root(self):
assert len(skipped_items) == 0
assert len(sa.search_items(f"{self.PROJECT_NAME}/{self.FOLDER_1}")) == 7

def test_copy_items_from_root_with_annotations(self):
uploaded, _, _ = sa.attach_items(self.PROJECT_NAME, self.ATTACHMENT)
assert len(uploaded) == 2
annotation_path = join(self.folder_path, f"{self.IMAGE_NAME}___objects.json")
sa.upload_image_annotations(self.PROJECT_NAME, self.IMAGE_NAME, annotation_path)
sa.create_folder(self.PROJECT_NAME, self.FOLDER_1)
skipped_items = sa.copy_items(
self.PROJECT_NAME, f"{self.PROJECT_NAME}/{self.FOLDER_1}"
)
assert len(skipped_items) == 0
assert len(sa.search_items(f"{self.PROJECT_NAME}/{self.FOLDER_1}")) == 2
with tempfile.TemporaryDirectory() as tmp_dir:
sa.download_image_annotations(
f"{self.PROJECT_NAME}/{self.FOLDER_1}", self.IMAGE_NAME, tmp_dir
)
origin_annotation = json.load(open(annotation_path))
annotation = json.load(open(join(tmp_dir, f"{self.IMAGE_NAME}.json")))
self.assertEqual(
len([i["attributes"] for i in annotation["instances"]]),
len([i["attributes"] for i in origin_annotation["instances"]]),
)

def test_copy_items_from_not_existing_folder(self):
with self.assertRaisesRegexp(AppException, "Folder not found."):
sa.copy_items(f"{self.PROJECT_NAME}/{self.FOLDER_1}", self.PROJECT_NAME)
Expand Down Expand Up @@ -79,7 +109,7 @@ def test_skipped_count(self):
def test_copy_items_wrong_items_list(self):
uploaded, _, _ = sa.attach_items(
self.PROJECT_NAME,
self.Attachment,
self.ATTACHMENT,
)
sa.set_approval_statuses(self.PROJECT_NAME, "Approved", items=[self.IMAGE_NAME])
sa.set_annotation_statuses(
Expand All @@ -102,7 +132,7 @@ def test_copy_duplicated_items_without_data_with_replace_strategy(self):
sa.create_folder(self.PROJECT_NAME, self.FOLDER_1)
sa.create_folder(self.PROJECT_NAME, self.FOLDER_2)
uploaded, _, _ = sa.attach_items(
f"{self.PROJECT_NAME}/{self.FOLDER_1}", self.Attachment
f"{self.PROJECT_NAME}/{self.FOLDER_1}", self.ATTACHMENT
)
assert len(uploaded) == 2
sa.set_approval_statuses(
Expand All @@ -117,7 +147,7 @@ def test_copy_duplicated_items_without_data_with_replace_strategy(self):
)

uploaded_2, _, _ = sa.attach_items(
f"{self.PROJECT_NAME}/{self.FOLDER_2}", self.Attachment
f"{self.PROJECT_NAME}/{self.FOLDER_2}", self.ATTACHMENT
)
assert len(uploaded_2) == 2

Expand Down
61 changes: 49 additions & 12 deletions tests/integration/items/test_move_items.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import json
import os
import tempfile
from os.path import join
from pathlib import Path

from src.superannotate import SAClient
Expand All @@ -11,13 +14,14 @@ class TestMoveItems(BaseTestCase):
PROJECT_NAME = "TestMoveItemsVector"
PROJECT_DESCRIPTION = "TestCopyItemsVector"
PROJECT_TYPE = "Vector"
IMAGE_NAME = "test_image"
IMAGE_NAME_2 = "test_image_2"
IMAGE_NAME = "example_image_1.jpg"
IMAGE_NAME_2 = "example_image_2.jpg"
FOLDER_1 = "folder_1"
FOLDER_2 = "folder_2"
CSV_PATH = "data_set/attach_urls.csv"
TEST_FOLDER_PATH = "data_set/sample_project_vector"

Attachment = [
ATTACHMENT = [
{
"url": "https://drive.google.com/uc?export=download&id=1vwfCpTzcjxoEA4hhDxqapPOVvLVeS7ZS",
"name": IMAGE_NAME,
Expand All @@ -28,6 +32,10 @@ class TestMoveItems(BaseTestCase):
},
]

@property
def folder_path(self):
return os.path.join(Path(__file__).parent.parent.parent, self.TEST_FOLDER_PATH)

@property
def scv_path(self):
return os.path.join(Path(__file__).parent.parent.parent, self.CSV_PATH)
Expand All @@ -46,22 +54,37 @@ def test_move_items_from_folder(self):
sa.create_folder(self.PROJECT_NAME, self.FOLDER_1)
sa.create_folder(self.PROJECT_NAME, self.FOLDER_2)
uploaded, _, _ = sa.attach_items(
f"{self.PROJECT_NAME}/{self.FOLDER_1}", self.scv_path
f"{self.PROJECT_NAME}/{self.FOLDER_1}", self.ATTACHMENT
)
assert len(uploaded) == 7
annotation_path = join(self.folder_path, f"{self.IMAGE_NAME}___objects.json")
sa.upload_image_annotations(
f"{self.PROJECT_NAME}/{self.FOLDER_1}", self.IMAGE_NAME, annotation_path
)

assert len(uploaded) == 2
skipped_items = sa.move_items(
f"{self.PROJECT_NAME}/{self.FOLDER_1}",
f"{self.PROJECT_NAME}/{self.FOLDER_2}",
)
assert len(skipped_items) == 0
assert len(sa.search_items(f"{self.PROJECT_NAME}/{self.FOLDER_2}")) == 7
assert len(sa.search_items(f"{self.PROJECT_NAME}/{self.FOLDER_2}")) == 2
assert len(sa.search_items(f"{self.PROJECT_NAME}/{self.FOLDER_1}")) == 0
with tempfile.TemporaryDirectory() as tmp_dir:
sa.download_image_annotations(
f"{self.PROJECT_NAME}/{self.FOLDER_2}", self.IMAGE_NAME, tmp_dir
)
origin_annotation = json.load(open(annotation_path))
annotation = json.load(open(join(tmp_dir, f"{self.IMAGE_NAME}.json")))
self.assertEqual(
len([i["attributes"] for i in annotation["instances"]]),
len([i["attributes"] for i in origin_annotation["instances"]]),
)

def test_move_items_from_folder_with_replace(self):
sa.create_folder(self.PROJECT_NAME, self.FOLDER_1)
sa.create_folder(self.PROJECT_NAME, self.FOLDER_2)
uploaded, _, _ = sa.attach_items(
f"{self.PROJECT_NAME}/{self.FOLDER_1}", self.Attachment
f"{self.PROJECT_NAME}/{self.FOLDER_1}", self.ATTACHMENT
)
assert len(uploaded) == 2
sa.set_approval_statuses(
Expand All @@ -76,7 +99,7 @@ def test_move_items_from_folder_with_replace(self):
)

uploaded_2, _, _ = sa.attach_items(
f"{self.PROJECT_NAME}/{self.FOLDER_2}", self.Attachment
f"{self.PROJECT_NAME}/{self.FOLDER_2}", self.ATTACHMENT
)
assert len(uploaded_2) == 2
folder_2_items = sa.search_items(f"{self.PROJECT_NAME}/{self.FOLDER_2}")
Expand All @@ -102,7 +125,7 @@ def test_move_items_from_folder_with_replace_annotations_only(self):
sa.create_folder(self.PROJECT_NAME, self.FOLDER_1)
sa.create_folder(self.PROJECT_NAME, self.FOLDER_2)
uploaded, _, _ = sa.attach_items(
f"{self.PROJECT_NAME}/{self.FOLDER_1}", self.Attachment
f"{self.PROJECT_NAME}/{self.FOLDER_1}", self.ATTACHMENT
)
assert len(uploaded) == 2
sa.set_approval_statuses(
Expand All @@ -115,9 +138,13 @@ def test_move_items_from_folder_with_replace_annotations_only(self):
"Completed",
items=[self.IMAGE_NAME, self.IMAGE_NAME_2],
)
annotation_path = join(self.folder_path, f"{self.IMAGE_NAME}___objects.json")
sa.upload_image_annotations(
f"{self.PROJECT_NAME}/{self.FOLDER_1}", self.IMAGE_NAME, annotation_path
)

uploaded_2, _, _ = sa.attach_items(
f"{self.PROJECT_NAME}/{self.FOLDER_2}", self.Attachment
f"{self.PROJECT_NAME}/{self.FOLDER_2}", self.ATTACHMENT
)
assert len(uploaded_2) == 2
folder_2_items = sa.search_items(f"{self.PROJECT_NAME}/{self.FOLDER_2}")
Expand All @@ -138,17 +165,27 @@ def test_move_items_from_folder_with_replace_annotations_only(self):
folder_2_items = sa.search_items(f"{self.PROJECT_NAME}/{self.FOLDER_2}")
assert folder_2_items[0]["annotation_status"] == "NotStarted"
assert not folder_2_items[0]["approval_status"]
with tempfile.TemporaryDirectory() as tmp_dir:
sa.download_image_annotations(
f"{self.PROJECT_NAME}/{self.FOLDER_2}", self.IMAGE_NAME, tmp_dir
)
origin_annotation = json.load(open(annotation_path))
annotation = json.load(open(join(tmp_dir, f"{self.IMAGE_NAME}.json")))
self.assertEqual(
len([i["attributes"] for i in annotation["instances"]]),
len([i["attributes"] for i in origin_annotation["instances"]]),
)

def test_move_items_from_folder_with_skip(self):
sa.create_folder(self.PROJECT_NAME, self.FOLDER_1)
sa.create_folder(self.PROJECT_NAME, self.FOLDER_2)
uploaded, _, _ = sa.attach_items(
f"{self.PROJECT_NAME}/{self.FOLDER_1}", self.Attachment
f"{self.PROJECT_NAME}/{self.FOLDER_1}", self.ATTACHMENT
)
assert len(uploaded) == 2

uploaded_2, _, _ = sa.attach_items(
f"{self.PROJECT_NAME}/{self.FOLDER_2}", self.Attachment
f"{self.PROJECT_NAME}/{self.FOLDER_2}", self.ATTACHMENT
)
assert len(uploaded_2) == 2

Expand Down