@@ -154,6 +154,37 @@ def assert_valid_date_header(response: Response) -> None:
154154 assert time_difference < datetime .timedelta (minutes = 1 )
155155
156156
157+ def assert_valid_transaction_id (response : Response ) -> None :
158+ """
159+ Assert that a response includes a valid transaction ID.
160+
161+ Args:
162+ response: The response returned by a request to a Vuforia service.
163+
164+ Raises:
165+ AssertionError: The response does not include a valid transaction ID.
166+ """
167+ transaction_id = response .json ()['transaction_id' ]
168+ assert len (transaction_id ) == 32
169+ assert all (char in hexdigits for char in transaction_id )
170+
171+
172+ def assert_json_separators (response : Response ) -> None :
173+ """
174+ Assert that a JSON response is formatted correctly.
175+
176+ Args:
177+ response: The response returned by a request to a Vuforia service.
178+
179+ Raises:
180+ AssertionError: The response JSON is not formatted correctly.
181+ """
182+ assert response .text == json .dumps (
183+ obj = response .json (),
184+ separators = (',' , ':' ),
185+ )
186+
187+
157188def assert_vws_response (
158189 response : Response ,
159190 status_code : int ,
@@ -191,17 +222,10 @@ def assert_vws_response(
191222 assert response .headers .keys () == response_header_keys
192223 assert response .headers ['Connection' ] == 'keep-alive'
193224 assert response .headers ['Content-Length' ] == str (len (response .text ))
194- # This confirms that the formatting style used matches what is expected.
195- # There are no spaces in the separators.
196- assert response .text == json .dumps (
197- obj = response .json (),
198- separators = (',' , ':' ),
199- )
200225 assert response .headers ['Content-Type' ] == 'application/json'
201226 assert response .headers ['Server' ] == 'nginx'
202- transaction_id = response .json ()['transaction_id' ]
203- assert len (transaction_id ) == 32
204- assert all (char in hexdigits for char in transaction_id )
227+ assert_json_separators (response = response )
228+ assert_valid_transaction_id (response = response )
205229 assert_valid_date_header (response = response )
206230
207231
0 commit comments