Exemplo n.º 1
0
 def testErrorWithViolationsWithoutDescription(self):
     content = """{"error": {"details":
 [{"field": "value", "fieldViolations": [{"key": "value"}]}]}}"""
     error = testutil.CreateTestHttpError(10, 'reason', content)
     result = util.GetHttpErrorMessage(error)
     self.assertEqual(
         'ResponseError: status=[10], code=[reason], message=[]', result)
Exemplo n.º 2
0
 def testErrorWithStringError(self):
     content = '{"error": "message"}'
     error = testutil.CreateTestHttpError(10, 'reason', content)
     result = util.GetHttpErrorMessage(error)
     expected = 'ResponseError: status=[{0}], code=[{1}], message=[{2}]'.format(
         10, 'reason', '{"error": "message"}')
     self.assertEqual(result, expected)
Exemplo n.º 3
0
 def testErrorWithMessage(self):
     content = '{"error": {"message": "message"}}'
     error = testutil.CreateTestHttpError(10, 'reason', content)
     result = util.GetHttpErrorMessage(error)
     self.assertEqual(
         'ResponseError: status=[10], code=[reason], message=[message]',
         result)
Exemplo n.º 4
0
 def testErrorInvalidJsonWithError(self):
     # Test that 'error' word doesn't break our functions.
     error = testutil.CreateTestHttpError(10, 'reason', 'json error')
     result = util.GetHttpErrorMessage(error)
     self.assertEqual(
         'ResponseError: status=[10], code=[reason], message=[json error]',
         result)
Exemplo n.º 5
0
    def _setListResponseWithException(self):
        location = 'projects/{0}/locations/-'.format(self.Project())

        self.mock_client.projects_locations_functions.List.Expect(
            self.messages.CloudfunctionsProjectsLocationsFunctionsListRequest(
                parent=location, pageSize=100, pageToken=None),
            exception=testutil.CreateTestHttpError(404, 'Not Found'))
Exemplo n.º 6
0
 def _setListLogEntriesResponseWithException(self, log_filter, order, limit):
   self.mock_logging_client.entries.List.Expect(
       self.logging_msgs.ListLogEntriesRequest(
           resourceNames=['projects/{0}'.format(self.Project())],
           filter=log_filter,
           orderBy='timestamp {0}'.format(order),
           pageSize=limit),
       exception=testutil.CreateTestHttpError(404, 'Not Found'))
Exemplo n.º 7
0
 def testErrorSuccessful(self):
     content = """{"error": {"details":
 [{"field": "some.field.name", "fieldViolations": [
 {"description": "value 1"}, {"description": "value 2"}]},
 {"field": "outer.field.name", "fieldViolations":
 [{"field": "inner.field.name", "description": "value 3"}]}]}}"""
     error = testutil.CreateTestHttpError(10, 'reason', content)
     result = util.GetHttpErrorMessage(error)
     # When multiple overlapping field names are provided at different depths:
     # one at the same level as the "fieldViolations" key (outer) and
     # one at the same level as a violation in the "fieldViolations" list (inner)
     # then the outer field name is used.
     self.assertEqual(
         result, '\n'.join([
             'ResponseError: status=[10], code=[reason], message=[',
             'Problems:', 'some.field.name:', 'value 1', 'value 2',
             'outer.field.name:', 'value 3', ']'
         ]))
Exemplo n.º 8
0
 def testErrorWithDetailsWithoutInnerDictionary(self):
     content = '{"error": {"details": {"field": "value"}}}'
     error = testutil.CreateTestHttpError(10, 'reason', content)
     result = util.GetHttpErrorMessage(error)
     self.assertEqual(
         'ResponseError: status=[10], code=[reason], message=[]', result)
Exemplo n.º 9
0
 def testErrorWithStringDetails(self):
     content = '{"error": {"details": "field"}}'
     error = testutil.CreateTestHttpError(10, 'reason', content)
     result = util.GetHttpErrorMessage(error)
     self.assertEqual(
         'ResponseError: status=[10], code=[reason], message=[]', result)
Exemplo n.º 10
0
 def testErrorWithoutJson(self):
     error = testutil.CreateTestHttpError(10, 'reason', 'invalid json')
     result = util.GetHttpErrorMessage(error)
     self.assertEqual(
         'ResponseError: status=[10], code=[reason], message=[invalid json]',
         result)