def test_get_engine_empty_schema(self, mock_keyring_get_password: MagicMock, mock_user_config_dir: MagicMock) -> None: redshift_connector = RedshiftConnector() mock_user_config_dir.assert_called_once_with('pypandasql') mock_keyring_get_password.assert_called_once_with( 'pypandasql-redshift', 'test') with self.assertRaises(AssertionError): redshift_connector.get_engine(schema='')
def test_get_uri(self, mock_keyring_get_password: MagicMock, mock_user_config_dir: MagicMock) -> None: redshift_connector = RedshiftConnector() mock_user_config_dir.assert_called_once_with('pypandasql') mock_keyring_get_password.assert_called_once_with( 'pypandasql-redshift', 'test') self.assertEqual( redshift_connector.get_uri(schema='test-schema'), 'redshift+psycopg2://test:random-password@test-host:1234/test-schema' )
def test_get_connection(self, mock_connect: MagicMock, mock_keyring_get_password: MagicMock, mock_user_config_dir: MagicMock) -> None: redshift_connector = RedshiftConnector() redshift_connector.get_connection(schema='test-schema') mock_user_config_dir.assert_called_once_with('pypandasql') mock_keyring_get_password.assert_called_once_with( 'pypandasql-redshift', 'test') mock_connect.assert_called_once_with(dbname='test-schema', host='test-host', port=1234, user='******', password='******')
def test_redshift_connector_creation( self, mock_keyring_get_password: MagicMock, mock_user_config_dir: MagicMock) -> None: redshift_connector = RedshiftConnector() mock_user_config_dir.assert_called_once_with('pypandasql') mock_keyring_get_password.assert_called_once_with( 'pypandasql-redshift', 'test') self.assertEqual(redshift_connector.engine_name, 'redshift+psycopg2') connection_att = redshift_connector.connection_attr self.assertEqual(connection_att['host'], 'test-host') self.assertEqual(connection_att['port'], '1234') self.assertEqual(connection_att['user_name'], 'test') credentials = connection_att['credentials'] self.assertEqual(credentials.service_name, 'pypandasql-redshift') self.assertEqual(credentials.user, 'test') self.assertEqual(credentials.password, 'random-password')
def __init__(self) -> None: super(RedshiftQueryEngine, self).__init__(db_connector=RedshiftConnector())