示例#1
0
def test_lsi_init_throughput():
    """Can't set throughput when creating an LSI"""
    with pytest.raises(InvalidIndex):
        LocalSecondaryIndex(range_key="range",
                            projection="keys",
                            write_units=1)

    with pytest.raises(InvalidIndex):
        LocalSecondaryIndex(range_key="range", projection="keys", read_units=1)
示例#2
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")
示例#3
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)
示例#4
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_
示例#5
0
def test_lsi_repr():
    index = LocalSecondaryIndex(projection="all", range_key="key", name="f")
    index.model = User
    index.model_name = "by_foo"
    assert repr(index) == "<LSI[User.by_foo=all]>"
示例#6
0
 class Model(BaseModel):
     name = Column(String, hash_key=True)
     other = Column(String, range_key=True)
     joined = Column(String)
     by_joined = LocalSecondaryIndex(range_key="joined", projection="keys")
示例#7
0
def test_lsi_specifies_hash_key():
    with pytest.raises(InvalidIndex):
        LocalSecondaryIndex(hash_key="blah",
                            range_key="foo",
                            projection="keys")
示例#8
0
 class Model(BaseModel):
     id = Column(UUID, hash_key=True)
     another = Column(UUID)
     by_another = LocalSecondaryIndex(range_key="another",
                                      projection="keys")
示例#9
0
 class InvalidLSI(BaseModel):
     id = Column(UUID, hash_key=True)
     index = LocalSecondaryIndex(range_key="id", projection="keys")