Пример #1
0
 def test_serialize_dict_tag_set(self):
     test_values = {
         "id":
         123,
         "tags": [{
             "id": 1,
             "name": "foo"
         }, {
             "id": 2,
             "name": "bar"
         }, {
             "id": 3,
             "name": "baz"
         }],
     }
     test = Record(test_values, None, None).serialize()
     self.assertEqual(len(test["tags"]), 3)
Пример #2
0
 def test_attribute_access(self):
     test_values = {
         "id": 123,
         "units": 12,
         "nested_dict": {
             "id": 222,
             "name": "bar"
         },
         "int_list": [123, 321, 231],
     }
     test_obj = Record(test_values, None, None)
     self.assertEqual(test_obj.id, 123)
     self.assertEqual(test_obj.units, 12)
     self.assertEqual(test_obj.nested_dict.name, "bar")
     self.assertEqual(test_obj.int_list[1], 321)
     with self.assertRaises(AttributeError) as _:
         test_obj.nothing
Пример #3
0
 def test_dict_access(self):
     test_values = {
         "id": 123,
         "units": 12,
         "nested_dict": {
             "id": 222,
             "name": "bar"
         },
         "int_list": [123, 321, 231],
     }
     test_obj = Record(test_values, None, None)
     self.assertEqual(test_obj["id"], 123)
     self.assertEqual(test_obj["units"], 12)
     self.assertEqual(test_obj["nested_dict"]["name"], "bar")
     self.assertEqual(test_obj["int_list"][1], 321)
     with self.assertRaises(KeyError) as _:
         test_obj["nothing"]
Пример #4
0
 def test_dict(self):
     test_values = {
         "id":
         123,
         "custom_fields": {
             "foo": "bar"
         },
         "string_field":
         "foobar",
         "int_field":
         1,
         "nested_dict": {
             "id": 222,
             "name": "bar"
         },
         "tags": ["foo", "bar"],
         "int_list": [123, 321, 231],
         "empty_list": [],
         "record_list": [
             {
                 "id": 123,
                 "name": "Test",
                 "str_attr": "foo",
                 "int_attr": 123,
                 "custom_fields": {
                     "foo": "bar"
                 },
                 "tags": ["foo", "bar"],
             },
             {
                 "id": 321,
                 "name": "Test 1",
                 "str_attr": "bar",
                 "int_attr": 321,
                 "custom_fields": {
                     "foo": "bar"
                 },
                 "tags": ["foo", "bar"],
             },
         ],
     }
     test = Record(test_values, None, None)
     self.assertEqual(dict(test), test_values)
Пример #5
0
    def test_serialize_tag_list_order(self):
        """Add tests to ensure we're preserving tag order

        This test could still give false-negatives, but making the tag list
        longer helps mitigate that.
        """

        test_tags = [
            "one",
            "two",
            "three",
            "four",
            "five",
            "six",
            "seven",
            "eight",
            "nine",
            "ten",
        ]
        test = Record({"id": 123, "tags": test_tags}, None, None).serialize()
        self.assertEqual(test["tags"], test_tags)
Пример #6
0
 def test_serialize_string_tag_set(self):
     test_values = {"id": 123, "tags": ["foo", "bar", "foo"]}
     test = Record(test_values, None, None).serialize()
     self.assertEqual(len(test["tags"]), 2)
Пример #7
0
 def test_serialize_list_of_ints(self):
     test_values = {"id": 123, "units": [12]}
     test_obj = Record(test_values, None, None)
     test = test_obj.serialize()
     self.assertEqual(test["units"], [12])
Пример #8
0
 def test_hash(self):
     endpoint = Mock()
     endpoint.name = "test-endpoint"
     test = Record({}, None, endpoint)
     self.assertIsInstance(hash(test), int)