Exemplo n.º 1
0
 def test_under_to_camel_input_untouched_for_sequence(self):
     data = [
         {
             'first_input': 1
         },
         {
             'second_input': 2
         },
     ]
     reference_input = deepcopy(data)
     underscoreize(data)
     self.assertEqual(data, reference_input)
Exemplo n.º 2
0
 def test_underscoreize_iterates_over_generator(self):
     data = self._camel_generator()
     output = [
         {
             'simple_is_better': 'than complex'
         },
         {
             'that_is': 'correct'
         },
     ]
     self.assertEqual(underscoreize(data), output)
Exemplo n.º 3
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 underscoreize(
                json.loads(data),
                **api_settings.JSON_UNDERSCOREIZE
            )
        except ValueError as exc:
            raise ParseError('JSON parse error - %s' % str(exc))
Exemplo n.º 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 = json.loads(stream.read().decode(encoding))
            data = data['data']
            if api_settings.CAMELIZE:
                data = underscoreize(data, **api_settings.JSON_UNDERSCOREIZE)
            return data
        except (ValueError, TypeError, KeyError) as exc:
            raise ParseError('JSON parse error - %s' % str(exc))
Exemplo n.º 5
0
 def test_camel_to_under_keys(self):
     data = {
         "twoWord": 1,
         "longKeyWithManyUnderscores": 2,
         "only1Key": 3,
         "onlyOneLetterA": 4,
         "bOnlyOneLetter": 5,
         "onlyCLetter": 6,
         "mix123123aAndLetters": 7,
     }
     output = {
         "two_word": 1,
         "long_key_with_many_underscores": 2,
         "only_1_key": 3,
         "only_one_letter_a": 4,
         "b_only_one_letter": 5,
         "only_c_letter": 6,
         "mix_123123a_and_letters": 7
     }
     self.assertEqual(underscoreize(data), output)
Exemplo n.º 6
0
 def test_non_string_key(self):
     data = {1: "test"}
     self.assertEqual(underscoreize(camelize(data)), data)
Exemplo n.º 7
0
 def test_camel_to_under_keys_with_no_underscore_before_number(self):
     data = {'noUnderscoreBefore123': 1}
     output = {'no_underscore_before123': 1}
     options = {'no_underscore_before_number': True}
     self.assertEqual(underscoreize(data, **options), output)