コード例 #1
0
def setup_and_teardown_postgres():
    """Setups and teardowns for postgresql."""

    # pylint: disable=invalid-name
    Postgresql = postgresql.PostgresqlFactory(cache_initialized_db=True)

    postgres = Postgresql()
    yield postgres

    postgres.stop()
    Postgresql.clear_cache()
コード例 #2
0
def pytest_configure(config):
    def handler(postgresql):
        f = open(
            os.path.dirname(os.path.realpath(__file__)) + "/../sql/init.sql")
        sql_query = f.read()
        f.close()
        conn = psycopg2.connect(**postgresql.dsn())
        cursor = conn.cursor()
        cursor.execute(sql_query)
        cursor.close()
        conn.commit()
        conn.close()

    global postgresql
    # force default timezone to pass tests on os with different local timezone setting
    pgsql_test.Postgresql.DEFAULT_SETTINGS[
        "postgres_args"] += " -c timezone=+5"

    PGSQLFactory = pgsql_test.PostgresqlFactory(cache_initialized_db=True,
                                                on_initialized=handler)

    postgresql = PGSQLFactory()
    environ["DATABASE_URL"] = postgresql.url()
    environ["USE_AVG_PERF_TDM"] = "TRUE"
コード例 #3
0
import unittest
import testing.postgresql as tpg

import utilities as util
from models.mouse import Mouse

import database.handlers.handlers
import database.seed_tables.seed_tables
from database.seed_tables.seeds import test_mouse_table_seed

mice_seed = set(test_mouse_table_seed)
Postgresql = tpg.PostgresqlFactory(cache_initialized_db=True,
                                   on_initialized=database.handlers.handlers.handler_create_mouse_table)


def tearDownModule():
    Postgresql.clear_cache()


class TestNewMouse(unittest.TestCase):
    birthdate = 20200527

    def setUp(self):
        self.postgresql = Postgresql()

    def tearDown(self):
        self.postgresql.stop()

    @unittest.skip("Not currently testing")
    def test_setUp_tearDown(self):
        self.assertTrue(1)
コード例 #4
0
def postgres_factory():
    """
    Creates an initial fake database for use in unit tests.
    """
    postgres_factory = postgresql.PostgresqlFactory(cache_initialized_db=True)
    return postgres_factory
コード例 #5
0
import unittest

import testing.postgresql as tpg

import database.handlers.handlers
import database.seed_tables.seeds as seeds
from models.experiments import Experiment
from models.mouse import Mouse
from models.participant_details import ParticipantDetails

mice_seed = set(seeds.test_mouse_table_seed)
experiment_seed = {seeds.exp_one, seeds.exp_two}
Postgresql = tpg.PostgresqlFactory(cache_initialized_db=True,
                                   on_initialized=database.handlers.handlers.
                                   handler_create_participant_details)


def tearDownModule():
    Postgresql.clear_cache()


class TestNewParticipantDetails(unittest.TestCase):
    mouse_seed = mice_seed.pop()

    def setUp(self):
        self.postgresql = Postgresql()
        database.handlers.handlers.handler_seed_participant_details(
            self.postgresql)

    def tearDown(self):
        self.postgresql.stop()