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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""

from http import HTTPStatus
from urllib.parse import urlparse

from vws_auth_tools import rfc_1123_date

Expand All @@ -17,7 +16,7 @@
from tests.mock_vws.utils.too_many_requests import handle_server_errors


def test_missing(endpoint: Endpoint) -> None:
def test_missing(endpoint: Endpoint, base_vwq_url: str) -> None:
"""
An `UNAUTHORIZED` response is returned when no `Authorization`
header
Expand Down Expand Up @@ -46,8 +45,7 @@ def test_missing(endpoint: Endpoint) -> None:

handle_server_errors(response=response)

netloc = urlparse(url=endpoint.base_url).netloc
if netloc == "cloudreco.vuforia.com":
if endpoint.base_url == base_vwq_url:
assert_vwq_failure(
response=response,
status_code=HTTPStatus.UNAUTHORIZED,
Expand Down
7 changes: 2 additions & 5 deletions tests/mock_vws/date_header/test_missing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Tests for what happens when the `Date` header is missing."""

from http import HTTPStatus
from urllib.parse import urlparse

from vws_auth_tools import authorization_header

Expand All @@ -14,7 +13,7 @@
from tests.mock_vws.utils.too_many_requests import handle_server_errors


def test_no_date_header(endpoint: Endpoint) -> None:
def test_no_date_header(endpoint: Endpoint, base_vwq_url: str) -> None:
"""
A `BAD_REQUEST` response is returned when no `Date` header is
given.
Expand Down Expand Up @@ -51,9 +50,7 @@ def test_no_date_header(endpoint: Endpoint) -> None:

handle_server_errors(response=response)

netloc = urlparse(url=endpoint.base_url).netloc

if netloc == "cloudreco.vuforia.com":
if endpoint.base_url == base_vwq_url:
expected_content_type = "text/plain;charset=iso-8859-1"
assert response.text == "Date header required."
assert_vwq_failure(
Expand Down
51 changes: 34 additions & 17 deletions tests/mock_vws/fixtures/prepared_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
from tests.mock_vws.fixtures.credentials import VuMarkCloudDatabase
from tests.mock_vws.utils import Endpoint

VWS_HOST = "https://vws.vuforia.com"
VWQ_HOST = "https://cloudreco.vuforia.com"


@pytest.fixture
def add_target(
*,
vuforia_database: CloudDatabase,
base_vws_url: str,
image_file_failed_state: io.BytesIO,
) -> Endpoint:
"""Return details of the endpoint for adding a target."""
Expand Down Expand Up @@ -66,7 +64,7 @@ def add_target(
return Endpoint(
successful_headers_status_code=HTTPStatus.CREATED,
successful_headers_result_code=ResultCodes.TARGET_CREATED,
base_url=VWS_HOST,
base_url=base_vws_url,
path_url=request_path,
method=method,
headers=headers,
Expand All @@ -80,6 +78,7 @@ def add_target(
def delete_target(
*,
vuforia_database: CloudDatabase,
base_vws_url: str,
target_id: str,
) -> Endpoint:
"""Return details of the endpoint for deleting a target."""
Expand Down Expand Up @@ -107,7 +106,7 @@ def delete_target(
}

return Endpoint(
base_url=VWS_HOST,
base_url=base_vws_url,
path_url=request_path,
method=method,
headers=headers,
Expand All @@ -120,7 +119,11 @@ def delete_target(


@pytest.fixture
def database_summary(*, vuforia_database: CloudDatabase) -> Endpoint:
def database_summary(
*,
vuforia_database: CloudDatabase,
base_vws_url: str,
) -> Endpoint:
"""
Return details of the endpoint for getting details about the
database.
Expand Down Expand Up @@ -150,7 +153,7 @@ def database_summary(*, vuforia_database: CloudDatabase) -> Endpoint:
}

return Endpoint(
base_url=VWS_HOST,
base_url=base_vws_url,
path_url=request_path,
method=method,
headers=headers,
Expand All @@ -166,6 +169,7 @@ def database_summary(*, vuforia_database: CloudDatabase) -> Endpoint:
def get_duplicates(
*,
vuforia_database: CloudDatabase,
base_vws_url: str,
target_id: str,
) -> Endpoint:
"""
Expand Down Expand Up @@ -197,7 +201,7 @@ def get_duplicates(
}

return Endpoint(
base_url=VWS_HOST,
base_url=base_vws_url,
path_url=request_path,
method=method,
headers=headers,
Expand All @@ -213,6 +217,7 @@ def get_duplicates(
def get_target(
*,
vuforia_database: CloudDatabase,
base_vws_url: str,
target_id: str,
) -> Endpoint:
"""Return details of the endpoint for getting details of a target."""
Expand Down Expand Up @@ -243,7 +248,7 @@ def get_target(
return Endpoint(
successful_headers_status_code=HTTPStatus.OK,
successful_headers_result_code=ResultCodes.SUCCESS,
base_url=VWS_HOST,
base_url=base_vws_url,
path_url=request_path,
method=method,
headers=headers,
Expand All @@ -254,7 +259,11 @@ def get_target(


@pytest.fixture
def target_list(*, vuforia_database: CloudDatabase) -> Endpoint:
def target_list(
*,
vuforia_database: CloudDatabase,
base_vws_url: str,
) -> Endpoint:
"""Return details of the endpoint for getting a list of targets."""
date = rfc_1123_date()
request_path = "/targets"
Expand Down Expand Up @@ -283,7 +292,7 @@ def target_list(*, vuforia_database: CloudDatabase) -> Endpoint:
return Endpoint(
successful_headers_status_code=HTTPStatus.OK,
successful_headers_result_code=ResultCodes.SUCCESS,
base_url=VWS_HOST,
base_url=base_vws_url,
path_url=request_path,
method=method,
headers=headers,
Expand All @@ -297,6 +306,7 @@ def target_list(*, vuforia_database: CloudDatabase) -> Endpoint:
def target_summary(
*,
vuforia_database: CloudDatabase,
base_vws_url: str,
target_id: str,
) -> Endpoint:
"""
Expand Down Expand Up @@ -330,7 +340,7 @@ def target_summary(
return Endpoint(
successful_headers_status_code=HTTPStatus.OK,
successful_headers_result_code=ResultCodes.SUCCESS,
base_url=VWS_HOST,
base_url=base_vws_url,
path_url=request_path,
method=method,
headers=headers,
Expand All @@ -344,6 +354,7 @@ def target_summary(
def update_target(
*,
vuforia_database: CloudDatabase,
base_vws_url: str,
target_id: str,
) -> Endpoint:
"""Return details of the endpoint for updating a target."""
Expand Down Expand Up @@ -377,7 +388,7 @@ def update_target(
return Endpoint(
successful_headers_status_code=HTTPStatus.OK,
successful_headers_result_code=ResultCodes.SUCCESS,
base_url=VWS_HOST,
base_url=base_vws_url,
path_url=request_path,
method=method,
headers=headers,
Expand All @@ -391,6 +402,7 @@ def update_target(
def query(
*,
vuforia_database: CloudDatabase,
base_vwq_url: str,
high_quality_image: io.BytesIO,
) -> Endpoint:
"""
Expand Down Expand Up @@ -428,7 +440,7 @@ def query(
return Endpoint(
successful_headers_status_code=HTTPStatus.OK,
successful_headers_result_code=ResultCodes.SUCCESS,
base_url=VWQ_HOST,
base_url=base_vwq_url,
path_url=request_path,
method=method,
headers=headers,
Expand All @@ -442,6 +454,7 @@ def query(
def vumark_generate_instance(
*,
vumark_vuforia_database: VuMarkCloudDatabase,
base_vws_url: str,
) -> Endpoint:
"""Return details of the endpoint for generating a VuMark instance."""
request_path = f"/targets/{vumark_vuforia_database.target_id}/instances"
Expand Down Expand Up @@ -475,7 +488,7 @@ def vumark_generate_instance(
return Endpoint(
successful_headers_status_code=HTTPStatus.OK,
successful_headers_result_code=None,
base_url=VWS_HOST,
base_url=base_vws_url,
path_url=request_path,
method=method,
headers=headers,
Expand All @@ -486,7 +499,11 @@ def vumark_generate_instance(


@pytest.fixture
def reco_counts_report(*, vuforia_database: CloudDatabase) -> Endpoint:
def reco_counts_report(
*,
vuforia_database: CloudDatabase,
base_vws_url: str,
) -> Endpoint:
"""Return details of the endpoint for requesting a reco counts
report.
"""
Expand Down Expand Up @@ -521,7 +538,7 @@ def reco_counts_report(*, vuforia_database: CloudDatabase) -> Endpoint:
return Endpoint(
successful_headers_status_code=HTTPStatus.OK,
successful_headers_result_code=ResultCodes.SUCCESS,
base_url=VWS_HOST,
base_url=base_vws_url,
path_url=request_path,
method=method,
headers=headers,
Expand Down
Loading