예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
    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)
예제 #4
0
    def test_dbname_verification_is_case_insensitive(self):
        # Override adapter settings from setUp()
        profile_cfg = {
            'outputs': {
                'test': {
                    'type': 'redshift',
                    'dbname': 'Redshift',
                    'user': '******',
                    'host': 'thishostshouldnotexist',
                    'pass': '******',
                    'port': 5439,
                    'schema': 'public'
                }
            },
            'target': 'test'
        }

        project_cfg = {
            'name': 'X',
            'version': '0.1',
            'profile': 'test',
            'project-root': '/tmp/dbt/does-not-exist',
            'quoting': {
                'identifier': False,
                'schema': True,
            },
        }
        self.config = config_from_parts_or_dicts(project_cfg, profile_cfg)
        self.adapter.cleanup_connections()
        self._adapter = RedshiftAdapter(self.config)
        self.adapter.verify_database('redshift')
예제 #5
0
    def test_set_zero_keepalive(self, psycopg2):
        self.profile['keepalives_idle'] = 0
        connection = RedshiftAdapter.acquire_connection(self.profile, 'dummy')

        psycopg2.connect.assert_called_once_with(dbname='redshift',
                                                 user='******',
                                                 host='database',
                                                 password='******',
                                                 port=5439,
                                                 connect_timeout=10)
예제 #6
0
 def test_convert_datetime_type(self):
     rows = [
         ['', '20190101T01:01:01Z', '2019-01-01 01:01:01'],
         ['', '20190102T01:01:01Z', '2019-01-01 01:01:01'],
         ['', '20190103T01:01:01Z', '2019-01-01 01:01:01'],
     ]
     agate_table = self._make_table_of(rows, [agate.DateTime, agate_helper.ISODateTime, agate.DateTime])
     expected = ['timestamp without time zone', 'timestamp without time zone', 'timestamp without time zone']
     for col_idx, expect in enumerate(expected):
         assert RedshiftAdapter.convert_datetime_type(agate_table, col_idx) == expect
예제 #7
0
 def test_convert_date_type(self):
     rows = [
         ['', '2019-01-01', '2019-01-04'],
         ['', '2019-01-02', '2019-01-04'],
         ['', '2019-01-03', '2019-01-04'],
     ]
     agate_table = self._make_table_of(rows, agate.Date)
     expected = ['date', 'date', 'date']
     for col_idx, expect in enumerate(expected):
         assert RedshiftAdapter.convert_date_type(agate_table, col_idx) == expect
예제 #8
0
 def test_convert_number_type(self):
     rows = [
         ['', '23.98', '-1'],
         ['', '12.78', '-2'],
         ['', '79.41', '-3'],
     ]
     agate_table = self._make_table_of(rows, agate.Number)
     expected = ['integer', 'float8', 'integer']
     for col_idx, expect in enumerate(expected):
         assert RedshiftAdapter.convert_number_type(agate_table, col_idx) == expect
예제 #9
0
 def test_convert_boolean_type(self):
     rows = [
         ['', 'false', 'true'],
         ['', 'false', 'false'],
         ['', 'false', 'true'],
     ]
     agate_table = self._make_table_of(rows, agate.Boolean)
     expected = ['boolean', 'boolean', 'boolean']
     for col_idx, expect in enumerate(expected):
         assert RedshiftAdapter.convert_boolean_type(agate_table, col_idx) == expect
예제 #10
0
 def test_convert_text_type(self):
     rows = [
         ['', 'a1', 'stringval1'],
         ['', 'a2', 'stringvalasdfasdfasdfa'],
         ['', 'a3', 'stringval3'],
     ]
     agate_table = self._make_table_of(rows, agate.Text)
     expected = ['varchar(64)', 'varchar(2)', 'varchar(22)']
     for col_idx, expect in enumerate(expected):
         assert RedshiftAdapter.convert_text_type(agate_table, col_idx) == expect
예제 #11
0
    def test_default_keepalive(self, psycopg2):
        connection = RedshiftAdapter.acquire_connection(self.profile, 'dummy')

        psycopg2.connect.assert_called_once_with(
            dbname='redshift',
            user='******',
            host='database',
            password='******',
            port=5439,
            connect_timeout=10,
            keepalives_idle=RedshiftAdapter.DEFAULT_TCP_KEEPALIVE)
예제 #12
0
 def test_convert_time_type(self):
     # dbt's default type testers actually don't have a TimeDelta at all.
     agate.TimeDelta
     rows = [
         ['', '120s', '10s'],
         ['', '3m', '11s'],
         ['', '1h', '12s'],
     ]
     agate_table = self._make_table_of(rows, agate.TimeDelta)
     expected = ['varchar(24)', 'varchar(24)', 'varchar(24)']
     for col_idx, expect in enumerate(expected):
         assert RedshiftAdapter.convert_time_type(agate_table, col_idx) == expect
예제 #13
0
    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)
예제 #14
0
    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)
예제 #15
0
 def adapter(self):
     if self._adapter is None:
         self._adapter = RedshiftAdapter(self.config)
     return self._adapter
예제 #16
0
 def adapter(self):
     if self._adapter is None:
         self._adapter = RedshiftAdapter(self.config)
         inject_adapter(self._adapter, RedshiftPlugin)
     return self._adapter
예제 #17
0
    def test_explicit_database_conn(self):
        self.profile['method'] = 'database'

        creds = RedshiftAdapter.get_credentials(self.profile)
        self.assertEquals(creds, self.profile)
예제 #18
0
    def test_explicit_database_conn(self):
        self.config.method = 'database'

        creds = RedshiftAdapter.get_credentials(self.config.credentials)
        self.assertEquals(creds, self.config.credentials)
예제 #19
0
 def test_implicit_database_conn(self):
     creds = RedshiftAdapter.get_credentials(self.config.credentials)
     self.assertEquals(creds, self.config.credentials)
예제 #20
0
 def adapter(self):
     return RedshiftAdapter(self.config)