Beispiel #1
0
def test_wrong_pk():
    with pytest.raises(SchemaError) as e:
        with DB() as db:
            db.create("ninjas", DB_SCHEMA, "ID")

    assert str(
        e.value) == "The provided primary key must be part of the schema."
Beispiel #2
0
def test_create(table, schema, pk):
    with DB() as db:
        assert db.num_transactions == 0
        db.create(table, schema, pk)
        query = (
            f"SELECT name FROM sqlite_master WHERE type= 'table' AND name='{table}';"
        )
        output = db.cursor.execute(query).fetchall()
        assert len(output) == 1
        assert db.num_transactions == 0
Beispiel #3
0
def test_empty_db():
    db = DB()
    assert db.location == ":memory:"
    assert db.cursor is None
    assert db.connection is None
    assert db.table_schemas == {}
Beispiel #4
0
def db():
    with DB() as db:
        db.create("ninjas", DB_SCHEMA, "ninja")
        db.insert("ninjas", NINJAS)

        yield db