def test_unexpected_http_method(self): connection = \ self._make_connection_for_expected_api_call(_STUB_API_CALL_1) error_message = "Expected HTTP method 'GET', got 'POST'" with assert_raises_substring(AssertionError, error_message): connection.send_post_request(_STUB_URL_PATH, None)
def test_exception_inside_context_manager(self): """The validation for the number of requests is skipped.""" connection = \ self._make_connection_for_expected_api_call(_STUB_API_CALL_1) error_message = 'Foo' with assert_raises_substring(AssertionError, error_message): with connection: assert False, error_message
def test_too_many_requests(self): connection = MockConnection() error_message = \ 'Not enough API calls for new requests (requested {!r})'.format( _STUB_URL_PATH, ) with assert_raises_substring(AssertionError, error_message): connection.send_get_request(_STUB_URL_PATH)
def test_too_few_requests(self): connection = \ self._make_connection_for_expected_api_call(_STUB_API_CALL_1) error_message = '1 more requests were expected' with assert_raises_substring(AssertionError, error_message): with connection: # Do not make any requests in the connection pass
def test_too_many_requests(self): connection = MockPortalConnection() error_message = \ 'Not enough API calls for new requests (requested {!r})'.format( _STUB_URL_PATH, ) with assert_raises_substring(AssertionError, error_message): connection.send_get_request(_STUB_URL_PATH)
def test_unexpected_query_string_args(self): connection = \ self._make_connection_for_expected_api_call(_STUB_API_CALL_1) query_string_args = {'a': 'b'} error_message = 'Expected query string arguments {!r}, got {!r}' \ .format(None, query_string_args) with assert_raises_substring(AssertionError, error_message): connection.send_get_request(_STUB_URL_PATH, query_string_args)
def test_unexpected_url_path(self): connection = \ self._make_connection_for_expected_api_call(_STUB_API_CALL_1) url_path = _STUB_URL_PATH + '/foo' error_message = 'Expected URL {!r}, got {!r}'.format( _STUB_URL_PATH, url_path, ) with assert_raises_substring(AssertionError, error_message): connection.send_get_request(url_path)
def test_unexpected_url_path(self): connection = \ self._make_connection_for_expected_api_call(_STUB_API_CALL_1) url_path = _STUB_URL_PATH + '/foo' error_message = 'Expected URL path {!r}, got {!r}'.format( _STUB_URL_PATH, url_path, ) with assert_raises_substring(AssertionError, error_message): connection.send_get_request(url_path)
def test_unexpected_request_body_deserialization(self): expected_api_call = SuccessfulAPICall( _STUB_URL_PATH, 'PUT', response=_STUB_RESPONSE, ) connection = \ self._make_connection_for_expected_api_call(expected_api_call) request_body_deserialization = {'a': 'b'} error_message = 'Expected request body deserialization {!r}, got {!r}' \ .format(None, request_body_deserialization) with assert_raises_substring(AssertionError, error_message): connection.send_put_request( _STUB_URL_PATH, request_body_deserialization, )
def test_unexpected_request_body_deserialization(self): expected_api_call = SuccessfulAPICall( _STUB_URL_PATH, 'PUT', response_body_deserialization=_STUB_RESPONSE_BODY_DESERIALIZATION, ) connection = \ self._make_connection_for_expected_api_call(expected_api_call) request_body_deserialization = {'a': 'b'} error_message = 'Expected request body deserialization {!r}, got {!r}' \ .format(None, request_body_deserialization) with assert_raises_substring(AssertionError, error_message): connection.send_put_request( _STUB_URL_PATH, request_body_deserialization, )