Skip to content

Commit 181b15f

Browse files
Merge pull request #762 from VWS-Python/fewer-assumptions-in-vwq-assertion
Fewer assumptions in vwq assertion
2 parents fab6b28 + 9b2a9db commit 181b15f

File tree

7 files changed

+64
-5
lines changed

7 files changed

+64
-5
lines changed

tests/mock_vws/test_authorization_header.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ def test_missing(self, endpoint: Endpoint) -> None:
6161
response=response,
6262
status_code=HTTPStatus.UNAUTHORIZED,
6363
content_type='text/plain; charset=ISO-8859-1',
64+
cache_control=None,
65+
www_authenticate='VWS',
6466
)
6567
assert response.text == 'Authorization header missing.'
6668
return
@@ -113,6 +115,8 @@ def test_one_part(
113115
response=response,
114116
status_code=HTTPStatus.UNAUTHORIZED,
115117
content_type='text/plain; charset=ISO-8859-1',
118+
cache_control=None,
119+
www_authenticate='VWS',
116120
)
117121
assert response.text == 'Malformed authorization header.'
118122
return
@@ -160,6 +164,8 @@ def test_missing_signature(
160164
response=response,
161165
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
162166
content_type='text/html; charset=ISO-8859-1',
167+
cache_control='must-revalidate,no-cache,no-store',
168+
www_authenticate=None,
163169
)
164170
# We have seen multiple responses given.
165171
assert 'Powered by Jetty' in response.text
@@ -220,6 +226,8 @@ def test_bad_access_key_query(
220226
response=response,
221227
status_code=HTTPStatus.UNAUTHORIZED,
222228
content_type='application/json',
229+
cache_control=None,
230+
www_authenticate='VWS',
223231
)
224232

225233
assert response.json().keys() == {'transaction_id', 'result_code'}
@@ -276,6 +284,8 @@ def test_bad_secret_key_query(
276284
response=response,
277285
status_code=HTTPStatus.UNAUTHORIZED,
278286
content_type='application/json',
287+
cache_control=None,
288+
www_authenticate='VWS',
279289
)
280290

281291
assert response.json().keys() == {'transaction_id', 'result_code'}

tests/mock_vws/test_content_length.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ def test_too_small(self, endpoint: Endpoint) -> None:
101101
response=response,
102102
status_code=HTTPStatus.UNAUTHORIZED,
103103
content_type='application/json',
104+
cache_control=None,
105+
www_authenticate='VWS',
104106
)
105107
return
106108

tests/mock_vws/test_date_header.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ def test_no_date_header(
7575
response=response,
7676
status_code=HTTPStatus.BAD_REQUEST,
7777
content_type=expected_content_type,
78+
cache_control=None,
79+
www_authenticate=None,
7880
)
7981
return
8082

@@ -141,6 +143,8 @@ def test_incorrect_date_format(
141143
response=response,
142144
status_code=HTTPStatus.UNAUTHORIZED,
143145
content_type='text/plain; charset=ISO-8859-1',
146+
cache_control=None,
147+
www_authenticate='VWS',
144148
)
145149
return
146150

tests/mock_vws/test_invalid_json.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ def test_invalid_json(
9999
response=response,
100100
status_code=HTTPStatus.BAD_REQUEST,
101101
content_type='text/html;charset=UTF-8',
102+
cache_control=None,
103+
www_authenticate=None,
102104
)
103105
expected_text = (
104106
'java.lang.RuntimeException: RESTEASY007500: '

tests/mock_vws/test_query.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ def test_incorrect_no_boundary(
148148
response=response,
149149
status_code=HTTPStatus.UNSUPPORTED_MEDIA_TYPE,
150150
content_type=None,
151+
cache_control=None,
152+
www_authenticate=None,
151153
)
152154

153155
def test_incorrect_with_boundary(
@@ -202,6 +204,8 @@ def test_incorrect_with_boundary(
202204
response=response,
203205
status_code=HTTPStatus.UNSUPPORTED_MEDIA_TYPE,
204206
content_type=None,
207+
cache_control=None,
208+
www_authenticate=None,
205209
)
206210

207211
@pytest.mark.parametrize(
@@ -263,6 +267,8 @@ def test_no_boundary(
263267
response=response,
264268
status_code=HTTPStatus.BAD_REQUEST,
265269
content_type='text/html;charset=UTF-8',
270+
cache_control=None,
271+
www_authenticate=None,
266272
)
267273

268274
def test_bogus_boundary(
@@ -315,6 +321,8 @@ def test_bogus_boundary(
315321
response=response,
316322
status_code=HTTPStatus.BAD_REQUEST,
317323
content_type='text/html;charset=UTF-8',
324+
cache_control=None,
325+
www_authenticate=None,
318326
)
319327

320328
def test_extra_section(
@@ -505,6 +513,8 @@ def test_missing_image(
505513
response=response,
506514
status_code=HTTPStatus.BAD_REQUEST,
507515
content_type='application/json',
516+
cache_control=None,
517+
www_authenticate=None,
508518
)
509519

510520
def test_extra_fields(
@@ -528,6 +538,8 @@ def test_extra_fields(
528538
response=response,
529539
content_type='application/json',
530540
status_code=HTTPStatus.BAD_REQUEST,
541+
cache_control=None,
542+
www_authenticate=None,
531543
)
532544

533545
def test_missing_image_and_extra_fields(
@@ -551,6 +563,8 @@ def test_missing_image_and_extra_fields(
551563
response=response,
552564
content_type='application/json',
553565
status_code=HTTPStatus.BAD_REQUEST,
566+
cache_control=None,
567+
www_authenticate=None,
554568
)
555569

556570

@@ -687,6 +701,8 @@ def test_out_of_range(
687701
response=response,
688702
content_type='application/json',
689703
status_code=HTTPStatus.BAD_REQUEST,
704+
cache_control=None,
705+
www_authenticate=None,
690706
)
691707

692708
@pytest.mark.parametrize(
@@ -723,6 +739,8 @@ def test_invalid_type(
723739
response=response,
724740
content_type='application/json',
725741
status_code=HTTPStatus.BAD_REQUEST,
742+
cache_control=None,
743+
www_authenticate=None,
726744
)
727745

728746

@@ -904,6 +922,8 @@ def test_invalid_value(
904922
response=response,
905923
status_code=HTTPStatus.BAD_REQUEST,
906924
content_type='application/json',
925+
cache_control=None,
926+
www_authenticate=None,
907927
)
908928

909929

@@ -1014,6 +1034,8 @@ def test_invalid(
10141034
response=response,
10151035
status_code=HTTPStatus.NOT_ACCEPTABLE,
10161036
content_type=None,
1037+
cache_control=None,
1038+
www_authenticate=None,
10171039
)
10181040

10191041

@@ -1090,6 +1112,8 @@ def test_not_image(
10901112
response=response,
10911113
status_code=HTTPStatus.UNPROCESSABLE_ENTITY,
10921114
content_type='application/json',
1115+
cache_control=None,
1116+
www_authenticate=None,
10931117
)
10941118
assert response.json().keys() == {'transaction_id', 'result_code'}
10951119
assert_valid_transaction_id(response=response)
@@ -1290,6 +1314,8 @@ def test_max_height(self, vuforia_database: VuforiaDatabase) -> None:
12901314
response=response,
12911315
status_code=HTTPStatus.UNPROCESSABLE_ENTITY,
12921316
content_type='application/json',
1317+
cache_control=None,
1318+
www_authenticate=None,
12931319
)
12941320
assert response.json().keys() == {'transaction_id', 'result_code'}
12951321
assert_valid_transaction_id(response=response)
@@ -1346,6 +1372,8 @@ def test_max_width(self, vuforia_database: VuforiaDatabase) -> None:
13461372
response=response,
13471373
status_code=HTTPStatus.UNPROCESSABLE_ENTITY,
13481374
content_type='application/json',
1375+
cache_control=None,
1376+
www_authenticate=None,
13491377
)
13501378
assert response.json().keys() == {'transaction_id', 'result_code'}
13511379
assert_valid_transaction_id(response=response)
@@ -1413,6 +1441,8 @@ def test_unsupported(
14131441
response=response,
14141442
status_code=HTTPStatus.UNPROCESSABLE_ENTITY,
14151443
content_type='application/json',
1444+
cache_control=None,
1445+
www_authenticate=None,
14161446
)
14171447
assert response.json().keys() == {'transaction_id', 'result_code'}
14181448
assert_valid_transaction_id(response=response)
@@ -1500,6 +1530,8 @@ def test_processing(
15001530
response=response,
15011531
content_type='text/html; charset=ISO-8859-1',
15021532
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
1533+
cache_control='must-revalidate,no-cache,no-store',
1534+
www_authenticate=None,
15031535
)
15041536

15051537

@@ -1637,6 +1669,8 @@ def test_deleted(
16371669
response=response,
16381670
content_type='text/html; charset=ISO-8859-1',
16391671
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
1672+
cache_control='must-revalidate,no-cache,no-store',
1673+
www_authenticate=None,
16401674
)
16411675

16421676
return
@@ -1876,6 +1910,8 @@ def test_inactive_project(
18761910
response=response,
18771911
status_code=HTTPStatus.FORBIDDEN,
18781912
content_type='application/json',
1913+
cache_control=None,
1914+
www_authenticate=None,
18791915
)
18801916
assert response.json().keys() == {'transaction_id', 'result_code'}
18811917
assert_valid_transaction_id(response=response)

tests/mock_vws/test_unexpected_json.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ def test_does_not_take_data(
7777
response=response,
7878
status_code=HTTPStatus.UNSUPPORTED_MEDIA_TYPE,
7979
content_type=None,
80+
cache_control=None,
81+
www_authenticate=None,
8082
)
8183
return
8284

tests/mock_vws/utils/assertions.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,18 @@ def assert_vwq_failure(
199199
response: Response,
200200
status_code: int,
201201
content_type: Optional[str],
202+
cache_control: Optional[str],
203+
www_authenticate: Optional[str],
202204
) -> None:
203205
"""
204206
Assert that a VWQ failure response is as expected.
205207
206208
Args:
207209
response: The response returned by a request to VWQ.
208210
content_type: The expected Content-Type header.
209-
status_code: The expected status code of the response.
211+
status_code: The expected status code.
212+
cache_control: The expected Cache-Control header.
213+
www_authenticate: The expected WWW-Authenticate header.
210214
211215
Raises:
212216
AssertionError: The response is not in the expected VWQ error format
@@ -220,18 +224,17 @@ def assert_vwq_failure(
220224
'Server',
221225
}
222226

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

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

232-
if status_code == HTTPStatus.UNAUTHORIZED:
235+
if www_authenticate is not None:
233236
response_header_keys.add('WWW-Authenticate')
234-
assert response.headers['WWW-Authenticate'] == 'VWS'
237+
assert response.headers['WWW-Authenticate'] == www_authenticate
235238

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

0 commit comments

Comments
 (0)