Exemplo n.º 1
0
    def test_ini_bad_port(self, ini):
        ini.return_value = fixture('config-bad-port.ini')

        with pytest.raises(Exception) as excinfo:
            get_database_uri()

        assert str(excinfo.value) == 'PORT is invalid in ~/.config/ocdskingfisher-views/config.ini. ' \
                                     "(invalid literal for int() with base 10: 'invalid')"
Exemplo n.º 2
0
    def test_ini_empty_dbname(self, ini):
        ini.return_value = fixture('config-empty-dbname.ini')

        with pytest.raises(Exception) as excinfo:
            get_database_uri()

        assert str(
            excinfo.value
        ) == 'You must set DBNAME in ~/.config/ocdskingfisher-views/config.ini.'
Exemplo n.º 3
0
    def test_ini_nonexistent(self, ini):
        ini.return_value = 'nonexistent.ini'

        with pytest.raises(Exception) as excinfo:
            get_database_uri()

        assert str(excinfo.value) == 'You must either set the KINGFISHER_VIEWS_DB_URI environment variable or ' \
                                     'create the ~/.config/ocdskingfisher-views/config.ini file.\nSee https://' \
                                     'kingfisher-views.readthedocs.io/en/latest/get-started.html'
Exemplo n.º 4
0
    def test_pgpass_no_match(self, ini):
        ini.return_value = fixture('config.ini')

        database_uri = get_database_uri()

        assert database_uri == 'postgresql://*****:*****@localhost:5432/ocdskingfisher'
        assert len(self.caplog.records) == 0
Exemplo n.º 5
0
def test_env(ini, caplog):
    ini.return_value = fixture('config.ini')

    database_uri = get_database_uri()

    assert database_uri == 'postgresql:///test'
    assert len(caplog.records) == 0
Exemplo n.º 6
0
    def test_ini_empty_options(self, user, ini):
        user.return_value = 'morgan'
        ini.return_value = fixture('config-empty-options.ini')

        database_uri = get_database_uri()

        assert database_uri == 'postgresql://morgan:@localhost:5432/ocdskingfisher'
Exemplo n.º 7
0
    def test_pgpass_bad_port(self, ini):
        ini.return_value = fixture('config.ini')

        database_uri = get_database_uri()

        assert database_uri == 'postgresql://*****:*****@localhost:5432/ocdskingfisher'

        message = 'Skipping PostgreSQL Password File: Error validating port value "invalid"'

        assert len(self.caplog.records) == 1
        assert self.caplog.records[0].levelname == 'WARNING'
        assert self.caplog.records[0].message == message
Exemplo n.º 8
0
    def test_pgpass_bad_permissions(self, ini):
        ini.return_value = fixture('config.ini')

        database_uri = get_database_uri()

        assert database_uri == 'postgresql://*****:*****@localhost:5432/ocdskingfisher'

        message = r'^Skipping PostgreSQL Password File: Invalid Permissions for ' \
                  r'tests/fixtures/pgpass-bad-permissions\.txt: 0o6\d4\.\nTry: chmod 600 ' \
                  r'tests/fixtures/pgpass-bad-permissions\.txt$'

        assert len(self.caplog.records) == 1
        assert self.caplog.records[0].levelname == 'WARNING'
        assert re.search(message, self.caplog.records[0].message)
Exemplo n.º 9
0
    def test_ini_empty_section(self, ini):
        ini.return_value = fixture('config-empty-section.ini')

        with pytest.raises(NoOptionError):
            get_database_uri()
Exemplo n.º 10
0
 def __init__(self):
     self.database_uri = get_database_uri()
Exemplo n.º 11
0
import os
import sys

from alembic import context
from sqlalchemy import engine_from_config, pool

sys.path.append(
    os.path.dirname(
        os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))
from ocdskingfisherviews.config import get_database_uri  # noqa isort:skip

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config

config.set_main_option("sqlalchemy.url", get_database_uri())

# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
target_metadata = None

# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.


def run_migrations_offline():
    """Run migrations in 'offline' mode.