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
10 changes: 10 additions & 0 deletions tests/mock_vws/test_authorization_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def test_missing(self, endpoint: Endpoint) -> None:
response=response,
status_code=HTTPStatus.UNAUTHORIZED,
content_type='text/plain; charset=ISO-8859-1',
cache_control=None,
www_authenticate='VWS',
)
assert response.text == 'Authorization header missing.'
return
Expand Down Expand Up @@ -113,6 +115,8 @@ def test_one_part(
response=response,
status_code=HTTPStatus.UNAUTHORIZED,
content_type='text/plain; charset=ISO-8859-1',
cache_control=None,
www_authenticate='VWS',
)
assert response.text == 'Malformed authorization header.'
return
Expand Down Expand Up @@ -160,6 +164,8 @@ def test_missing_signature(
response=response,
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
content_type='text/html; charset=ISO-8859-1',
cache_control='must-revalidate,no-cache,no-store',
www_authenticate=None,
)
# We have seen multiple responses given.
assert 'Powered by Jetty' in response.text
Expand Down Expand Up @@ -220,6 +226,8 @@ def test_bad_access_key_query(
response=response,
status_code=HTTPStatus.UNAUTHORIZED,
content_type='application/json',
cache_control=None,
www_authenticate='VWS',
)

assert response.json().keys() == {'transaction_id', 'result_code'}
Expand Down Expand Up @@ -276,6 +284,8 @@ def test_bad_secret_key_query(
response=response,
status_code=HTTPStatus.UNAUTHORIZED,
content_type='application/json',
cache_control=None,
www_authenticate='VWS',
)

assert response.json().keys() == {'transaction_id', 'result_code'}
Expand Down
2 changes: 2 additions & 0 deletions tests/mock_vws/test_content_length.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ def test_too_small(self, endpoint: Endpoint) -> None:
response=response,
status_code=HTTPStatus.UNAUTHORIZED,
content_type='application/json',
cache_control=None,
www_authenticate='VWS',
)
return

Expand Down
4 changes: 4 additions & 0 deletions tests/mock_vws/test_date_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ def test_no_date_header(
response=response,
status_code=HTTPStatus.BAD_REQUEST,
content_type=expected_content_type,
cache_control=None,
www_authenticate=None,
)
return

Expand Down Expand Up @@ -141,6 +143,8 @@ def test_incorrect_date_format(
response=response,
status_code=HTTPStatus.UNAUTHORIZED,
content_type='text/plain; charset=ISO-8859-1',
cache_control=None,
www_authenticate='VWS',
)
return

Expand Down
2 changes: 2 additions & 0 deletions tests/mock_vws/test_invalid_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ def test_invalid_json(
response=response,
status_code=HTTPStatus.BAD_REQUEST,
content_type='text/html;charset=UTF-8',
cache_control=None,
www_authenticate=None,
)
expected_text = (
'java.lang.RuntimeException: RESTEASY007500: '
Expand Down
36 changes: 36 additions & 0 deletions tests/mock_vws/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ def test_incorrect_no_boundary(
response=response,
status_code=HTTPStatus.UNSUPPORTED_MEDIA_TYPE,
content_type=None,
cache_control=None,
www_authenticate=None,
)

def test_incorrect_with_boundary(
Expand Down Expand Up @@ -202,6 +204,8 @@ def test_incorrect_with_boundary(
response=response,
status_code=HTTPStatus.UNSUPPORTED_MEDIA_TYPE,
content_type=None,
cache_control=None,
www_authenticate=None,
)

@pytest.mark.parametrize(
Expand Down Expand Up @@ -263,6 +267,8 @@ def test_no_boundary(
response=response,
status_code=HTTPStatus.BAD_REQUEST,
content_type='text/html;charset=UTF-8',
cache_control=None,
www_authenticate=None,
)

def test_bogus_boundary(
Expand Down Expand Up @@ -315,6 +321,8 @@ def test_bogus_boundary(
response=response,
status_code=HTTPStatus.BAD_REQUEST,
content_type='text/html;charset=UTF-8',
cache_control=None,
www_authenticate=None,
)

def test_extra_section(
Expand Down Expand Up @@ -505,6 +513,8 @@ def test_missing_image(
response=response,
status_code=HTTPStatus.BAD_REQUEST,
content_type='application/json',
cache_control=None,
www_authenticate=None,
)

def test_extra_fields(
Expand All @@ -528,6 +538,8 @@ def test_extra_fields(
response=response,
content_type='application/json',
status_code=HTTPStatus.BAD_REQUEST,
cache_control=None,
www_authenticate=None,
)

def test_missing_image_and_extra_fields(
Expand All @@ -551,6 +563,8 @@ def test_missing_image_and_extra_fields(
response=response,
content_type='application/json',
status_code=HTTPStatus.BAD_REQUEST,
cache_control=None,
www_authenticate=None,
)


Expand Down Expand Up @@ -687,6 +701,8 @@ def test_out_of_range(
response=response,
content_type='application/json',
status_code=HTTPStatus.BAD_REQUEST,
cache_control=None,
www_authenticate=None,
)

@pytest.mark.parametrize(
Expand Down Expand Up @@ -723,6 +739,8 @@ def test_invalid_type(
response=response,
content_type='application/json',
status_code=HTTPStatus.BAD_REQUEST,
cache_control=None,
www_authenticate=None,
)


Expand Down Expand Up @@ -904,6 +922,8 @@ def test_invalid_value(
response=response,
status_code=HTTPStatus.BAD_REQUEST,
content_type='application/json',
cache_control=None,
www_authenticate=None,
)


Expand Down Expand Up @@ -1014,6 +1034,8 @@ def test_invalid(
response=response,
status_code=HTTPStatus.NOT_ACCEPTABLE,
content_type=None,
cache_control=None,
www_authenticate=None,
)


Expand Down Expand Up @@ -1090,6 +1112,8 @@ def test_not_image(
response=response,
status_code=HTTPStatus.UNPROCESSABLE_ENTITY,
content_type='application/json',
cache_control=None,
www_authenticate=None,
)
assert response.json().keys() == {'transaction_id', 'result_code'}
assert_valid_transaction_id(response=response)
Expand Down Expand Up @@ -1290,6 +1314,8 @@ def test_max_height(self, vuforia_database: VuforiaDatabase) -> None:
response=response,
status_code=HTTPStatus.UNPROCESSABLE_ENTITY,
content_type='application/json',
cache_control=None,
www_authenticate=None,
)
assert response.json().keys() == {'transaction_id', 'result_code'}
assert_valid_transaction_id(response=response)
Expand Down Expand Up @@ -1346,6 +1372,8 @@ def test_max_width(self, vuforia_database: VuforiaDatabase) -> None:
response=response,
status_code=HTTPStatus.UNPROCESSABLE_ENTITY,
content_type='application/json',
cache_control=None,
www_authenticate=None,
)
assert response.json().keys() == {'transaction_id', 'result_code'}
assert_valid_transaction_id(response=response)
Expand Down Expand Up @@ -1413,6 +1441,8 @@ def test_unsupported(
response=response,
status_code=HTTPStatus.UNPROCESSABLE_ENTITY,
content_type='application/json',
cache_control=None,
www_authenticate=None,
)
assert response.json().keys() == {'transaction_id', 'result_code'}
assert_valid_transaction_id(response=response)
Expand Down Expand Up @@ -1500,6 +1530,8 @@ def test_processing(
response=response,
content_type='text/html; charset=ISO-8859-1',
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
cache_control='must-revalidate,no-cache,no-store',
www_authenticate=None,
)


Expand Down Expand Up @@ -1637,6 +1669,8 @@ def test_deleted(
response=response,
content_type='text/html; charset=ISO-8859-1',
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
cache_control='must-revalidate,no-cache,no-store',
www_authenticate=None,
)

return
Expand Down Expand Up @@ -1876,6 +1910,8 @@ def test_inactive_project(
response=response,
status_code=HTTPStatus.FORBIDDEN,
content_type='application/json',
cache_control=None,
www_authenticate=None,
)
assert response.json().keys() == {'transaction_id', 'result_code'}
assert_valid_transaction_id(response=response)
Expand Down
2 changes: 2 additions & 0 deletions tests/mock_vws/test_unexpected_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ def test_does_not_take_data(
response=response,
status_code=HTTPStatus.UNSUPPORTED_MEDIA_TYPE,
content_type=None,
cache_control=None,
www_authenticate=None,
)
return

Expand Down
13 changes: 8 additions & 5 deletions tests/mock_vws/utils/assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,18 @@ def assert_vwq_failure(
response: Response,
status_code: int,
content_type: Optional[str],
cache_control: Optional[str],
www_authenticate: Optional[str],
) -> None:
"""
Assert that a VWQ failure response is as expected.

Args:
response: The response returned by a request to VWQ.
content_type: The expected Content-Type header.
status_code: The expected status code of the response.
status_code: The expected status code.
cache_control: The expected Cache-Control header.
www_authenticate: The expected WWW-Authenticate header.

Raises:
AssertionError: The response is not in the expected VWQ error format
Expand All @@ -220,18 +224,17 @@ def assert_vwq_failure(
'Server',
}

if status_code == HTTPStatus.INTERNAL_SERVER_ERROR:
if cache_control is not None:
response_header_keys.add('Cache-Control')
cache_control = 'must-revalidate,no-cache,no-store'
assert response.headers['Cache-Control'] == cache_control

if content_type is not None:
response_header_keys.add('Content-Type')
assert response.headers['Content-Type'] == content_type

if status_code == HTTPStatus.UNAUTHORIZED:
if www_authenticate is not None:
response_header_keys.add('WWW-Authenticate')
assert response.headers['WWW-Authenticate'] == 'VWS'
assert response.headers['WWW-Authenticate'] == www_authenticate

assert response.headers.keys() == response_header_keys
assert response.headers['Connection'] == 'keep-alive'
Expand Down