Skip to content

Commit f1bb208

Browse files
authored
Merge pull request #527 from Labelbox/jt/al-1859
[AL-1859] Update SDK Tests for On-Prem
2 parents 5a905f9 + 502a75f commit f1bb208

File tree

8 files changed

+45
-8
lines changed

8 files changed

+45
-8
lines changed

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,11 @@ test-prod: build
1919
docker run -it -v ${PWD}:/usr/src -w /usr/src \
2020
-e LABELBOX_TEST_ENVIRON="prod" \
2121
-e LABELBOX_TEST_API_KEY_PROD=${LABELBOX_TEST_API_KEY_PROD} \
22+
local/labelbox-python:test pytest $(PATH_TO_TEST)
23+
24+
test-onprem: build
25+
docker run -it -v ${PWD}:/usr/src -w /usr/src \
26+
-e LABELBOX_TEST_ENVIRON="onprem" \
27+
-e LABELBOX_TEST_API_KEY_ONPREM=${LABELBOX_TEST_API_KEY_ONPREM} \
28+
-e LABELBOX_TEST_ONPREM_HOSTNAME=${LABELBOX_TEST_ONPREM_HOSTNAME} \
2229
local/labelbox-python:test pytest $(PATH_TO_TEST)

pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[pytest]
2-
addopts = -s -vv --reruns 5 --reruns-delay 10
2+
addopts = -s -vv -x --reruns 5 --reruns-delay 10
33
markers =
44
slow: marks tests as slow (deselect with '-m "not slow"')

tests/integration/annotation_import/test_label_import.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,18 @@ def test_create_from_url(client, project, annotation_import_test_helpers):
2020
annotation_import_test_helpers.check_running_state(label_import, name, url)
2121

2222

23-
def test_create_from_objects(client, project, object_predictions,
23+
def test_create_from_objects(client, configured_project, object_predictions,
2424
annotation_import_test_helpers):
25+
"""this test should check running state only to validate running, not completed"""
2526
name = str(uuid.uuid4())
2627

27-
label_import = LabelImport.create_from_objects(client=client,
28-
project_id=project.uid,
29-
name=name,
30-
labels=object_predictions)
31-
assert label_import.parent_id == project.uid
28+
label_import = LabelImport.create_from_objects(
29+
client=client,
30+
project_id=configured_project.uid,
31+
name=name,
32+
labels=object_predictions)
33+
34+
assert label_import.parent_id == configured_project.uid
3235
annotation_import_test_helpers.check_running_state(label_import, name)
3336
annotation_import_test_helpers.assert_file_content(
3437
label_import.input_file_url, object_predictions)

tests/integration/annotation_import/test_model_run.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import time
2+
import os
3+
import pytest
24

35

46
def test_model_run(client, configured_project_with_label, rand_gen):
@@ -84,6 +86,8 @@ def test_model_run_export_labels(model_run_with_model_run_data_rows):
8486
assert len(labels) == 3
8587

8688

89+
@pytest.mark.skipif(condition=os.environ['LABELBOX_TEST_ENVIRON'] == "onprem",
90+
reason="does not work for onprem")
8791
def test_model_run_status(model_run_with_model_run_data_rows):
8892

8993
def get_model_run_status():

tests/integration/conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class Environ(Enum):
2424
LOCAL = 'local'
2525
PROD = 'prod'
2626
STAGING = 'staging'
27+
ONPREM = 'onprem'
2728

2829

2930
@pytest.fixture(scope="session")
@@ -46,6 +47,12 @@ def graphql_url(environ: str) -> str:
4647
return 'https://api.labelbox.com/graphql'
4748
elif environ == Environ.STAGING:
4849
return 'https://staging-api.labelbox.com/graphql'
50+
elif environ == Environ.ONPREM:
51+
hostname = os.environ.get('LABELBOX_TEST_ONPREM_HOSTNAME', None)
52+
if hostname is None:
53+
raise Exception(f"Missing LABELBOX_TEST_ONPREM_INSTANCE")
54+
instance_id = hostname.split("-")[1].split(".")[0]
55+
return f"https://app.replicated-{instance_id}.labelbox.dev/api/_gql"
4956
return 'http://host.docker.internal:8080/graphql'
5057

5158

@@ -54,6 +61,8 @@ def testing_api_key(environ: str) -> str:
5461
return os.environ["LABELBOX_TEST_API_KEY_PROD"]
5562
elif environ == Environ.STAGING:
5663
return os.environ["LABELBOX_TEST_API_KEY_STAGING"]
64+
elif environ == Environ.ONPREM:
65+
return os.environ["LABELBOX_TEST_API_KEY_ONPREM"]
5766
return os.environ["LABELBOX_TEST_API_KEY_LOCAL"]
5867

5968

tests/integration/test_label.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import pytest
44
import requests
5+
import os
56

67
from labelbox import Label
78

@@ -35,6 +36,8 @@ def test_label_export(configured_project_with_label):
3536
# The new exporter doesn't work with the create_label mutation
3637

3738

39+
@pytest.mark.skipif(condition=os.environ['LABELBOX_TEST_ENVIRON'] == "onprem",
40+
reason="does not work for onprem")
3841
def test_label_update(configured_project_with_label):
3942
_, _, _, label = configured_project_with_label
4043
label.update(label="something else")

tests/integration/test_labeler_performance.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
from datetime import datetime, timezone, timedelta
22
import pytest
3+
import os
34

45

6+
@pytest.mark.skipif(
7+
condition=os.environ['LABELBOX_TEST_ENVIRON'] == "onprem",
8+
reason="longer runtime than expected for onprem. unskip when resolved.")
59
def test_labeler_performance(configured_project_with_label):
610
project, _, _, _ = configured_project_with_label
711

@@ -13,4 +17,4 @@ def test_labeler_performance(configured_project_with_label):
1317
assert isinstance(my_performance.last_activity_time, datetime)
1418
now_utc = datetime.now().astimezone(timezone.utc)
1519
assert timedelta(0) < now_utc - my_performance.last_activity_time < \
16-
timedelta(seconds=30)
20+
timedelta(seconds=60)

tests/integration/test_project.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import time
3+
import os
34

45
import pytest
56
import requests
@@ -124,6 +125,8 @@ def test_extend_reservations(project):
124125
project.extend_reservations("InvalidQueueType")
125126

126127

128+
@pytest.mark.skipif(condition=os.environ['LABELBOX_TEST_ENVIRON'] == "onprem",
129+
reason="new mutation does not work for onprem")
127130
def test_attach_instructions(client, project):
128131
with pytest.raises(ValueError) as execinfo:
129132
project.upsert_instructions('tests/integration/media/sample_pdf.pdf')
@@ -147,6 +150,8 @@ def test_attach_instructions(client, project):
147150
exc_info.value)
148151

149152

153+
@pytest.mark.skipif(condition=os.environ['LABELBOX_TEST_ENVIRON'] == "onprem",
154+
reason="new mutation does not work for onprem")
150155
def test_html_instructions(configured_project):
151156
html_file_path = '/tmp/instructions.html'
152157
sample_html_str = "<html></html>"
@@ -161,6 +166,8 @@ def test_html_instructions(configured_project):
161166
assert requests.get(instructions).text == sample_html_str
162167

163168

169+
@pytest.mark.skipif(condition=os.environ['LABELBOX_TEST_ENVIRON'] == "onprem",
170+
reason="new mutation does not work for onprem")
164171
def test_same_ontology_after_instructions(
165172
configured_project_with_complex_ontology):
166173
project, _ = configured_project_with_complex_ontology

0 commit comments

Comments
 (0)