Example #1
0
    def assert_copy_schema_to_redshift_with_drop(self, sql, execute):
        with patch.object(TargetTable, 'exists') as exists:
            exists.return_value = True
            target_table = TargetTable(self.schema, Mock())
            target_table.stage_update = Mock()
            target_table.drop = Mock()
            target_table.create = Mock()
            target_table.insert_update = Mock()
            step = ManifestCopyFromS3JsonStep(metadata='',
                                              source=SOURCE,
                                              schema=self.schema,
                                              aws_access_key_id=AWS_ACCESS_KEY_ID,
                                              aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
                                              bucket=self.bucket,
                                              table=target_table)
            step.manifest.save = Mock(return_value=self.updated_journal)
            step.manifest.journal_exists = Mock(return_value=False)
            step.sql = Mock()
            execute(step)

            self.assert_migration_with_drop(step)

            step.sql.execute.assert_called_once_with((sql,
                                                      self.schema.table,
                                                      step.manifest.manifest_url,
                                                      AWS_ACCESS_KEY_ID,
                                                      AWS_SECRET_ACCESS_KEY,
                                                      step.schema_url,
                                                      step.max_error_count))

            return target_table.database
Example #2
0
    def test_insert_update(self):
        table = TargetTable(self.schema, self.database)
        table.create()
        table.stage_update()
        self.database.execute("INSERT INTO %s VALUES('%s')",
                              (AsIs(TABLE_NAME), AsIs(1),))
        self.database.execute("INSERT INTO %s VALUES('%s')",
                              (AsIs(self.schema.update_table), AsIs(2),))
        self.database.execute("INSERT INTO %s VALUES('%s')",
                              (AsIs(self.schema.update_table), AsIs(3),))

        table.insert_update()

        self.database.execute(
            "SELECT * FROM %s",
            (AsIs(TABLE_NAME),))
        values = list(self.database.cursor.fetchall())

        self.assertEqual([('1',), ('2',), ('3',)], values)