def test_get_google_ads_failure_decode_error(self): """Returns none if the google ads failure cannot be decoded.""" interceptor = Interceptor(default_version) mock_failure_value = _MOCK_FAILURE_VALUE + b'1234' mock_metadata = ((interceptor._failure_key, mock_failure_value), ) result = interceptor._get_google_ads_failure(mock_metadata) self.assertEqual(result, None)
def test_deferred_error_proto_module_load(self): """Tests that import_module is called when an API error is received.""" with mock.patch('google.ads.google_ads.interceptors.' 'interceptor.import_module') as import_mock: interceptor = Interceptor(default_version) mock_metadata = ((interceptor._failure_key, _MOCK_FAILURE_VALUE), ) interceptor._get_google_ads_failure(mock_metadata) import_mock.assert_called_once_with('google.ads.google_ads.' f'{default_version}.proto.' 'errors.errors_pb2')
def test_get_error_from_response_does_not_cache_error(self): """Ensures errors are not cached across requests..""" interceptor = Interceptor(default_version) class MockRpcErrorResponse(grpc.RpcError): def code(self): return grpc.StatusCode.INVALID_ARGUMENT def trailing_metadata(self): return ( (interceptor._failure_key, b"\n \n\x02\x08\x10\x12\x1aInvalid customer ID '123'."), ) def exception(self): return self response = MockRpcErrorResponse() first_result = interceptor._get_error_from_response(response) second_result = interceptor._get_error_from_response(response) self.assertIsNot(first_result, second_result)
def test_get_google_ads_failure_with_None(self): """Returns None if None is passed.""" interceptor = Interceptor(default_version) result = interceptor._get_google_ads_failure(None) self.assertEqual(result, None)
def test_get_google_ads_failure_no_failure_key(self): """Returns None if an error cannot be found in metadata.""" mock_metadata = (('another-key', 'another-val'), ) interceptor = Interceptor(default_version) result = interceptor._get_google_ads_failure(mock_metadata) self.assertEqual(result, None)
def test_get_google_ads_failure(self): """Obtains the content of a google ads failure from metadata.""" interceptor = Interceptor(default_version) mock_metadata = ((interceptor._failure_key, _MOCK_FAILURE_VALUE), ) result = interceptor._get_google_ads_failure(mock_metadata) self.assertIsInstance(result, error_protos.GoogleAdsFailure)
def test_init_no_error_proto_load(self): """Ensures that error proto modules are not loaded on init.""" interceptor = Interceptor(default_version) self.assertEqual(interceptor._error_protos, None)