コード例 #1
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))
コード例 #2
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))
コード例 #3
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))
コード例 #4
0
 def render(self, data, accepted_media_type=None, renderer_context=None):
     data = transformations.keys_to_camelcase(data)
     return super(CamelCaseJSONRenderer, self).render(data,
         accepted_media_type=accepted_media_type, renderer_context=renderer_context)