Пример #1
0
def test_database_drop_all():
    model_collection = create_model_collection()
    model_class = model_collection["model_class"]
    model_tables = model_collection["tables"]

    db = Database("sqlite://", model_class=model_class)
    conn = db.connect()
    db.create_all()

    count_tables = sa.text("SELECT COUNT(name) FROM sqlite_master")
    assert conn.execute(count_tables).scalar_one() == len(model_tables)
    db.drop_all()
    assert conn.execute(count_tables).scalar_one() == 0
Пример #2
0
def test_database_create_all():
    model_collection = create_model_collection()
    model_class = model_collection["model_class"]
    model_tables = model_collection["tables"]

    db = Database("sqlite://", model_class=model_class)
    db.create_all()

    with db.connect() as conn:
        result = conn.execute(sa.text("SELECT name FROM sqlite_master"))
        table_names = result.scalars().all()

    assert len(table_names) == len(model_tables)
    for table_name in table_names:
        assert table_name in db.tables