Пример #1
0
    def test_create_destination_data_raises(self):
        #: non-file geodatabase
        crate = Crate('DNROilGasWells', check_for_changes_gdb, test_folder,
                      'test.shp')

        with self.assertRaises(Exception):
            core._create_destination_data(crate)
Пример #2
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
Пример #3
0
    def test_create_destination_data_feature_class(self):
        arcpy.CreateFileGDB_management(path.join(current_folder, 'data'),
                                       'test.gdb')

        fc_crate = Crate('DNROilGasWells', check_for_changes_gdb, test_gdb)
        core._create_destination_data(fc_crate)
        self.assertTrue(arcpy.Exists(fc_crate.destination))
Пример #4
0
    def test_create_destination_data_table(self):
        arcpy.CreateFileGDB_management(path.join(current_folder, 'data'),
                                       'test.gdb')

        tbl_crate = Crate('Providers', check_for_changes_gdb, test_gdb)
        core._create_destination_data(tbl_crate)
        self.assertTrue(arcpy.Exists(tbl_crate.destination))
Пример #5
0
def test_create_destination_data_raises(test_gdb, tmpdir):

    #: non-file geodatabase
    crate = Crate('DNROilGasWells', test_gdb, str(tmpdir), 'test.shp')

    with pytest.raises(Exception):
        core._create_destination_data(crate)
Пример #6
0
def test_create_destination_data_workspace(create_mock, test_gdb):

    #: file geodatabase
    crate = Crate('DNROilGasWells', test_gdb, TEMP_GDB)
    core._create_destination_data(crate)

    create_mock.assert_called_once()
Пример #7
0
def test_create_destination_data_table(test_gdb):

    arcpy.CreateFileGDB_management(path.join(CURRENT_FOLDER, 'data'),
                                   'test.gdb')

    tbl_crate = Crate('Providers', test_gdb, TEMP_GDB)
    core._create_destination_data(tbl_crate)
    assert arcpy.Exists(tbl_crate.destination) == True
Пример #8
0
def test_create_destination_data_feature_class(test_gdb):

    arcpy.CreateFileGDB_management(path.join(CURRENT_FOLDER, 'data'),
                                   'test.gdb')

    fc_crate = Crate('DNROilGasWells', test_gdb, TEMP_GDB)
    core._create_destination_data(fc_crate)
    assert arcpy.Exists(fc_crate.destination) == True
Пример #9
0
def test_preserve_metadata(test_gdb):
    crate = Crate('PreserveMetadata', test_gdb, test_gdb,
                  'PreserveMetadata_Dest')
    source_metadata = arcpy.metadata.Metadata(crate.source)
    core._create_destination_data(crate)
    destination_metadata = arcpy.metadata.Metadata(crate.destination)

    assert source_metadata.description == destination_metadata.description
    assert source_metadata.title == destination_metadata.title
    assert source_metadata.summary == destination_metadata.summary
Пример #10
0
    def test_create_destination_data_reproject(self):
        arcpy.CreateFileGDB_management(path.join(current_folder, 'data'), 'test.gdb')

        spatial_reference = arcpy.SpatialReference(3857)
        fc_crate = Crate(
            'DNROilGasWells',
            check_for_changes_gdb,
            test_gdb,
            destination_coordinate_system=spatial_reference,
            geographic_transformation='NAD_1983_To_WGS_1984_5')
        core._create_destination_data(fc_crate)
        self.assertTrue(arcpy.Exists(fc_crate.destination))
        self.assertEqual(arcpy.Describe(fc_crate.destination).spatialReference.name, spatial_reference.name)
Пример #11
0
    def test_create_destination_data_reproject(self):
        arcpy.CreateFileGDB_management(path.join(current_folder, 'data'), 'test.gdb')

        spatial_reference = arcpy.SpatialReference(3857)
        fc_crate = Crate(
            'DNROilGasWells',
            check_for_changes_gdb,
            test_gdb,
            destination_coordinate_system=spatial_reference,
            geographic_transformation='NAD_1983_To_WGS_1984_5')
        core._create_destination_data(fc_crate)
        self.assertTrue(arcpy.Exists(fc_crate.destination))
        self.assertEqual(arcpy.Describe(fc_crate.destination).spatialReference.name, spatial_reference.name)
Пример #12
0
def test_create_destination_data_reproject(test_gdb):

    arcpy.CreateFileGDB_management(path.join(CURRENT_FOLDER, 'data'),
                                   'test.gdb')

    spatial_reference = arcpy.SpatialReference(3857)
    fc_crate = Crate('DNROilGasWells',
                     test_gdb,
                     TEMP_GDB,
                     destination_coordinate_system=spatial_reference,
                     geographic_transformation='NAD_1983_To_WGS_1984_5')
    core._create_destination_data(fc_crate)
    assert arcpy.Exists(fc_crate.destination) == True
    assert arcpy.Describe(
        fc_crate.destination).spatialReference.name == spatial_reference.name
Пример #13
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
    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)
Пример #15
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}'
Пример #16
0
    def test_create_destination_data_raises(self):
        #: non-file geodatabase
        crate = Crate('DNROilGasWells', check_for_changes_gdb, test_folder, 'test.shp')

        with self.assertRaises(Exception):
            core._create_destination_data(crate)
Пример #17
0
    def test_create_destination_data_workspace(self, create_mock):
        #: file geodatabase
        crate = Crate('DNROilGasWells', check_for_changes_gdb, test_gdb)
        core._create_destination_data(crate)

        create_mock.assert_called_once()
Пример #18
0
    def test_create_destination_data_table(self):
        arcpy.CreateFileGDB_management(path.join(current_folder, 'data'), 'test.gdb')

        tbl_crate = Crate('Providers', check_for_changes_gdb, test_gdb)
        core._create_destination_data(tbl_crate)
        self.assertTrue(arcpy.Exists(tbl_crate.destination))
Пример #19
0
    def test_create_destination_data_workspace(self, create_mock):
        #: file geodatabase
        crate = Crate('DNROilGasWells', check_for_changes_gdb, test_gdb)
        core._create_destination_data(crate)

        create_mock.assert_called_once()
Пример #20
0
    def test_create_destination_data_feature_class(self):
        arcpy.CreateFileGDB_management(path.join(current_folder, 'data'), 'test.gdb')

        fc_crate = Crate('DNROilGasWells', check_for_changes_gdb, test_gdb)
        core._create_destination_data(fc_crate)
        self.assertTrue(arcpy.Exists(fc_crate.destination))