def testProfileExists(self): with patch('rubbish_geo_common.db_ops.APPDIR', new=get_app_dir()): set_db(profile='dev', connstr='postgresql://*****:*****@localhost:5432/baz', conntype='gcp', conname='bar') db_sessionmaker(profile='dev')
def testProfileDoesntExist(self): with patch('rubbish_geo_common.db_ops.APPDIR', new=get_app_dir()): with pytest.raises(ValueError): db_sessionmaker(profile='dev') # TODO: set_db tests, fix db_sessionmaker, etcetera. # Very far-reaching and annoying refactor. :'(
def testEmptyConfigFileKeyRaises(self): with patch('rubbish_geo_common.db_ops.APPDIR', new=get_app_dir()): with open(pathlib.Path(TEST_APP_DIR_TMPDIR) / 'config', 'w') as f: f.write( "[nonlocal]\nconnstr = foo\nconntype = local\nconname = unset" ) with pytest.raises(ValueError): return get_db('local')
def testPresentConfigFileKeyWorks(self): with patch('rubbish_geo_common.db_ops.APPDIR', new=get_app_dir()): with open(pathlib.Path(TEST_APP_DIR_TMPDIR) / 'config', 'w') as f: f.write( "[local]\nconnstr = foo\nconntype = local\nconname = unset" ) expected = ('foo', 'local', 'unset') result = get_db('local') assert result == expected
def testWriteGCPConnection(self): with patch('rubbish_geo_common.db_ops.APPDIR', new=get_app_dir()): set_db(profile='dev', connstr='foo', conntype='gcp', conname='bar') cfg = configparser.ConfigParser() cfg.read(pathlib.Path(TEST_APP_DIR_TMPDIR) / 'config') assert 'dev' in cfg dev = cfg['dev'] assert dev['connstr'] == 'foo' assert dev['conntype'] == 'gcp' assert dev['conname'] == 'bar'
def testWriteLocalConnection(self): with patch('rubbish_geo_common.db_ops.APPDIR', new=get_app_dir()): set_db(profile='local', connstr='foo', conntype='local') cfg = configparser.ConfigParser() cfg.read(pathlib.Path(TEST_APP_DIR_TMPDIR) / 'config') assert 'local' in cfg local = cfg['local'] assert local['connstr'] == 'foo' assert local['conntype'] == 'local' assert local['conname'] == 'unset'
def testWriteBadGCPConnection(self): with patch('rubbish_geo_common.db_ops.APPDIR', new=get_app_dir()): with pytest.raises(ValueError): set_db(profile='dev', connstr='foo', conntype='gcp') # no conntype!
def testEmptyConfigFileRaises(self): with patch('rubbish_geo_common.db_ops.APPDIR', new=get_app_dir()): (pathlib.Path(TEST_APP_DIR_TMPDIR) / 'config').touch() with pytest.raises(ValueError): return get_db('local')
def testNonexistantConfigFileRaises(self): with patch('rubbish_geo_common.db_ops.APPDIR', new=get_app_dir()): with pytest.raises(ValueError): return get_db('local')