Skip to content

Commit b29f9dd

Browse files
authored
Full cycle E2E test (#957)
1 parent 59561dc commit b29f9dd

File tree

87 files changed

+318
-189
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+318
-189
lines changed

e2e_tests/cli/test_full_cycle.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import shutil
2+
from pathlib import Path
3+
4+
from e2e_tests.helpers import assert_cli, run_cli_command, export_release
5+
from e2e_tests.objects import E2EDataset, ConfigValues
6+
from e2e_tests.cli.test_import import compare_annotations_export
7+
8+
9+
def test_full_cycle(
10+
local_dataset: E2EDataset,
11+
config_values: ConfigValues,
12+
):
13+
"""
14+
This test performs the following steps:
15+
- 1: Registers a set of files from external storage to a dataset
16+
- 2: Imports some annotations
17+
- 3: Creates and pulls a release of the dataset
18+
- 4: Deletes all items from the dataset
19+
- 5: Pushes and imports the pulled files & annotations to the dataset
20+
- 6: Deletes locally pulled copies of the dataset files
21+
- 7: Creates and pulls a new release of the dataset
22+
- 8: Assert that the pulled data is as expected
23+
24+
It is designed to catch errors that may arise from changes to exported Darwin JSON
25+
"""
26+
item_type = "single_slotted"
27+
annotation_format = "darwin"
28+
first_release_name = "first_release"
29+
second_release_name = "second_release"
30+
pull_dir = Path(
31+
f"{Path.home()}/.darwin/datasets/{config_values.team_slug}/{local_dataset.slug}"
32+
)
33+
annotations_import_dir = (
34+
Path(__file__).parents[1]
35+
/ "data"
36+
/ "import"
37+
/ "image_annotations_with_item_level_properties"
38+
)
39+
expected_filepaths = [
40+
f"{pull_dir}/images/image_1.jpg",
41+
f"{pull_dir}/images/image_2.jpg",
42+
f"{pull_dir}/images/dir1/image_3.jpg",
43+
f"{pull_dir}/images/dir1/image_4.jpg",
44+
f"{pull_dir}/images/dir2/image_5.jpg",
45+
f"{pull_dir}/images/dir2/image_6.jpg",
46+
f"{pull_dir}/images/dir1/dir3/image_7.jpg",
47+
f"{pull_dir}/images/dir1/dir3/image_8.jpg",
48+
]
49+
50+
# Populate the dataset with items and annotations
51+
local_dataset.register_read_only_items(config_values, item_type)
52+
result = run_cli_command(
53+
f"darwin dataset import {local_dataset.name} {annotation_format} {annotations_import_dir}"
54+
)
55+
assert_cli(result, 0)
56+
57+
# Pull a first release of the dataset
58+
original_release = export_release(
59+
annotation_format, local_dataset, config_values, release_name=first_release_name
60+
)
61+
result = run_cli_command(
62+
f"darwin dataset pull {local_dataset.name}:{original_release.name}"
63+
)
64+
assert_cli(result, 0)
65+
66+
# Delete all items in the dataset
67+
local_dataset.delete_items(config_values)
68+
69+
# Push and import the pulled files and annotations to the dataset
70+
result = run_cli_command(
71+
f"darwin dataset push {local_dataset.name} {pull_dir}/images --preserve-folders"
72+
)
73+
assert_cli(result, 0)
74+
result = run_cli_command(
75+
f"darwin dataset import {local_dataset.name} {annotation_format} {pull_dir}/releases/{first_release_name}/annotations"
76+
)
77+
assert_cli(result, 0)
78+
79+
# Delete local copies of the dataset files for the dataset
80+
shutil.rmtree(f"{pull_dir}/images")
81+
82+
# Pull a second release of the dataset
83+
new_release = export_release(
84+
annotation_format,
85+
local_dataset,
86+
config_values,
87+
release_name=second_release_name,
88+
)
89+
result = run_cli_command(
90+
f"darwin dataset pull {local_dataset.name}:{new_release.name}"
91+
)
92+
assert_cli(result, 0)
93+
94+
# Check that all expected files have been downloaded
95+
all_filepaths = list(pull_dir.rglob("*"))
96+
for expected_file in expected_filepaths:
97+
assert Path(expected_file) in all_filepaths
98+
99+
# Check that all downloaded annotations are as expected
100+
compare_annotations_export(
101+
Path(f"{pull_dir}/releases/{first_release_name}/annotations"),
102+
Path(f"{pull_dir}/releases/{second_release_name}/annotations"),
103+
item_type,
104+
unzip=False,
105+
)

e2e_tests/cli/test_import.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,15 @@ def compare_annotations_export(
226226
item_type: str,
227227
base_slot: Optional[str] = "0",
228228
annotation_format: str = "darwin",
229+
unzip: Optional[bool] = True,
229230
):
230231
"""
231232
Compares a set of downloaded annotation files with the imported files that resulted
232233
in those annotations. Ensures equality
233234
"""
234-
with zipfile.ZipFile(actual_annotations_dir / "dataset.zip") as z:
235-
z.extractall(actual_annotations_dir)
235+
if unzip:
236+
with zipfile.ZipFile(actual_annotations_dir / "dataset.zip") as z:
237+
z.extractall(actual_annotations_dir)
236238

237239
file_prefixes_to_ignore = [".", "metadata.json"]
238240
expected_annotation_files = {

e2e_tests/cli/test_pull.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ def test_pull_with_remote_folder_structure(
1616
f"{Path.home()}/.darwin/datasets/{config_values.team_slug}/{local_dataset.slug}/images"
1717
)
1818
expected_filepaths = [
19-
f"{pull_dir}/image_1",
20-
f"{pull_dir}/image_2",
21-
f"{pull_dir}/dir1/image_3",
22-
f"{pull_dir}/dir1/image_4",
23-
f"{pull_dir}/dir2/image_5",
24-
f"{pull_dir}/dir2/image_6",
25-
f"{pull_dir}/dir1/dir3/image_7",
26-
f"{pull_dir}/dir1/dir3/image_8",
19+
f"{pull_dir}/image_1.jpg",
20+
f"{pull_dir}/image_2.jpg",
21+
f"{pull_dir}/dir1/image_3.jpg",
22+
f"{pull_dir}/dir1/image_4.jpg",
23+
f"{pull_dir}/dir2/image_5.jpg",
24+
f"{pull_dir}/dir2/image_6.jpg",
25+
f"{pull_dir}/dir1/dir3/image_7.jpg",
26+
f"{pull_dir}/dir1/dir3/image_8.jpg",
2727
]
2828
item_type = "single_slotted"
2929
annotation_format = "darwin"

e2e_tests/data/import/coco_annotations/output.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"images": [
1818
{
1919
"license": 0,
20-
"file_name": "image_1",
20+
"file_name": "image_1.jpg",
2121
"coco_url": "n/a",
2222
"height": 1080,
2323
"width": 1920,
@@ -30,7 +30,7 @@
3030
},
3131
{
3232
"license": 0,
33-
"file_name": "image_2",
33+
"file_name": "image_2.jpg",
3434
"coco_url": "n/a",
3535
"height": 1080,
3636
"width": 1920,
@@ -43,7 +43,7 @@
4343
},
4444
{
4545
"license": 0,
46-
"file_name": "image_3",
46+
"file_name": "image_3.jpg",
4747
"coco_url": "n/a",
4848
"height": 1080,
4949
"width": 1920,
@@ -56,7 +56,7 @@
5656
},
5757
{
5858
"license": 0,
59-
"file_name": "image_4",
59+
"file_name": "image_4.jpg",
6060
"coco_url": "n/a",
6161
"height": 1080,
6262
"width": 1920,
@@ -69,7 +69,7 @@
6969
},
7070
{
7171
"license": 0,
72-
"file_name": "image_5",
72+
"file_name": "image_5.jpg",
7373
"coco_url": "n/a",
7474
"height": 1080,
7575
"width": 1920,
@@ -82,7 +82,7 @@
8282
},
8383
{
8484
"license": 0,
85-
"file_name": "image_6",
85+
"file_name": "image_6.jpg",
8686
"coco_url": "n/a",
8787
"height": 1080,
8888
"width": 1920,
@@ -95,7 +95,7 @@
9595
},
9696
{
9797
"license": 0,
98-
"file_name": "image_7",
98+
"file_name": "image_7.jpg",
9999
"coco_url": "n/a",
100100
"height": 1080,
101101
"width": 1920,
@@ -108,7 +108,7 @@
108108
},
109109
{
110110
"license": 0,
111-
"file_name": "image_8",
111+
"file_name": "image_8.jpg",
112112
"coco_url": "n/a",
113113
"height": 1080,
114114
"width": 1920,
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
image_1, test_tag_basic
2-
image_2, test_tag_basic
3-
dir1/image_3, test_tag_basic
4-
dir1/image_4, test_tag_basic
5-
dir2/image_5, test_tag_basic
6-
dir2/image_6, test_tag_basic
7-
dir1/dir3/image_7, test_tag_basic
8-
dir1/dir3/image_8, test_tag_basic
1+
image_1.jpg, test_tag_basic
2+
image_2.jpg, test_tag_basic
3+
dir1/image_3.jpg, test_tag_basic
4+
dir1/image_4.jpg, test_tag_basic
5+
dir2/image_5.jpg, test_tag_basic
6+
dir2/image_6.jpg, test_tag_basic
7+
dir1/dir3/image_7.jpg, test_tag_basic
8+
dir1/dir3/image_8.jpg, test_tag_basic

e2e_tests/data/import/image_annotations_item_level_properties_no_annotations/image_1.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"version": "2.0",
33
"schema_ref": "https://darwin-public.s3.eu-west-1.amazonaws.com/darwin_json/2.0/schema.json",
44
"item": {
5-
"name": "image_1",
5+
"name": "image_1.jpg",
66
"path": "/",
77
"source_info": {
88
"item_id": "01920b92-1d5d-94a4-6fbe-8a4d7f9fa15d",
@@ -26,7 +26,7 @@
2626
"thumbnail_url": "https://staging.v7labs.com/api/v2/teams/e2e-testing/files/2ec69e41-91b2-4155-9b05-6ed995677b1e/thumbnail",
2727
"source_files": [
2828
{
29-
"file_name": "image_1",
29+
"file_name": "image_1.jpg",
3030
"storage_key": "darwin-py/images/image_1.jpg",
3131
"url": "https://staging.v7labs.com/api/v2/teams/e2e-testing/uploads/9dfc5eac-bf16-4380-a148-9fff6e63b9f0"
3232
}

e2e_tests/data/import/image_annotations_item_level_properties_no_annotations/image_2.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"version": "2.0",
33
"schema_ref": "https://darwin-public.s3.eu-west-1.amazonaws.com/darwin_json/2.0/schema.json",
44
"item": {
5-
"name": "image_2",
5+
"name": "image_2.jpg",
66
"path": "/",
77
"source_info": {
88
"item_id": "01920b92-1d5d-ea77-8fa4-16378bafedb3",
@@ -26,7 +26,7 @@
2626
"thumbnail_url": "https://staging.v7labs.com/api/v2/teams/e2e-testing/files/5e0b3d9d-9bf8-4166-8949-6ab7392161ad/thumbnail",
2727
"source_files": [
2828
{
29-
"file_name": "image_2",
29+
"file_name": "image_2.jpg",
3030
"storage_key": "darwin-py/images/image_2.jpg",
3131
"url": "https://staging.v7labs.com/api/v2/teams/e2e-testing/uploads/4920b12a-1706-47f1-b084-2d2234ed1151"
3232
}

e2e_tests/data/import/image_annotations_item_level_properties_no_annotations/image_3.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"version": "2.0",
33
"schema_ref": "https://darwin-public.s3.eu-west-1.amazonaws.com/darwin_json/2.0/schema.json",
44
"item": {
5-
"name": "image_3",
5+
"name": "image_3.jpg",
66
"path": "/dir1",
77
"source_info": {
88
"item_id": "01920b92-1d5d-e8ad-986f-ad4942f1bbfc",
@@ -26,7 +26,7 @@
2626
"thumbnail_url": "https://staging.v7labs.com/api/v2/teams/e2e-testing/files/ddd13905-9bbb-4fab-9642-bf4604686fda/thumbnail",
2727
"source_files": [
2828
{
29-
"file_name": "image_3",
29+
"file_name": "image_3.jpg",
3030
"storage_key": "darwin-py/images/image_3.jpg",
3131
"url": "https://staging.v7labs.com/api/v2/teams/e2e-testing/uploads/30ec0f13-caaa-4374-be5a-e90b3493fb73"
3232
}

e2e_tests/data/import/image_annotations_item_level_properties_no_annotations/image_4.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"version": "2.0",
33
"schema_ref": "https://darwin-public.s3.eu-west-1.amazonaws.com/darwin_json/2.0/schema.json",
44
"item": {
5-
"name": "image_4",
5+
"name": "image_4.jpg",
66
"path": "/dir1",
77
"source_info": {
88
"item_id": "01920b92-1d5d-8b50-17e9-c0f178e6eee6",
@@ -26,7 +26,7 @@
2626
"thumbnail_url": "https://staging.v7labs.com/api/v2/teams/e2e-testing/files/3c731d84-7d7f-4ac8-bbd9-0d53f1d47195/thumbnail",
2727
"source_files": [
2828
{
29-
"file_name": "image_4",
29+
"file_name": "image_4.jpg",
3030
"storage_key": "darwin-py/images/image_4.jpg",
3131
"url": "https://staging.v7labs.com/api/v2/teams/e2e-testing/uploads/609ba1a4-79da-4743-b331-e57ccd9ee518"
3232
}

e2e_tests/data/import/image_annotations_item_level_properties_no_annotations/image_5.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"version": "2.0",
33
"schema_ref": "https://darwin-public.s3.eu-west-1.amazonaws.com/darwin_json/2.0/schema.json",
44
"item": {
5-
"name": "image_5",
5+
"name": "image_5.jpg",
66
"path": "/dir2",
77
"source_info": {
88
"item_id": "01920b92-1d5d-55bf-d705-8b39dea7fde6",
@@ -26,7 +26,7 @@
2626
"thumbnail_url": "https://staging.v7labs.com/api/v2/teams/e2e-testing/files/8f95e81c-def7-4973-9152-6d0fc39e1473/thumbnail",
2727
"source_files": [
2828
{
29-
"file_name": "image_5",
29+
"file_name": "image_5.jpg",
3030
"storage_key": "darwin-py/images/image_5.jpg",
3131
"url": "https://staging.v7labs.com/api/v2/teams/e2e-testing/uploads/08448a07-4e23-41f9-abbd-0dc149ef2be4"
3232
}

0 commit comments

Comments
 (0)