Example #1
0
 def test_key_formatting(self):
     """
     Ensures attribute keys formatted following underscore convention.
     """
     mock_attributes = {
         'integer': 1234567890,
         'a-float-number': 0.0123456789,
         'simple_string': 'hello, world!',
         'dashed-string': 'hello-world_!',
         'an-Object': {'aFirstKey': 1, 'second-key': '2nd'},
         'Array': [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],
         'OK': True,
         'BadStatus': False,
         'noStatus': None
     }
     primary_data = {
         'attributes': mock_attributes
     }
     attributes = api_utils.parse_attributes(primary_data)
     self.assertEqual(attributes['integer'], mock_attributes['integer'])
     self.assertEqual(attributes['a_float_number'], mock_attributes['a-float-number'])
     self.assertEqual(attributes['simple_string'], mock_attributes['simple_string'])
     self.assertEqual(attributes['dashed_string'], mock_attributes['dashed-string'])
     self.assertEqual(attributes['an_object'], OrderedDict(mock_attributes['an-Object']))
     self.assertEqual(attributes['array'], mock_attributes['Array'])
     self.assertEqual(attributes['ok'], mock_attributes['OK'])
     self.assertEqual(attributes['bad_status'], mock_attributes['BadStatus'])
     self.assertEqual(attributes['no_status'], mock_attributes['noStatus'])
     test_object = attributes['an_object']
     self.assertEqual(test_object['aFirstKey'], 1)
     self.assertEqual(test_object['second-key'], '2nd')
     self.assertEqual(attributes['dashed_string'], 'hello-world_!')
Example #2
0
 def test_missing_attributes(self):
     """
     Ensures a ``None`` for missing ``attributes`` member in primary data.
     """
     primary_data = {'no_attributes': {}}
     attributes = api_utils.parse_attributes(primary_data)
     self.assertIsNone(attributes)