Ejemplo n.º 1
0
 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"])
Ejemplo n.º 2
0
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())
Ejemplo n.º 3
0
    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")
Ejemplo n.º 4
0
def test_abstract_not_inherited():
    base = new_base()

    class Concrete(base):
        pass

    assert base.Meta.abstract
    assert not Concrete.Meta.abstract
Ejemplo n.º 5
0
    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"])
Ejemplo n.º 6
0
 class Neither(new_base()):
     pass
Ejemplo n.º 7
0
 class Model(bloop.new_base()):
     id = bloop.Column(bloop.UUID, hash_key=True)
     counter = bloop.Column(bloop.Integer)
Ejemplo n.º 8
0
    class Other(new_base()):
        class Meta:
            table_name = "table_name"
            write_units = 3

        id = Column(UUID, hash_key=True)
Ejemplo n.º 9
0
 class DoubleRange(new_base()):
     id = Column(UUID, range_key=True)
     other = Column(UUID, range_key=True)
Ejemplo n.º 10
0
 class Model(bloop.new_base()):
     id = bloop.Column(bloop.Integer, hash_key=True)
     data = bloop.Column(bloop.TypedMap(bloop.UUID))
Ejemplo n.º 11
0
    class Abstract(bloop.new_base()):
        class Meta:
            abstract = True

        id = bloop.Column(bloop.Integer, hash_key=True)
Ejemplo n.º 12
0
 class Concrete(bloop.new_base()):
     pass
Ejemplo n.º 13
0
 class Abstract(bloop.new_base()):
     class Meta:
         abstract = True
Ejemplo n.º 14
0
 class UnboundModel(bloop.new_base()):
     id = bloop.Column(bloop.String, hash_key=True)
Ejemplo n.º 15
0
 class HashAndRange(bloop.new_base()):
     foo = bloop.Column(bloop.Integer, hash_key=True)
     bar = bloop.Column(bloop.Integer, range_key=True)
Ejemplo n.º 16
0
 class Both(new_base()):
     h = hash_column()
     r = range_column()
Ejemplo n.º 17
0
 class DoubleHash(new_base()):
     id = Column(UUID, hash_key=True)
     other = Column(UUID, hash_key=True)
Ejemplo n.º 18
0
 class Model(bloop.new_base()):
     id = bloop.Column(bloop.Integer, hash_key=True, name='this.is.id')
     data = bloop.Column(DocumentType)
Ejemplo n.º 19
0
 class InvalidIndex(new_base()):
     id = Column(UUID, hash_key=True)
     index = LocalSecondaryIndex(range_key="id")
Ejemplo n.º 20
0
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
Ejemplo n.º 21
0
 class Model(new_base()):
     id = Column(UUID, hash_key=True)
     another = Column(UUID)
     by_another = LocalSecondaryIndex(range_key="another")
Ejemplo n.º 22
0
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
Ejemplo n.º 23
0
 class Model(new_base()):
     id = Column(UUID, hash_key=True)
Ejemplo n.º 24
0
    class Other(new_base()):
        class Meta:
            read_units = 2
            write_units = 3

        id = Column(UUID, hash_key=True)
Ejemplo n.º 25
0
 class HashOnly(new_base()):
     h = hash_column()
Ejemplo n.º 26
0
 class RangeOnly(new_base()):
     r = range_column()
Ejemplo n.º 27
0
 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)
Ejemplo n.º 28
0
        '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")