Exemplo n.º 1
0
 def test_map_of_list_of_map(self):
     family_attributes = {
         'phillips': [{
             'name': 'Justin',
             'age': 31,
             'height': 187.96
         }, {
             'name': 'Galen',
             'age': 29,
             'height': 193.04,
             'male': True
         }, {
             'name': 'Colin',
             'age': 32,
             'height': 203.2,
             'male': True,
             'hasChild': True
         }],
         'workman': [{
             'name': 'Mandy',
             'age': 29,
             'height': 157.48,
             'female': True
         }, {
             'name': 'Rodney',
             'age': 31,
             'height': 175.26,
             'hasChild': False
         }]
     }
     serialized = MapAttribute().serialize(family_attributes)
     assert MapAttribute().deserialize(serialized) == family_attributes
Exemplo n.º 2
0
 def test_map_of_list(self):
     grocery_list = {
         'fruit': ['apple', 'pear', 32],
         'veggies': ['broccoli', 'potatoes', 5]
     }
     serialized = MapAttribute().serialize(grocery_list)
     assert MapAttribute().deserialize(serialized) == grocery_list
Exemplo n.º 3
0
 def test_attribute_children(self):
     person_attribute = {
         'name': 'Justin',
         'age': 12345678909876543211234234324234,
         'height': 187.96
     }
     attr = MapAttribute()
     serialized = attr.serialize(person_attribute)
     assert attr.deserialize(serialized) == person_attribute
Exemplo n.º 4
0
 def test_map_of_map(self):
     attribute = {
         'name': 'Justin',
         'metrics': {
             'age': 31,
             'height': 187.96
         }
     }
     attr = MapAttribute()
     serialized = attr.serialize(attribute)
     assert attr.deserialize(serialized) == attribute
Exemplo n.º 5
0
    async def test_raw_map_json_serialize(self):
        raw = {"foo": "bar", "num": 3, "nested": {"nestedfoo": "nestedbar"}}

        serialized_raw = json.dumps(raw, sort_keys=True)
        serialized_attr_from_raw = json.dumps(
            (await
             AttributeTestModel.initialize(map_attr=raw)).map_attr.as_dict(),
            sort_keys=True)
        serialized_attr_from_map = json.dumps(
            (await AttributeTestModel.initialize(map_attr=MapAttribute(**raw)
                                                 )).map_attr.as_dict(),
            sort_keys=True)

        assert serialized_attr_from_raw == serialized_raw
        assert serialized_attr_from_map == serialized_raw
Exemplo n.º 6
0
class AttributeTestModel(Model):
    class Meta:
        host = 'http://localhost:8000'
        table_name = 'test'

    binary_attr = BinaryAttribute()
    binary_set_attr = BinarySetAttribute()
    number_attr = NumberAttribute()
    number_set_attr = NumberSetAttribute()
    unicode_attr = UnicodeAttribute()
    unicode_set_attr = UnicodeSetAttribute()
    datetime_attr = UTCDateTimeAttribute()
    bool_attr = BooleanAttribute()
    json_attr = JSONAttribute()
    map_attr = MapAttribute()
Exemplo n.º 7
0
    def test_map_attribute_indexing(self):
        # Simulate initialization from inside an AttributeContainer
        my_map_attribute = MapAttribute(attr_name='foo.bar')
        my_map_attribute._make_attribute()
        my_map_attribute._update_attribute_paths(my_map_attribute.attr_name)

        condition = my_map_attribute['foo'] == 'baz'
        placeholder_names, expression_attribute_values = {}, {}
        expression = condition.serialize(placeholder_names, expression_attribute_values)
        assert expression == "#0.#1 = :0"
        assert placeholder_names == {'foo.bar': '#0', 'foo': '#1'}
        assert expression_attribute_values == {':0': {'S': 'baz'}}
Exemplo n.º 8
0
 class InnerMapAttribute(MapAttribute):
     map_attr = MapAttribute(attr_name='dyn_map_attr')
Exemplo n.º 9
0
 class NestedThing(MapAttribute):
     double_nested = MapAttribute()
     double_nested_renamed = MapAttribute(attr_name='something_else')
Exemplo n.º 10
0
 class TypedMap(MapAttribute):
     map_attr = MapAttribute()
Exemplo n.º 11
0
    def test_raw_map_iter(self):
        raw = {"foo": "bar", "num": 3, "nested": {"nestedfoo": "nestedbar"}}
        attr = MapAttribute(**raw)

        assert list(iter(raw)) == list(iter(attr))
Exemplo n.º 12
0
    def test_raw_map_access(self):
        raw = {"foo": "bar", "num": 3, "nested": {"nestedfoo": "nestedbar"}}
        attr = MapAttribute(**raw)

        for k, v in six.iteritems(raw):
            assert attr[k] == v
Exemplo n.º 13
0
 def test_null_attribute_raw_map(self):
     null_attribute = {'skip': None}
     attr = MapAttribute()
     serialized = attr.serialize(null_attribute)
     assert serialized == {'skip': {'NULL': True}}
Exemplo n.º 14
0
class DefaultsMap(MapAttribute):
    map_field = MapAttribute(default={})