class Person(BaseModel): Type = UnicodeAttribute(default='person') FirstName = UnicodeAttribute() LastName = UnicodeAttribute() Age = NumberAttribute(default=0) CreateDate = UTCDateTimeAttribute(attr_name='CreateDateTime') ValueList = ListAttribute() ValueMap = MapAttribute() DoesNotExist = DoesNotExist
class TestModel(Model): '''Test model with meta''' class Meta(Model.Meta): table_name = 'falcano-map-attr-e2e' billing_mode = 'PAY_PER_REQUEST' PK = UnicodeAttribute(hash_key=True) SK = UnicodeAttribute(range_key=True) Data = MapAttribute() Type = UnicodeAttribute(default='test_map_attribute')
def test_raw_map_json_serialize(): raw = {"foo": "bar", "num": 3, "nested": {"nestedfoo": "nestedbar"}} serialized_raw = json.dumps(raw, sort_keys=True) serialized_attr_from_raw = json.dumps( TestModel(test_map=raw).test_map.as_dict(), sort_keys=True) serialized_attr_from_map = json.dumps( TestModel(test_map=MapAttribute(**raw)).test_map.as_dict(), sort_keys=True) assert serialized_attr_from_raw == serialized_raw assert serialized_attr_from_map == serialized_raw
class OuterMapAttribute(MapAttribute): mid_map = MapAttribute()
class TestModel(Model): test_map = MapAttribute(attr_name="test_name", default={})
class InnerMapAttribute(MapAttribute): test_map = MapAttribute(attr_name='dyn_test_map')
class TestDefaultsMap(MapAttribute): map_field = MapAttribute(default={}) string_field = UnicodeAttribute(null=True)
class TypedMap(MapAttribute): test_map = MapAttribute()