Exemplo n.º 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
    def test_validate_with_drop_on_run(self):
        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.promote_update = Mock()
            step = BulkCopyFromS3JsonStep(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.sql = Mock()
            step.validate()

            self.assert_migration_with_drop(target_table)
            target_table.database.rollback.assert_called_once_with()
Exemplo n.º 3
0
    def test_drop(self):
        table = TargetTable(self.schema, self.database)
        table.create()
        table.drop()

        self.assertEqual(False, table.exists())