Ejemplo n.º 1
0
def test_updates_data(test_gdb):
    hash_table = str(Path(test_gdb) / 'TableHashes')
    scratch_hash_table = str(Path(arcpy.env.scratchGDB) / Path(hash_table).name)
    scratch_destination = str(Path(arcpy.env.scratchGDB) / 'Counties')
    temp_data = [scratch_hash_table, scratch_destination]
    for dataset in temp_data:
        if arcpy.Exists(dataset):
            arcpy.management.Delete(dataset)
    arcpy.management.Copy(hash_table, scratch_hash_table)

    change_detection = ChangeDetection(['ChangeDetection'], test_gdb, hash_table=scratch_hash_table)

    table = 'counties'
    crate = Crate(table, test_gdb, arcpy.env.scratchGDB, Path(scratch_destination).name)
    crate.result = (Crate.CREATED, None)
    core._create_destination_data(crate, skip_hash_field=True)
    change_detection.current_hashes[table] = '8'
    result = change_detection.update(crate)

    where = f'{table_name_field} = \'{table}\''
    with arcpy.da.SearchCursor(scratch_hash_table, [hash_field], where_clause=where) as cursor:
        assert next(cursor)[0] == '8'

    assert result[0] == Crate.CREATED

    change_detection.current_hashes[table] = '9'
    crate.result = (Crate.UNINITIALIZED, None)
    result = change_detection.update(crate)

    where = f'{table_name_field} = \'{table}\''
    with arcpy.da.SearchCursor(scratch_hash_table, [hash_field], where_clause=where) as cursor:
        assert next(cursor)[0] == '9'

    assert result[0] == Crate.UPDATED
Ejemplo n.º 2
0
    def test_crates_with_unhandled_exception_returns_false(self):
        updated = Crate('', '', '', '')
        updated.result = (Crate.UPDATED, None)

        unhandled_exception = Crate('', '', '', '')
        unhandled_exception.result = (Crate.UNHANDLED_EXCEPTION, None)

        self.patient._crates = [updated, updated, unhandled_exception]

        self.assertFalse(self.patient.requires_processing())
Ejemplo n.º 3
0
    def test_crates_with_schema_changes_returns_false(self):
        updated = Crate('', '', '', '')
        updated.result = (Crate.UPDATED, None)

        schema_change = Crate('', '', '', '')
        schema_change.result = (Crate.INVALID_DATA, None)

        self.patient._crates = [schema_change, updated, updated]

        self.assertFalse(self.patient.requires_processing())
Ejemplo n.º 4
0
    def test_crates_with_updates_and_changes_returns_true(self):
        updated = Crate('', '', '', '')
        updated.result = (Crate.UPDATED, None)

        no_changes = Crate('', '', '', '')
        no_changes.result = (Crate.NO_CHANGES, None)

        self.patient._crates = [updated, no_changes, no_changes]

        self.assertTrue(self.patient.requires_processing())
Ejemplo n.º 5
0
    def test_is_ready_to_ship_crates_with_updates_and_no_changes_returns_true(
            self):
        updated = Crate('', '', '', '')
        updated.result = (Crate.UPDATED, None)

        no_changes = Crate('', '', '', '')
        no_changes.result = (Crate.NO_CHANGES, None)

        self.patient._crates = [no_changes, updated, no_changes]

        self.assertTrue(self.patient.is_ready_to_ship())
Ejemplo n.º 6
0
    def test_is_ready_to_ship_crates_with_any_exception_returns_false(self):
        updated = Crate('', '', '', '')
        updated.result = (Crate.UPDATED, None)

        no_changes = Crate('', '', '', '')
        no_changes.result = (Crate.NO_CHANGES, None)

        unhandled_exception = Crate('', '', '', '')
        unhandled_exception.result = (Crate.UNHANDLED_EXCEPTION, None)

        self.patient._crates = [updated, no_changes, unhandled_exception]

        self.assertFalse(self.patient.is_ready_to_ship())
Ejemplo n.º 7
0
    def test_was_updated(self):
        crate = Crate('foo', 'bar', 'baz', 'goo')

        crate.result = (Crate.INVALID_DATA, None)
        self.assertFalse(crate.was_updated())

        crate.result = (Crate.WARNING, None)
        self.assertFalse(crate.was_updated())

        crate.result = (Crate.NO_CHANGES, None)
        self.assertFalse(crate.was_updated())

        crate.result = (Crate.UNHANDLED_EXCEPTION, None)
        self.assertFalse(crate.was_updated())

        crate.result = (Crate.UNINITIALIZED, None)
        self.assertFalse(crate.was_updated())

        crate.result = (Crate.CREATED, None)
        self.assertTrue(crate.was_updated())

        crate.result = (Crate.UPDATED, None)
        self.assertTrue(crate.was_updated())

        crate.result = (Crate.UPDATED_OR_CREATED_WITH_WARNINGS, None)
        self.assertTrue(crate.was_updated())
Ejemplo n.º 8
0
    def test_is_ready_to_ship_crates_with_any_schema_changed_returns_false(
            self):
        updated = Crate('', '', '', '')
        updated.result = (Crate.UPDATED, None)

        no_changes = Crate('', '', '', '')
        no_changes.result = (Crate.NO_CHANGES, None)

        schema_change = Crate('', '', '', '')
        schema_change.result = (Crate.INVALID_DATA, None)

        self.patient._crates = [updated, no_changes, schema_change]

        self.assertFalse(self.patient.is_ready_to_ship())
Ejemplo n.º 9
0
    def test_requires_processing_crates_result_created_returns_true(self):
        updated = Crate('', '', '', '')
        updated.result = (Crate.CREATED, None)

        self.patient._crates = [updated]

        self.assertTrue(self.patient.requires_processing())
Ejemplo n.º 10
0
    def test_process_on_fail(self):
        updated = Crate('', '', '', '')
        updated.result = (Crate.UPDATED, None)

        no_changes = Crate('', '', '', '')
        no_changes.result = (Crate.NO_CHANGES, None)

        unhandled_exception = Crate('', '', '', '')
        unhandled_exception.result = (Crate.UNHANDLED_EXCEPTION, None)

        self.patient._crates = [updated, no_changes, unhandled_exception]
        self.patient.success = (False, None)

        self.patient.process_on_fail = True

        self.assertTrue(self.patient.requires_processing())
Ejemplo n.º 11
0
    def test_is_ready_to_ship_crates_with_no_changes_returns_true(self):
        no_changes = Crate('', '', '', '')
        no_changes.result = (Crate.NO_CHANGES, None)

        self.patient._crates = [no_changes, no_changes, no_changes]

        self.assertTrue(self.patient.is_ready_to_ship())
Ejemplo n.º 12
0
    def test_is_ready_to_ship_crates_with_updates_returns_true(self):
        updated = Crate('', '', '', '')
        updated.result = (Crate.UPDATED, None)

        self.patient._crates = [updated, updated, updated]

        self.assertTrue(self.patient.is_ready_to_ship())
Ejemplo n.º 13
0
    def test_requires_processing_crates_with_update_and_no_changes_returns_true(
            self):
        updated = Crate('', '', '', '')
        updated.result = (Crate.UPDATED, None)

        self.patient._crates = [updated, updated, updated]

        self.assertTrue(self.patient.requires_processing())
Ejemplo n.º 14
0
    def update_problem_layers(self):
        for source_name, source_workspace, destination_workspace, destination_name in self.problem_layer_infos:
            if self.test_layer and self.test_layer.split('.')[-1] != destination_name:
                continue
            try:
                crate = Crate(source_name, source_workspace, destination_workspace, destination_name)
                source = path.join(source_workspace, source_name)
                destination = path.join(destination_workspace, destination_name)
                if not arcpy.Exists(destination):
                    self.log.info('creating %s', destination)
                    arcpy.Copy_management(source, destination)
                    crate.result = (Crate.CREATED, None)
                else:
                    self.log.info('manually updating %s', destination)
                    arcpy.TruncateTable_management(destination)
                    arcpy.Append_management(source, destination, 'TEST')
                    crate.result = (Crate.UPDATED, None)
            except Exception as ex:
                self.log.error('error manually updating %s!', destination)
                crate.result = (Crate.UNHANDLED_EXCEPTION, ex)

            self._crates.append(crate)
Ejemplo n.º 15
0
    def test_get_report(self):
        crate = Crate('foo', 'bar', 'baz', 'goo')

        crate.result = (Crate.NO_CHANGES, None)

        self.assertIsNone(crate.get_report())

        msg = 'blah'
        crate.result = (Crate.CREATED, msg)

        self.assertEqual(crate.get_report()['crate_message'], msg)

        crate.result = (Crate.WARNING, msg)

        self.assertEqual(crate.get_report()['result'], Crate.WARNING)
        self.assertEqual(crate.get_report()['message_level'], 'warning')

        crate.result = (Crate.UNHANDLED_EXCEPTION, msg)
        self.assertEqual(crate.get_report()['message_level'], 'error')

        crate.result = (Crate.INVALID_DATA, msg)
        self.assertEqual(crate.get_report()['message_level'], 'error')
    def test_updates_data(self):
        scratch_hash_table = path.join(arcpy.env.scratchGDB,
                                       path.basename(hash_table))
        scratch_destination = path.join(arcpy.env.scratchGDB, 'Counties')
        temp_data = [scratch_hash_table, scratch_destination]
        for dataset in temp_data:
            if arcpy.Exists(dataset):
                arcpy.management.Delete(dataset)
        arcpy.management.Copy(hash_table, scratch_hash_table)

        change_detection = ChangeDetection(['ChangeDetection'],
                                           test_fgdb,
                                           hash_table=scratch_hash_table)

        table = 'counties'
        crate = Crate(table, test_fgdb, arcpy.env.scratchGDB,
                      path.basename(scratch_destination))
        crate.result = (Crate.CREATED, None)
        core._create_destination_data(crate, skip_hash_field=True)
        change_detection.current_hashes[table] = '8'
        result = change_detection.update(crate)

        where = f'{table_name_field} = \'{table}\''
        with arcpy.da.SearchCursor(scratch_hash_table, [hash_field],
                                   where_clause=where) as cursor:
            self.assertEqual(next(cursor)[0], '8')

        self.assertEqual(result[0], Crate.CREATED)

        change_detection.current_hashes[table] = '9'
        crate.result = (Crate.UNINITIALIZED, None)
        result = change_detection.update(crate)

        where = f'{table_name_field} = \'{table}\''
        with arcpy.da.SearchCursor(scratch_hash_table, [hash_field],
                                   where_clause=where) as cursor:
            self.assertEqual(next(cursor)[0], '9')

        self.assertEqual(result[0], Crate.UPDATED)
Ejemplo n.º 17
0
def test_can_handle_globalid_fields_without_index(test_gdb):
    hash_table = str(Path(test_gdb) / 'TableHashes')
    scratch_hash_table = str(Path(arcpy.env.scratchGDB) / Path(hash_table).name)
    scratch_destination = str(Path(arcpy.env.scratchGDB) / 'GlobalIds')
    temp_data = [scratch_hash_table, scratch_destination]
    for dataset in temp_data:
        if arcpy.Exists(dataset):
            arcpy.management.Delete(dataset)
    arcpy.management.Copy(hash_table, scratch_hash_table)
    test_sde = str(Path(test_data_folder) / 'UPDATE_TESTS.sde')

    change_detection = ChangeDetection(['ChangeDetection'], test_sde, hash_table=scratch_hash_table)

    table = 'GlobalIdsNoIndex'
    crate = Crate(table, test_sde, arcpy.env.scratchGDB, Path(scratch_destination).name)
    crate.result = (Crate.CREATED, None)
    core._create_destination_data(crate, skip_hash_field=True)
    change_detection.current_hashes[f'update_tests.dbo.{table.casefold()}'] = 'hash'
    result = change_detection.update(crate)

    assert result[0] == Crate.CREATED
Ejemplo n.º 18
0
def test_preserves_globalids_table(test_gdb):
    hash_table = str(Path(test_gdb) / 'TableHashes')
    scratch_hash_table = str(Path(arcpy.env.scratchGDB) / Path(hash_table).name)
    scratch_destination = str(Path(arcpy.env.scratchGDB) / 'GlobalIds')
    temp_data = [scratch_hash_table, scratch_destination]
    for dataset in temp_data:
        if arcpy.Exists(dataset):
            arcpy.management.Delete(dataset)
    arcpy.management.Copy(hash_table, scratch_hash_table)
    test_sde = str(Path(test_data_folder) / 'UPDATE_TESTS.sde')

    change_detection = ChangeDetection(['ChangeDetection'], test_sde, hash_table=scratch_hash_table)

    table = 'GlobalIdsTable'
    crate = Crate(table, test_sde, str(Path(scratch_destination).parent), Path(scratch_destination).name)
    crate.result = (Crate.CREATED, None)
    core._create_destination_data(crate, skip_hash_field=True)
    change_detection.current_hashes[f'update_tests.dbo.{table.casefold()}'] = 'hash'
    result = change_detection.update(crate)

    assert result[0] == Crate.CREATED

    with arcpy.da.SearchCursor(scratch_destination, ['GlobalID', 'NAME'], 'NAME = \'JUAB\'') as cursor:
        assert next(cursor)[0] == '{D5868F73-B65A-4B11-B346-D00E7A5043F7}'