def test_invalid_iam_no_cluster_id(self): self.config.credentials = self.config.credentials.incorporate( method='iam' ) with self.assertRaises(dbt.exceptions.FailedToConnectException) as context: with mock.patch.object(RedshiftAdapter, 'fetch_cluster_credentials', new=fetch_cluster_credentials): RedshiftAdapter.get_credentials(self.config.credentials) self.assertTrue("'cluster_id' must be provided" in context.exception.msg)
def test_invalid_auth_method(self): # we have to set method this way, otherwise it won't validate self.config.credentials._contents['method'] = 'badmethod' with self.assertRaises(dbt.exceptions.FailedToConnectException) as context: with mock.patch.object(RedshiftAdapter, 'fetch_cluster_credentials', new=fetch_cluster_credentials): RedshiftAdapter.get_credentials(self.config.credentials) self.assertTrue('badmethod' in context.exception.msg)
def test_invalid_auth_method(self): self.profile['method'] = 'badmethod' with self.assertRaises( dbt.exceptions.FailedToConnectException) as context: with mock.patch.object(RedshiftAdapter, 'fetch_cluster_credentials', new=fetch_cluster_credentials): RedshiftAdapter.get_credentials(self.profile) self.assertTrue('badmethod' in context.exception.msg)
def test_explicit_iam_conn(self): self.config.credentials = self.config.credentials.incorporate( method='iam', cluster_id='my_redshift', iam_duration_seconds=1200 ) with mock.patch.object(RedshiftAdapter, 'fetch_cluster_credentials', new=fetch_cluster_credentials): creds = RedshiftAdapter.get_credentials(self.config.credentials) expected_creds = self.config.credentials.incorporate(password='******') self.assertEquals(creds, expected_creds)
def test_explicit_iam_conn(self): self.profile.update({ 'method': 'iam', 'cluster_id': 'my_redshift', 'iam_duration_s': 1200, }) with mock.patch.object(RedshiftAdapter, 'fetch_cluster_credentials', new=fetch_cluster_credentials): creds = RedshiftAdapter.get_credentials(self.profile) expected_creds = dbt.utils.merge(self.profile, {'pass': '******'}) self.assertEquals(creds, expected_creds)
def test_explicit_database_conn(self): self.config.method = 'database' creds = RedshiftAdapter.get_credentials(self.config.credentials) self.assertEquals(creds, self.config.credentials)
def test_implicit_database_conn(self): creds = RedshiftAdapter.get_credentials(self.config.credentials) self.assertEquals(creds, self.config.credentials)
def test_explicit_database_conn(self): self.profile['method'] = 'database' creds = RedshiftAdapter.get_credentials(self.profile) self.assertEquals(creds, self.profile)