Пример #1
0
    def test_nested_list_dict_keys(self):
        d = {'key_one': 1, 'key_two': [{'nest_data_one': 1}, {'nest_data_two': 2}]}
        cd = {'keyOne': 1, 'keyTwo': [{'nestDataOne': 1}, {'nestDataTwo': 2}]}
        pd = {'KeyOne': 1, 'KeyTwo': [{'NestDataOne': 1}, {'NestDataTwo': 2}]}

        # to camel/pascal
        self.assertEqual(cd, transformations.keys_to_camelcase(d))
        self.assertEqual(pd, transformations.keys_to_pascalcase(d))

        # to snake
        self.assertEqual(d, transformations.keys_to_snakecase(cd))
        self.assertEqual(d, transformations.keys_to_snakecase(pd))
Пример #2
0
    def test_dict_keys(self):
        d = {'key_one': 1, 'key_two': 2}
        cd = {'keyOne': 1, 'keyTwo': 2}
        pd = {'KeyOne': 1, 'KeyTwo': 2}

        # to camel/pascal
        self.assertEqual(cd, transformations.keys_to_camelcase(d))
        self.assertEqual(pd, transformations.keys_to_pascalcase(d))

        # to snake
        self.assertEqual(d, transformations.keys_to_snakecase(cd))
        self.assertEqual(d, transformations.keys_to_snakecase(pd))
Пример #3
0
    def test_nested_dict_keys(self):
        d = {'key_one': 1, 'key_two': 2, 'key_three': {'nest_data': 'n'}}
        cd = {'keyOne': 1, 'keyTwo': 2, 'keyThree': {'nestData': 'n'}}
        pd = {'KeyOne': 1, 'KeyTwo': 2, 'KeyThree': {'NestData': 'n'}}

        # to camel/pascal
        self.assertEqual(cd, transformations.keys_to_camelcase(d))
        self.assertEqual(pd, transformations.keys_to_pascalcase(d))

        # to snake
        self.assertEqual(d, transformations.keys_to_snakecase(cd))
        self.assertEqual(d, transformations.keys_to_snakecase(pd))
Пример #4
0
 def parse(self, stream, media_type=None, parser_context=None):
     parser_context = parser_context or {}
     encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET)
     try:
         data = stream.read().decode(encoding)
         return transformations.keys_to_snakecase(json.loads(data))
     except ValueError as exc:
         raise ParseError('JSON parse error - %s' % six.text_type(exc))