Beispiel #1
0
    def test_connect_db_psycopg2_missing(self, import_mock):
        ''' Raise exception if psycopg2 driver is not available. '''

        config = self.config_fixture(schema='myapp')

        with self.assertRaises(click.ClickException):
            agnostic._connect_db(config)
Beispiel #2
0
    def test_connect_db_unsupported(self):
        ''' Raise an exception if the database type is not supported. '''

        config = self.config_fixture(type='bogusdb')

        with self.assertRaises(ValueError):
            agnostic._connect_db(config)
Beispiel #3
0
    def test_connect_db_psycopg2(self, connect_mock):
        ''' Connect to a postgres database with the psycopg2 driver. '''

        config = self.config_fixture()

        agnostic._connect_db(config)

        self.assertTrue(connect_mock.called)
        self.assertEqual(config.host, connect_mock.call_args[1]['host'])
        self.assertEqual(config.port, connect_mock.call_args[1]['port'])
        self.assertEqual(config.user, connect_mock.call_args[1]['user'])
        self.assertEqual(config.password, connect_mock.call_args[1]['password'])
        self.assertEqual(config.schema, connect_mock.call_args[1]['database'])