def testToSnakeCasedDictMixed(self):
     test_dict = {'some_field': {'another_field': 3}, 'third_field': [1, 2]}
     self.assertEqual(text_utils.ToSnakeCaseDict(test_dict), {
         'someField': {
             'anotherField': 3
         },
         'thirdField': [1, 2]
     })
def GetMessageFromResponse(response, message_type):
    """Returns a message from the ResponseValue.

  Operations normally return a ResponseValue object in their response field that
  is somewhat difficult to use. This functions returns the corresponding
  message type to make it easier to parse the response.

  Args:
    response: The ResponseValue object that resulted from an Operation.
    message_type: The type of the message that should be returned

  Returns:
    An instance of message_type with the values from the response filled in.
  """
    message_dict = encoding.MessageToDict(response)
    snake_cased_dict = text_utils.ToSnakeCaseDict(message_dict)
    return messages_util.DictToMessageWithErrorCheck(snake_cased_dict,
                                                     message_type)
 def testToSnakeCasedDictSimple(self):
     test_dict = {'some_field': 'SomeValue', 'some_other_field': 2}
     self.assertEqual(text_utils.ToSnakeCaseDict(test_dict), {
         'someField': 'SomeValue',
         'someOtherField': 2
     })
 def testToSnakeCasedDictNested(self):
     test_dict = {'some_field': {'another_field': 3}}
     self.assertEqual(text_utils.ToSnakeCaseDict(test_dict),
                      {'someField': {
                          'anotherField': 3
                      }})
 def testToSnakeCasedDictEmpty(self):
     self.assertEqual(text_utils.ToSnakeCaseDict({}), {})