Exemple #1
0
def test_get_all_ordered_descending():
    t = Table(primary_id="a")
    t.insert({"a": 1, "b": 2})
    t.insert({"a": 2, "b": 5})
    t.insert({"a": 3, "b": 6})

    results = t.all(ordered="descending")

    assert [r["b"] for r in results] == [6, 5, 2]
Exemple #2
0
def test_number_of_rows():
    table = Table(primary_id="pk")
    rows = []
    for i in range(167):
        row = {"pk": i, "a": 1, "b": 2, "c": 0}
        table.insert(row)
        rows.append(row)

    assert list(table.all()) == rows
Exemple #3
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
Exemple #4
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
Exemple #5
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
    }]
Exemple #6
0
def test_invalid_arg_ordered():
    t = Table(primary_id="a")
    t.insert({"a": 1})

    with pytest.raises(ValueError):
        list(t.all(ordered="foo"))
Exemple #7
0
def test_single_insert_given_primary():
    table = Table(primary_id="pk")
    row = {"pk": 1, "a": 1, "b": 2, "c": 0}
    table.insert(row)
    assert list(table.all()) == [{**row}]
Exemple #8
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]