Example #1
0
    def test_stage_update_when_column_name_defined(self):
        schema = JsonObject(TABLE_NAME,
                            Property('property1', 'VARCHAR(10)', 'someColumn'),
                            Property('property2', 'TIMESTAMP', 'anotherColumn'))
        table = TargetTable(schema, self.database)
        table.stage_update()

        self.assertColumns(schema.update_table, schema)
Example #2
0
    def test_stage_update_when_column_name_defined(self):
        with patch.object(Database, 'execute') as execute:
            schema = JsonObject(
                TABLE_NAME, Property('property1', 'VARCHAR(10)', 'someColumn'),
                Property('property2', 'TIMESTAMP', 'anotherColumn'))
            table = TargetTable(schema, Database(Mock()))

            table.stage_update()

            expected_sql = 'CREATE TABLE {0}_update (someColumn VARCHAR(10), ' \
                           'anotherColumn TIMESTAMP)'.format(TABLE_NAME)

            execute.assert_called_once_with(expected_sql)
Example #3
0
    def test_stage_update_when_column_name_not_defined(self):
        with patch.object(Database, 'execute') as execute:
            schema = JsonObject(TABLE_NAME,
                                Property('property1', 'VARCHAR(10)'),
                                Property('property2', 'TIMESTAMP'))
            table = TargetTable(schema, Database(Mock()))

            table.stage_update()

            expected_sql = 'CREATE TABLE {0}_update (property1 VARCHAR(10), ' \
                           'property2 TIMESTAMP)'.format(TABLE_NAME)

            execute.assert_called_once_with(
                expected_sql)
Example #4
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 #5
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)
    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()
Example #7
0
    def test_promote_update(self):
        table = TargetTable(self.schema, self.database)
        table.stage_update()
        table.promote_update()

        self.assertColumns(self.schema.table, self.schema)