Exemplo n.º 1
0
def test_delete_columns():
    t = Table(primary_id="primary_key")
    t.create_column("a")
    t.create_column("b")
    del t["b"]

    assert t.columns == ["primary_key", "a"]
Exemplo n.º 2
0
def test_delete_invalid_columns():
    t = Table()
    t.create_column("a")
    t.create_column("b")

    with pytest.raises(ColumnDoesNotExist):
        del t["c"]
Exemplo n.º 3
0
def test_unique_constraint():
    t = Table()
    t.create_column("a", unique=True)
    t.insert({"a": 1, "b": 2})
    t.insert({"a": 2})

    with pytest.raises(UniqueConstraintError):
        t.insert({"a": 1})
Exemplo n.º 4
0
def test_find_with_multiple_default_vals():
    t = Table(primary_id="b")
    t.create_column("firstname", default="John")
    t.create_column("lastname", default="Smith")
    t.insert(dict(b=1))
    t.insert(dict(b=2))
    t.insert(dict(b=3, lastname="Doe"))

    result = t.find(lastname="Smith")
    result2 = t.find(b=2)
    result3 = t.find(firstname="John", lastname="Smith")

    assert [r["b"] for r in result] == [1, 2]
    assert list(result2) == [dict(b=2, firstname="John", lastname="Smith")]
    assert [r["b"] for r in result3] == [1, 2]
Exemplo n.º 5
0
def test_add_columns():
    t = Table(primary_id="id")
    t.create_column("a")
    t.create_column("b")

    assert t.columns == ["id", "a", "b"]