def wx(engine): """prepared write tx with one item""" user = User(id="numberoverzero") other = User(id="other") items = [ TxItem.new("save", user, condition=User.id.is_(None)), TxItem.new("delete", other), TxItem.new("check", other, condition=User.email.begins_with("foo")) ] tx = PreparedTransaction() tx.prepare(engine, "w", items) return tx
def rx(engine): """prepared read tx with one item""" user = User(id="numberoverzero") items = [TxItem.new("get", user)] tx = PreparedTransaction() tx.prepare(engine, "r", items) return tx
def test_read_item(engine): engine.bind(User) user = User(id="numberoverzero") tx = ReadTransaction(engine) tx.load(user) p = tx.prepare() expected_items = [TxItem.new("get", user, None, False)] assert tx._items == expected_items assert p.items == expected_items assert p.first_commit_at is None
def test_delete_complex_item(engine): engine.bind(User) user = User(id="numberoverzero") tx = WriteTransaction(engine) condition = User.id.begins_with("foo") tx.delete(user, condition=condition, atomic=True) p = tx.prepare() expected_items = [TxItem.new("delete", user, condition, True)] assert tx._items == expected_items assert p.items == expected_items assert p.first_commit_at is None assert len(p._request) == 1 entry = p._request[0]["Delete"] expected_fields = { "Key", "TableName", "ConditionExpression", "ExpressionAttributeNames", "ExpressionAttributeValues" } assert set(entry.keys()) == expected_fields
def test_should_render_obj(type, expected): item = TxItem(type=type, obj=None, condition=None, atomic=False) assert item.should_render_obj is expected
def test_is_update(type, expected): item = TxItem(type=type, obj=None, condition=None, atomic=False) assert item.is_update is expected