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')"
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.'
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'
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
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
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'
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
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)
def test_ini_empty_section(self, ini): ini.return_value = fixture('config-empty-section.ini') with pytest.raises(NoOptionError): get_database_uri()
def __init__(self): self.database_uri = get_database_uri()
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.