Example #1
0
 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")
Example #2
0
 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)
Example #3
0
    class Abstract(BaseModel):
        class Meta:
            abstract = True

        id = Column(Integer, hash_key=True)
        other = Column(Integer)
        by_other = GlobalSecondaryIndex(projection="all", hash_key="other")
Example #4
0
    class MyUser(BaseModel):
        class Meta:
            backups = {"enabled": True}
            ttl = {"column": "expiry"}

        id = Column(Integer, hash_key=True)
        expiry = Column(Timestamp)
Example #5
0
    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")
Example #6
0
class Email(BaseModel):
    class Meta:
        stream = {
            "include": {"new", "old"},
            "arn": "stream-arn"
        }
    id = Column(Integer, hash_key=True)
    data = Column(String)
Example #7
0
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")
Example #8
0
    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")
Example #9
0
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]]>"
Example #10
0
    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)
Example #11
0
    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_
Example #12
0
    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)
Example #13
0
 class StreamModel(BaseModel):
     class Meta:
         stream = {
             "include": {"new"},
             "arn": "test-arn-manually-set"
         }
     id = Column(String, hash_key=True)
Example #14
0
 class MyModel(BaseModel):
     class Meta:
         read_units = 1
         write_units = 1
         stream = {
             "include": ["keys"]
         }
     id = Column(String, hash_key=True)
Example #15
0
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_
Example #16
0
    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)
Example #17
0
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]>"
Example #18
0
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"
Example #19
0
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())
Example #20
0
 class Model(BaseModel):
     name = Column(String, hash_key=True)
     other = Column(String)
     by_joined = GlobalSecondaryIndex(hash_key="other", projection="keys")
Example #21
0
 class LocalModel(BaseModel):
     class Meta:
         table_name = "my-table-name"
     id = Column(Integer, hash_key=True)
Example #22
0
 class MyUser(BaseModel):
     class Meta:
         ttl = {"column": "expiry"}
     id = Column(Integer, hash_key=True)
     expiry = Column(Timestamp)
Example #23
0
 class MyUser(BaseModel):
     id = Column(Integer, hash_key=True)
Example #24
0
 class Concrete(BaseModel):
     id = Column(Integer, hash_key=True)
Example #25
0
 class AlsoConcrete(AlsoAbstract):
     id = Column(Integer, hash_key=True)
Example #26
0
 class AlsoAbstract(Concrete):
     class Meta:
         abstract = True
     id = Column(Integer, hash_key=True)
Example #27
0
 class Abstract(BaseModel):
     class Meta:
         abstract = True
     id = Column(Integer, hash_key=True)
Example #28
0
 class Admin(User):
     admin_id = Column(Integer, hash_key=True)
     other = Column(Integer)
Example #29
0
class HashAndRange(BaseModel):
    class Meta:
        abstract = True

    foo = Column(Integer, hash_key=True)
    bar = Column(Integer, range_key=True)
Example #30
0
 class HashAndRange(BaseModel):
     foo = Column(Integer, hash_key=True)
     bar = Column(Integer, range_key=True)