class FirstModel(BaseModel): class Meta: table_name = "SharedTable" id = Column(String, hash_key=True) range = Column(String, range_key=True) first = Column(String) as_date = Column(DateTime, dynamo_name="shared")
class MyModel(BaseModel): class Meta: read_units = 1 write_units = 1 id = Column(String, hash_key=True) other = Column(String) by_other = GlobalSecondaryIndex(projection="keys", hash_key=other)
class Abstract(BaseModel): class Meta: abstract = True id = Column(Integer, hash_key=True) other = Column(Integer) by_other = GlobalSecondaryIndex(projection="all", hash_key="other")
class MyUser(BaseModel): class Meta: backups = {"enabled": True} ttl = {"column": "expiry"} id = Column(Integer, hash_key=True) expiry = Column(Timestamp)
class SecondModel(BaseModel): class Meta: table_name = "SharedTable" id = Column(String, hash_key=True) range = Column(String, range_key=True) second = Column(String) as_string = Column(String, dynamo_name="shared")
class Email(BaseModel): class Meta: stream = { "include": {"new", "old"}, "arn": "stream-arn" } id = Column(Integer, hash_key=True) data = Column(String)
def test_unsupported_mixin_comparison_conditions(op, typedef): class Model(BaseModel): id = Column(Integer, hash_key=True) column = Column(typedef, dynamo_name="d") column.model = Model column._name = "c" with pytest.raises(InvalidCondition): op(column, "value")
class Model(BaseModel): id = Column(UUID, hash_key=True) other = Column(DateTime, range_key=True) another = Column(UUID) last = Column(String) by_last = GlobalSecondaryIndex(hash_key="another", range_key="last", projection="keys") by_another = LocalSecondaryIndex(range_key="last", projection="keys")
def test_column_repr_path(): column = Column(Integer, name="f") column.model = User column.model_name = "foo" assert repr( column[3]["foo"]["bar"][2][1]) == "<Proxy[User.foo[3].foo.bar[2][1]]>" column.hash_key = True assert repr( column[3]["foo"]["bar"][2][1]) == "<Proxy[User.foo[3].foo.bar[2][1]]>"
class Blob(BaseModel): def __init__(self, *args, **kwargs): nonlocal init_called # No args, kwargs provided to custom init function assert not args assert not kwargs init_called = True super().__init__(**kwargs) id = Column(String, hash_key=True) data = Column(String)
class TestModel(BaseModel): # Included in an "all" projection, not "keys" not_projected = Column(Integer) # Included in "include" projections inc = Column(Integer) model_hash = Column(Integer, hash_key=True) model_range = model_range_ index_hash = index_hash_ index_range = index_range_ by_index = by_index_
class Model(BaseModel): id = Column(Integer, hash_key=True) foo = Column(Integer) bar = Column(Integer) baz = Column(Integer) by_foo = GlobalSecondaryIndex(projection=["foo"], hash_key=bar, range_key="baz") by_bar = GlobalSecondaryIndex(projection=[foo], hash_key="bar", range_key=baz)
class StreamModel(BaseModel): class Meta: stream = { "include": {"new"}, "arn": "test-arn-manually-set" } id = Column(String, hash_key=True)
class MyModel(BaseModel): class Meta: read_units = 1 write_units = 1 stream = { "include": ["keys"] } id = Column(String, hash_key=True)
def model_for(has_model_range=False, has_index=False, has_index_range=False, index_type="gsi", index_projection="all", strict=True): """Not all permutations are possible. Impossible selections will always self-correct. For instance, has_model_range=False, has_index=True, index_type="gsi" can't happen. Instead, the model won't have an index.""" model_range_ = None index_hash_ = None index_range_ = None by_index_ = None if has_model_range: model_range_ = Column(Integer, range_key=True) # Sets up index_hash, index_range, by_index if has_index: if index_type == "gsi": index_hash_ = Column(Integer) if has_index_range: index_range_ = Column(Integer) by_index_ = GlobalSecondaryIndex( projection=index_projection, hash_key="index_hash", range_key="index_range" if has_index_range else None) elif index_type == "lsi" and has_model_range and has_index_range: index_range_ = Column(Integer) by_index_ = LocalSecondaryIndex(projection=index_projection, range_key="index_range", strict=strict) class TestModel(BaseModel): # Included in an "all" projection, not "keys" not_projected = Column(Integer) # Included in "include" projections inc = Column(Integer) model_hash = Column(Integer, hash_key=True) model_range = model_range_ index_hash = index_hash_ index_range = index_range_ by_index = by_index_ return TestModel, by_index_
class Model(BaseModel): id = Column(UUID, hash_key=True) other = Column(UUID, range_key=True) another = Column(UUID) date = Column(DateTime) boolean = Column(Boolean) g_all = GlobalSecondaryIndex(hash_key="another", range_key="date", projection="all") g_key = GlobalSecondaryIndex(hash_key="another", projection="keys") g_inc = GlobalSecondaryIndex(hash_key="other", projection=["another", "date"]) l_all = LocalSecondaryIndex(range_key="another", projection="all") l_key = LocalSecondaryIndex(range_key="another", projection="keys") l_inc = LocalSecondaryIndex(range_key="another", projection=["date"]) l_not_strict = LocalSecondaryIndex(range_key="another", projection=["date"], strict=False)
def test_column_repr(): column = Column(Integer, name="f") column.model = User column.model_name = "foo" assert repr(column) == "<Column[User.foo]>" column.hash_key = True assert repr(column) == "<Column[User.foo=hash]>" column.hash_key = False column.range_key = True assert repr(column) == "<Column[User.foo=range]>"
def test_column_dynamo_name(): """ Returns model name unless dynamo name is specified """ column = Column(Integer) # Normally set when a class is defined column.model_name = "foo" assert column.dynamo_name == "foo" column = Column(Integer, name="foo") column.model_name = "bar" assert column.dynamo_name == "foo"
def test_unsupported_mixin_function_conditions(op, typedefs, args): class Model(BaseModel): id = Column(Integer, hash_key=True) for typedef in typedefs: column = Column(typedef, dynamo_name="d") column.model = Model column._name = "c" with pytest.raises(InvalidCondition): getattr(column, op)(*args) column.begins_with(object())
class Model(BaseModel): name = Column(String, hash_key=True) other = Column(String) by_joined = GlobalSecondaryIndex(hash_key="other", projection="keys")
class LocalModel(BaseModel): class Meta: table_name = "my-table-name" id = Column(Integer, hash_key=True)
class MyUser(BaseModel): class Meta: ttl = {"column": "expiry"} id = Column(Integer, hash_key=True) expiry = Column(Timestamp)
class MyUser(BaseModel): id = Column(Integer, hash_key=True)
class Concrete(BaseModel): id = Column(Integer, hash_key=True)
class AlsoConcrete(AlsoAbstract): id = Column(Integer, hash_key=True)
class AlsoAbstract(Concrete): class Meta: abstract = True id = Column(Integer, hash_key=True)
class Abstract(BaseModel): class Meta: abstract = True id = Column(Integer, hash_key=True)
class Admin(User): admin_id = Column(Integer, hash_key=True) other = Column(Integer)
class HashAndRange(BaseModel): class Meta: abstract = True foo = Column(Integer, hash_key=True) bar = Column(Integer, range_key=True)
class HashAndRange(BaseModel): foo = Column(Integer, hash_key=True) bar = Column(Integer, range_key=True)