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_dynamo_name(): """ Returns model name unless dynamo name is specified """ column = bloop.Column(bloop.Integer) # Normally set when a class is defined column.model_name = "foo" assert column.dynamo_name == "foo" column = bloop.Column(bloop.Integer, name="foo") column.model_name = "bar" assert column.dynamo_name == "foo"
def test_contains(): value = object column = bloop.Column(bloop.Integer) condition = column.contains(value) assert isinstance(condition, bloop.condition.Contains) assert condition.column is column assert condition.value == value
def test_begins_with(): value = object column = bloop.Column(bloop.Integer) condition = column.begins_with(value) assert isinstance(condition, bloop.condition.BeginsWith) assert condition.column is column assert condition.value == value
def test_in(): values = [object() for _ in range(3)] column = bloop.Column(bloop.Integer) condition = column.in_(values) assert isinstance(condition, bloop.condition.In) assert condition.column is column assert condition.values == values
def test_comparison(operation): column = bloop.Column(bloop.Integer) value = object() condition = operation(column, value) assert condition.comparator is operation assert condition.column is column assert condition.value is value
def test_between(): lower, upper = object(), object() column = bloop.Column(bloop.Integer) condition = column.between(lower, upper) assert isinstance(condition, bloop.condition.Between) assert condition.column is column assert condition.lower is lower assert condition.upper is upper
def test_column_path(): """ Paths can be iteratively built up, with strings or ints as keys """ column = bloop.Column(bloop.Integer) comparison = column["foo"] assert comparison.path == ["foo"] comparison = column["f"]["o"]["o"]["b"]["a"]["r"] assert comparison.path == list("foobar") with pytest.raises(ValueError): column[object()]
def test_equals_alias_exists(): """ == and != should map to attribute_not_exists and attribute_exists when compared to None """ column = bloop.Column(bloop.Integer) condition = column.is_(None) assert isinstance(condition, bloop.condition.AttributeExists) assert condition.column is column assert condition.negate is True condition = column.is_not(None) assert isinstance(condition, bloop.condition.AttributeExists) assert condition.column is column assert condition.negate is False
class Admin(User): admin_id = bloop.Column(bloop.Integer, hash_key=True)
class SubModel(base_model): id = bloop.Column(bloop.String, 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 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 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 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)
class Model(bloop.new_base()): id = bloop.Column(bloop.UUID, hash_key=True) counter = bloop.Column(bloop.Integer)