Beispiel #1
0
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
Beispiel #2
0
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
Beispiel #3
0
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
Beispiel #4
0
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
Beispiel #5
0
def test_should_render_obj(type, expected):
    item = TxItem(type=type, obj=None, condition=None, atomic=False)
    assert item.should_render_obj is expected
Beispiel #6
0
def test_is_update(type, expected):
    item = TxItem(type=type, obj=None, condition=None, atomic=False)
    assert item.is_update is expected