2017-09-20 23:49:12 +03:00
|
|
|
import os
|
2015-01-08 00:30:20 +03:00
|
|
|
import pytest
|
2019-05-25 23:08:56 +03:00
|
|
|
from utils import (
|
|
|
|
POSTGRES_HOST,
|
|
|
|
POSTGRES_PORT,
|
|
|
|
POSTGRES_USER,
|
|
|
|
POSTGRES_PASSWORD,
|
|
|
|
create_db,
|
|
|
|
db_connection,
|
|
|
|
drop_tables,
|
|
|
|
)
|
2015-01-31 05:59:09 +03:00
|
|
|
import pgcli.pgexecute
|
2015-01-08 00:30:20 +03:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.yield_fixture(scope="function")
|
|
|
|
def connection():
|
2019-05-25 23:08:56 +03:00
|
|
|
create_db("_test_db")
|
|
|
|
connection = db_connection("_test_db")
|
2015-01-08 00:30:20 +03:00
|
|
|
yield connection
|
|
|
|
|
|
|
|
drop_tables(connection)
|
|
|
|
connection.close()
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def cursor(connection):
|
|
|
|
with connection.cursor() as cur:
|
|
|
|
return cur
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def executor(connection):
|
2019-05-25 23:08:56 +03:00
|
|
|
return pgcli.pgexecute.PGExecute(
|
|
|
|
database="_test_db",
|
|
|
|
user=POSTGRES_USER,
|
|
|
|
host=POSTGRES_HOST,
|
|
|
|
password=POSTGRES_PASSWORD,
|
|
|
|
port=POSTGRES_PORT,
|
|
|
|
dsn=None,
|
|
|
|
)
|
2015-10-22 00:10:30 +03:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def exception_formatter():
|
2015-10-24 20:43:28 +03:00
|
|
|
return lambda e: str(e)
|
2017-09-20 23:49:12 +03:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
|
|
|
def temp_config(tmpdir_factory):
|
2017-10-06 22:12:22 +03:00
|
|
|
# this function runs on start of test session.
|
|
|
|
# use temporary directory for config home so user config will not be used
|
2019-05-25 23:08:56 +03:00
|
|
|
os.environ["XDG_CONFIG_HOME"] = str(tmpdir_factory.mktemp("data"))
|