示例#1
0
def test_update():
    t = Table(primary_id="id")
    t.insert({"a": 1, "b": 2})
    t.insert({"a": 2, "b": 5})
    t.insert({"a": 3, "b": 6})
    t.insert({"a": 3, "b": 7})
    t.insert({"a": 3, "b": 8})

    t.update(where={"a": 2}, b=5)
    result = next(t.find(a=2))
    assert result["b"] == 5
    t.update(dict(a=3), b=10)

    result = list(t.find(a=3))
    assert all(row["b"] == 10 for row in result)
示例#2
0
def test_update_single():
    t = Table()

    row1 = dict(vorname="rainer", nachname="greiff")
    row2 = dict(vorname="rainer", nachname="greiff")
    row3 = dict(vorname="rainer", nachname="erhard")

    for row in [row1, row2, row3]:
        t.insert(row)

    row_vals_before = set(t["vorname"].values["rainer"])
    t.update(dict(vorname="rainer", nachname="erhard"), n_values=45)

    row_vals_after = set(t["vorname"].values["rainer"])
    result = list(t.find(n_values=45))
    assert len(result) == 1
    assert row_vals_before == row_vals_after
示例#3
0
def test_update_no_vals():
    t = Table(primary_id="a")
    row = {"a": 1, "b": 2}
    t.insert({"a": 1, "b": 2})
    t.update(where={"a": 2}, b=5)
    assert list(t.all()) == [row]