Skip to content

Commit 81e9fbb

Browse files
committed
add testing for indexing endpoints
1 parent 006abfb commit 81e9fbb

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

nucleus/constants.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
ANNOTATION_UPDATE_KEY = "update"
2222
DEFAULT_ANNOTATION_UPDATE_MODE = False
2323
STATUS_CODE_KEY = "status_code"
24-
SUCCESS_STATUS_CODES = [200, 201]
24+
STATUS_KEY = "status"
25+
SUCCESS_STATUS_CODES = [200, 201, 202]
2526
ERRORS_KEY = "errors"
2627
MODEL_RUN_ID_KEY = "model_run_id"
2728
MODEL_ID_KEY = "model_id"
@@ -57,3 +58,5 @@
5758
INDEX_KEY = "index"
5859
SEGMENTATIONS_KEY = "segmentations"
5960
EMBEDDINGS_URL_KEY = "embeddings_url"
61+
JOB_ID_KEY = "job_id"
62+
MESSAGE_KEY = "message"

tests/helpers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def reference_id_from_url(url):
120120
for i in range(len(TEST_POLYGON_ANNOTATIONS))
121121
]
122122

123+
TEST_INDEX_EMBEDDINGS_FILE = "https://scale-ml.s3.amazonaws.com/tmp/sasha/pytest_embeddings_payload.json"
123124

124125
# Asserts that a box annotation instance matches a dict representing its properties.
125126
# Useful to check annotation uploads/updates match.

tests/test_indexing.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import pytest
2+
3+
from helpers import (
4+
get_signed_url,
5+
TEST_INDEX_EMBEDDINGS_FILE,
6+
TEST_IMG_URLS,
7+
TEST_DATASET_NAME,
8+
reference_id_from_url,
9+
)
10+
11+
from nucleus import DatasetItem
12+
13+
from nucleus.constants import (
14+
ERROR_PAYLOAD,
15+
JOB_ID_KEY,
16+
MESSAGE_KEY,
17+
STATUS_KEY,
18+
)
19+
20+
21+
@pytest.fixture()
22+
def dataset(CLIENT):
23+
ds = CLIENT.create_dataset(TEST_DATASET_NAME)
24+
ds_items = []
25+
for url in TEST_IMG_URLS:
26+
ds_items.append(
27+
DatasetItem(
28+
image_location=url,
29+
reference_id=reference_id_from_url(url),
30+
)
31+
)
32+
33+
response = ds.append(ds_items)
34+
assert ERROR_PAYLOAD not in response.json()
35+
yield ds
36+
37+
response = CLIENT.delete_dataset(ds.id)
38+
assert response == {}
39+
40+
41+
def test_index_integration(dataset):
42+
signed_embeddings_url = get_signed_url(TEST_INDEX_EMBEDDINGS_FILE)
43+
create_response = dataset.create_custom_index(signed_embeddings_url)
44+
assert JOB_ID_KEY in create_response
45+
assert MESSAGE_KEY in create_response
46+
job_id = create_response[JOB_ID_KEY]
47+
48+
# Job can error because pytest dataset fixture gets deleted
49+
# As a workaround, we'll just check htat we got some response
50+
job_status_response = dataset.check_index_status(job_id)
51+
assert STATUS_KEY in job_status_response
52+
assert JOB_ID_KEY in job_status_response
53+
assert MESSAGE_KEY in job_status_response

0 commit comments

Comments
 (0)