Example #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."
Example #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
Example #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 == {}
Example #4
0
def db():
    with DB() as db:
        db.create("ninjas", DB_SCHEMA, "ninja")
        db.insert("ninjas", NINJAS)

        yield db