Skip to content
Merged
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
81 changes: 43 additions & 38 deletions tests/mock_vws/test_vumark_generation_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,46 @@


@pytest.mark.usefixtures("verify_mock_vuforia")
def test_generate_instance_success(
vumark_vuforia_database: VuMarkVuforiaDatabase,
) -> None:
"""A VuMark instance can be generated with valid template settings."""
request_path = f"/targets/{vumark_vuforia_database.target_id}/instances"
content_type = "application/json"
generated_instance_id = uuid4().hex
content = json.dumps(obj={"instance_id": generated_instance_id}).encode(
encoding="utf-8"
)
date = rfc_1123_date()
authorization_string = authorization_header(
access_key=vumark_vuforia_database.server_access_key,
secret_key=vumark_vuforia_database.server_secret_key,
method=HTTPMethod.POST,
content=content,
content_type=content_type,
date=date,
request_path=request_path,
)

response = requests.post(
url=_VWS_HOST + request_path,
headers={
"Accept": "image/png",
"Authorization": authorization_string,
"Content-Length": str(object=len(content)),
"Content-Type": content_type,
"Date": date,
},
data=content,
timeout=30,
)

assert response.status_code == HTTPStatus.OK
assert response.headers["Content-Type"].split(sep=";")[0] == "image/png"
assert response.content.startswith(_PNG_SIGNATURE)
assert len(response.content) > len(_PNG_SIGNATURE)
class TestGenerateInstance:
"""Tests for the VuMark instance generation endpoint."""

@staticmethod
def test_generate_instance_success(
vumark_vuforia_database: VuMarkVuforiaDatabase,
) -> None:
"""A VuMark instance can be generated with valid template settings."""
target_id = vumark_vuforia_database.target_id
request_path = f"/targets/{target_id}/instances"
content_type = "application/json"
generated_instance_id = uuid4().hex
body_dict = {"instance_id": generated_instance_id}
content = json.dumps(obj=body_dict).encode(encoding="utf-8")
date = rfc_1123_date()
authorization_string = authorization_header(
access_key=vumark_vuforia_database.server_access_key,
secret_key=vumark_vuforia_database.server_secret_key,
method=HTTPMethod.POST,
content=content,
content_type=content_type,
date=date,
request_path=request_path,
)

response = requests.post(
url=_VWS_HOST + request_path,
headers={
"Accept": "image/png",
"Authorization": authorization_string,
"Content-Length": str(object=len(content)),
"Content-Type": content_type,
"Date": date,
},
data=content,
timeout=30,
)

assert response.status_code == HTTPStatus.OK
content_type_value = response.headers["Content-Type"].split(sep=";")[0]
assert content_type_value == "image/png"
assert response.content.startswith(_PNG_SIGNATURE)
assert len(response.content) > len(_PNG_SIGNATURE)
Loading