class Visit(bloop.new_base()): page = bloop.Column(bloop.String, hash_key=True) visitor = bloop.Column(bloop.Integer) date = bloop.Column(bloop.String) not_projected = bloop.Column(bloop.Integer) by_date = bloop.GlobalSecondaryIndex(hash_key="date", projection=["visitor"])
def test_context(engine): engine.config["atomic"] = True user_id = uuid.uuid4() user = User(id=user_id, name="foo") expected = { "TableName": "User", "UpdateExpression": "SET #n0=:v1", "ExpressionAttributeValues": { ":v1": { "S": "foo" } }, "ExpressionAttributeNames": { "#n0": "name" }, "Key": { "id": { "S": str(user_id) } } } with engine.context(atomic=False) as eng: eng.save(user) engine.client.update_item.assert_called_once_with(expected) # EngineViews can't bind with pytest.raises(RuntimeError): with engine.context() as eng: eng.bind(base=bloop.new_base())
class Model(new_base()): 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") by_another = LocalSecondaryIndex(range_key="last")
def test_abstract_not_inherited(): base = new_base() class Concrete(base): pass assert base.Meta.abstract assert not Concrete.Meta.abstract
class Model(new_base()): id = Column(UUID, hash_key=True) other = Column(UUID, range_key=True) another = Column(UUID) date = Column(DateTime) boolean = Column(Boolean) g_all = Global(hash_key="another", range_key="date", projection="all") g_key = Global(hash_key="another", projection="keys_only") g_inc = Global(hash_key="other", projection=["another", "date"]) l_all = Local(range_key="another", projection="all") l_key = Local(range_key="another", projection="keys_only") l_inc = Local(range_key="another", projection=["date"])
class Neither(new_base()): pass
class Model(bloop.new_base()): id = bloop.Column(bloop.UUID, hash_key=True) counter = bloop.Column(bloop.Integer)
class Other(new_base()): class Meta: table_name = "table_name" write_units = 3 id = Column(UUID, hash_key=True)
class DoubleRange(new_base()): id = Column(UUID, range_key=True) other = Column(UUID, range_key=True)
class Model(bloop.new_base()): id = bloop.Column(bloop.Integer, hash_key=True) data = bloop.Column(bloop.TypedMap(bloop.UUID))
class Abstract(bloop.new_base()): class Meta: abstract = True id = bloop.Column(bloop.Integer, hash_key=True)
class Concrete(bloop.new_base()): pass
class Abstract(bloop.new_base()): class Meta: abstract = True
class UnboundModel(bloop.new_base()): id = bloop.Column(bloop.String, hash_key=True)
class HashAndRange(bloop.new_base()): foo = bloop.Column(bloop.Integer, hash_key=True) bar = bloop.Column(bloop.Integer, range_key=True)
class Both(new_base()): h = hash_column() r = range_column()
class DoubleHash(new_base()): id = Column(UUID, hash_key=True) other = Column(UUID, hash_key=True)
class Model(bloop.new_base()): id = bloop.Column(bloop.Integer, hash_key=True, name='this.is.id') data = bloop.Column(DocumentType)
class InvalidIndex(new_base()): id = Column(UUID, hash_key=True) index = LocalSecondaryIndex(range_key="id")
import arrow import uuid from bloop import (Column, Integer, DateTime, UUID, GlobalSecondaryIndex, String, new_base, engine_for_profile) # ================================================ # Model setup # ================================================ engine = engine_for_profile("test-user-bloop") Base = new_base() class Account(Base): class Meta: read_units = 5 write_units = 2 id = Column(UUID, hash_key=True) name = Column(String) email = Column(String) by_email = GlobalSecondaryIndex(hash_key='email', projection='keys_only', write_units=1, read_units=5) class Tweet(Base): class Meta: write_units = 10
class Model(new_base()): id = Column(UUID, hash_key=True) another = Column(UUID) by_another = LocalSecondaryIndex(range_key="another")
def test_create_abstract_raises(client): abstract_model = bloop.new_base() with pytest.raises(bloop.exceptions.AbstractModelException) as excinfo: client.create_table(abstract_model) assert excinfo.value.model is abstract_model
class Model(new_base()): id = Column(UUID, hash_key=True)
class Other(new_base()): class Meta: read_units = 2 write_units = 3 id = Column(UUID, hash_key=True)
class HashOnly(new_base()): h = hash_column()
class RangeOnly(new_base()): r = range_column()
class Visit(bloop.new_base()): hash = bloop.Column(bloop.String, hash_key=True) range = bloop.Column(bloop.Integer, range_key=True) non_key = bloop.Column(bloop.Integer)
'Rating': Float(), 'Stock': Integer(), 'Description': Map(**{ 'Heading': String, 'Body': String, 'Specifications': String }), 'Id': UUID, 'Updated': DateTime }) BaseModel = new_base() class Document(BaseModel): id = Column(Integer, hash_key=True) data = Column(DocumentType) numbers = Column(List(Integer)) class User(BaseModel): id = Column(UUID, hash_key=True) age = Column(Integer) name = Column(String) email = Column(String) joined = Column(DateTime, name="j") by_email = GlobalSecondaryIndex(hash_key="email", projection="all")