Beispiel #1
0
    __tablename__ = "quarter"

    id = Column(Integer, primary_key=True)
    year = Column(SmallInteger, nullable=False)
    quarter = Column(SmallInteger, nullable=False)


rows = Rows(
    Quarter(id=1, year=2012, quarter=1),
    Quarter(id=2, year=2012, quarter=2),
    Quarter(id=3, year=2012, quarter=3),
    Quarter(id=4, year=2012, quarter=4),
)

postgres = create_postgres_fixture(rows)
mysql = create_mysql_fixture(rows)


def test_rows_postgres(postgres):
    execute = postgres.execute("""
        SELECT *
        FROM quarter
        ORDER BY id
        """)
    assert [(1, 2012, 1), (2, 2012, 2), (3, 2012, 3),
            (4, 2012, 4)] == list(execute)


def test_rows_mysql(mysql):
    execute = mysql.execute("""
        SELECT *
Beispiel #2
0
from pytest_mock_resources import (
    create_mysql_fixture,
    create_postgres_fixture,
    create_redshift_fixture,
    create_sqlite_fixture,
    Statements,
)

statements = Statements("CREATE VIEW cool_view as select 3",
                        "CREATE VIEW cool_view_2 as select 1")
postgres = create_postgres_fixture(statements)
sqlite = create_sqlite_fixture(statements)
mysql = create_mysql_fixture(statements)


def test_statements_postgres(postgres):
    execute = postgres.execute("""
        SELECT table_name
        FROM INFORMATION_SCHEMA.views
        WHERE table_name in ('cool_view', 'cool_view_2')
        ORDER BY table_name
        """)

    result = [row[0] for row in execute]
    assert ["cool_view", "cool_view_2"] == result


def test_statements_mysql(mysql):
    execute = mysql.execute("""
        SELECT table_name
        FROM INFORMATION_SCHEMA.views
Beispiel #3
0
import pytest
from sqlalchemy import create_engine, text

from pytest_mock_resources import (
    compat,
    create_mysql_fixture,
    create_postgres_fixture,
    create_redshift_fixture,
    create_sqlite_fixture,
)
from pytest_mock_resources.fixture.database.relational.generic import EngineManager

sqlite = create_sqlite_fixture()
postgres = create_postgres_fixture()
redshift = create_redshift_fixture()
mysql = create_mysql_fixture()


def test_basic_sqlite_fixture(sqlite):
    sqlite.execute("select 1")


def test_basic_postgres_fixture(postgres):
    postgres.execute("select 1")


def test_basic_redshift_fixture(redshift):
    redshift.execute("select 1")


def test_basic_postgres_and_redshift_fixture(postgres, redshift):