예제 #1
0
 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')
예제 #2
0
    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. :'(
예제 #3
0
 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')
예제 #4
0
 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
예제 #5
0
    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'
예제 #6
0
    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'
예제 #7
0
 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!
예제 #8
0
 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')
예제 #9
0
 def testNonexistantConfigFileRaises(self):
     with patch('rubbish_geo_common.db_ops.APPDIR', new=get_app_dir()):
         with pytest.raises(ValueError):
             return get_db('local')