Beispiel #1
0
    def test_query_with_non_unique_keys(self, mock_connect):
        inst = Postgres(self.source, OPTIONS)
        inst.conn, inst.cursor = connect(self.source)

        cursor_return_value = mock_connect.return_value.cursor.return_value
        cursor_return_value.fetchall.return_value = [
            {
                'attname': 'idx3',
                'indisunique': False,
                'indisprimary': False,
                'indnatts': 1,
                'indexrelid': 'idx3123'
            },
        ]

        schema = 'public'
        table = 'test'
        inckey = ''
        incval = ''
        max_value = 100
        keys = inst.get_table_metadata(SQL_GET_KEYS, schema, table)
        keys = key_strategy(keys)
        state = None

        result = get_query(schema, table, inckey, incval, keys, max_value,
                           state)
        expected = 'SELECT * FROM "public"."test" ORDER BY "idx3"'

        self.assertEqual(result, expected)
Beispiel #2
0
    def test_get_table_metadata(self, mock_connect, mock_execute):
        testcases = [
            {
                'schema': 'public',
                'table': 'Errors'
            },
            {
                'schema': 'public',
                'table': 'Notifications'
            },
        ]

        stream = Postgres(self.source, OPTIONS)
        stream.conn, stream.cursor = connect(self.source)

        for i, tcase in enumerate(testcases):
            schema, table = tcase['schema'], tcase['table']
            stream.get_table_metadata(SQL_GET_KEYS, schema, table)

            # make sure tables and schema are properly escaped when
            # casting to regclass (as it implicitly converts to lowercase)
            query = mock_execute.call_args_list[i][0][0]
            self.assertIn('\'"%s"."%s"\'::regclass' % (schema, table), query)