예제 #1
0
def test_delete_simple():
    t = Table()
    t.insert(dict(b=2))
    t.insert(dict(a="John"))
    t.insert(dict(a="John"))
    t.delete(a="John")

    assert list(t.find(a="John")) == []
    assert len(list(t.all())) == 1
예제 #2
0
def test_invalid_delete():
    t = Table(primary_id="a")
    row = {"a": 1, "foo": "bar"}
    t.insert(row)
    t.delete(a=5, ignore_errors=True)
    assert list(t.all()) == [row]

    with pytest.raises(KeyError):
        t.delete(a=5, ignore_errors=False)

    assert t.delete(a=1, ignore_errors=False) == 1
    assert len(t) == 0
예제 #3
0
def test_delete_find_delete():
    t = Table(primary_id="a")
    t.insert({"a": 1, "b": 2})
    t.insert({"a": 2, "b": 5})
    t.insert({"a": 3, "b": 6})

    result = list(t.find(a=1))
    assert len(result) == 1
    assert len(t) == 3

    n_delete = t.delete(a=1)

    result = list(t.find(a=1))
    print(result)
    assert n_delete == 1
    assert len(result) == 0
    assert len(t) == 2
    assert list(t.all(ordered="ascending")) == [{
        "a": 2,
        "b": 5
    }, {
        "a": 3,
        "b": 6
    }]