def test_hash_custom_source_key_text(self): skip_if_no_local_sde() tbl = 'NO_OBJECTID_TEST' #: has changes crate = Crate('UPDATE_TESTS.dbo.{}'.format(tbl), update_tests_sde, check_for_changes_gdb, tbl, source_primary_key='TEST') self.assertEqual(len(core._hash(crate).adds), 1) #: no changes crate = Crate('UPDATE_TESTS.dbo.{}'.format(tbl), update_tests_sde, check_for_changes_gdb, '{}_NO_CHANGES'.format(tbl), source_primary_key='TEST') self.assertEqual(len(core._hash(crate).adds), 0)
def test_hash_no_OBJECTID_in_source(self): skip_if_no_local_sde() arcpy.Copy_management(check_for_changes_gdb, test_gdb) tbl = 'NO_OBJECTID_TEST' #: has changes crate = Crate('UPDATE_TESTS.dbo.{}'.format(tbl), update_tests_sde, test_gdb, tbl, source_primary_key='TEST') self.assertEqual(len(core._hash(crate, core.hash_gdb_path, False).adds), 1) #: no changes crate = Crate('UPDATE_TESTS.dbo.{}'.format(tbl), update_tests_sde, test_gdb, '{}_NO_CHANGES'.format(tbl), source_primary_key='TEST') self.assertEqual(len(core._hash(crate, core.hash_gdb_path, False).adds), 1)
def test_hash_custom_source_key_text(test_gdb): skip_if_no_local_sde() tbl = 'NO_OBJECTID_TEST' #: has changes crate = Crate('UPDATE_TESTS.dbo.{}'.format(tbl), UPDATE_TESTS_SDE, test_gdb, tbl) assert len(core._hash(crate).adds) == 1 #: no changes crate = Crate('UPDATE_TESTS.dbo.{}'.format(tbl), UPDATE_TESTS_SDE, test_gdb, '{}_NO_CHANGES'.format(tbl)) assert len(core._hash(crate).adds) == 0
def test_hash_shapefile(): test_data_folder = path.join(SUITE_DATA_FOLDER, 'test_hash_shapefile') fgdb = path.join(test_data_folder, 'data.gdb') crate = Crate('shapefile.shp', test_data_folder, fgdb, 'shapefile') changes = core._hash(crate) assert len(changes.adds) == 1
def test_hash_shapefile(self): data_folder = path.join(current_folder, 'data') crate = Crate('shapefile.shp', data_folder, check_for_changes_gdb, 'shapefile') changes = core._hash(crate) self.assertEqual(len(changes.adds), 1)
def test_hash_shapefile(self): arcpy.Copy_management(check_for_changes_gdb, test_gdb) data_folder = path.join(current_folder, 'data') crate = Crate('shapefile.shp', data_folder, test_gdb, 'shapefile') changes = core._hash(crate, core.hash_gdb_path, False) self.assertEqual(len(changes.adds), 1)
def run(name): return core._hash( Crate(name, UPDATE_TESTS_SDE, test_gdb, name, destination_coordinate_system=arcpy.SpatialReference(3857), geographic_transformation='NAD_1983_To_WGS_1984_5'))
def run(name): return core._hash( Crate( name, update_tests_sde, check_for_changes_gdb, name + '_NEW', destination_coordinate_system=arcpy.SpatialReference(3857), geographic_transformation='NAD_1983_To_WGS_1984_5'))
def test_hash_custom_source_key_float(self): skip_if_no_local_sde() tbl = 'FLOAT_ID' #: has changes crate = Crate('UPDATE_TESTS.dbo.{}'.format(tbl), update_tests_sde, check_for_changes_gdb, tbl, source_primary_key='TEST') changes = core._hash(crate) self.assertEqual(len(changes.adds), 1)
def test_hash_custom_source_key_float(test_gdb): skip_if_no_local_sde() tbl = 'FLOAT_ID' #: has changes crate = Crate('UPDATE_TESTS.dbo.{}'.format(tbl), UPDATE_TESTS_SDE, test_gdb, tbl) changes = core._hash(crate) assert len(changes.adds) == 1
def run(name): return core._hash( Crate( name, update_tests_sde, test_gdb, destination_coordinate_system=arcpy.SpatialReference(3857), geographic_transformation='NAD_1983_To_WGS_1984_5'), core.hash_gdb_path, True)
def test_destination_exists_hash_not_exist(self): #: If there is no existing hash then the dest table should be truncated #: and all feature should be added as new. arcpy.Copy_management(check_for_changes_gdb, test_gdb) crate = Crate('ExistingDest', test_gdb, test_gdb, 'ExistingDest_Dest') changes = core._hash(crate, core.hash_gdb_path, False) self.assertTrue(arcpy.Exists(path.join(core.hash_gdb_path, crate.name))) self.assertEqual(len(changes.adds), 4) core.update(crate, lambda x: True) self.assertEqual(arcpy.GetCount_management(crate.destination)[0], '4')
def test_source_row_added(self): arcpy.Copy_management(check_for_changes_gdb, test_gdb) crate = Crate('RowAdd', test_gdb, test_gdb, 'RowAdd_Dest') core.update(crate, lambda x: True) with arcpy.da.InsertCursor(crate.source, 'URL') as cur: cur.insertRow(('newrow',)) changes = core._hash(crate) self.assertEqual(len(changes.adds), 1) self.assertEqual(len(changes._deletes), 0) core.update(crate, lambda x: True) self.assertEqual(arcpy.GetCount_management(crate.destination)[0], '6')
def test_source_row_geometry_changed(self): row_api = '4300311427' arcpy.Copy_management(check_for_changes_gdb, test_gdb) crate = Crate('GeometryChange', test_gdb, test_gdb, 'GeometryChange_Dest') core.update(crate, lambda x: True) with arcpy.da.UpdateCursor(crate.source, 'Shape@XY', 'API = \'{}\''.format(row_api)) as cur: for row in cur: row[0] = (row[0][0] + 10, row[0][1] + 10) cur.updateRow(row) break changes = core._hash(crate) self.assertEqual(len(changes.adds), 1) self.assertEqual(len(changes._deletes), 1)
def test_source_row_added(test_gdb): arcpy.Copy_management(test_gdb, TEMP_GDB) crate = Crate('RowAdd', TEMP_GDB, TEMP_GDB, 'RowAdd_Dest') core.update(crate, lambda x: True, CHANGE_DETECTION) with arcpy.da.InsertCursor(crate.source, 'URL') as cur: cur.insertRow(('newrow', )) changes = core._hash(crate) assert len(changes.adds) == 1 assert len(changes._deletes) == 0 core.update(crate, lambda x: True, CHANGE_DETECTION) assert arcpy.GetCount_management(crate.destination)[0] == '6'
def test_source_row_added(self): arcpy.Copy_management(check_for_changes_gdb, test_gdb) crate = Crate('RowAdd', test_gdb, test_gdb, 'RowAdd_Dest') core.update(crate, lambda x: True) with arcpy.da.InsertCursor(crate.source, 'URL') as cur: cur.insertRow(('newrow',)) changes = core._hash(crate, core.hash_gdb_path, False) self.assertEqual(len(changes.adds), 1) self.assertEqual(len(changes._deletes), 0) core.update(crate, lambda x: True) self.assertEqual(arcpy.GetCount_management(path.join(core.hash_gdb_path, crate.name))[0], '6') self.assertEqual(arcpy.GetCount_management(crate.destination)[0], '6')
def test_source_row_attribute_changed(self): row_name = 'MALTA' arcpy.Copy_management(check_for_changes_gdb, test_gdb) crate = Crate('AttributeChange', test_gdb, test_gdb, 'AttributeChange_Dest') core.update(crate, lambda x: True) with arcpy.da.UpdateCursor(crate.source, 'SYMBOL', 'NAME = \'{}\''.format(row_name)) as cur: for row in cur: row[0] = 99 cur.updateRow(row) break changes = core._hash(crate) self.assertEqual(len(changes.adds), 1) self.assertEqual(len(changes._deletes), 1)
def test_source_row_geometry_changed(test_gdb): row_api = '4300311427' arcpy.Copy_management(test_gdb, TEMP_GDB) crate = Crate('GeometryChange', TEMP_GDB, TEMP_GDB, 'GeometryChange_Dest') core.update(crate, lambda x: True, CHANGE_DETECTION) with arcpy.da.UpdateCursor(crate.source, 'Shape@XY', 'API = \'{}\''.format(row_api)) as cur: for row in cur: row[0] = (row[0][0] + 10, row[0][1] + 10) cur.updateRow(row) break changes = core._hash(crate) assert len(changes.adds) == 1 assert len(changes._deletes) == 1
def test_source_row_geometry_changed(self): row_api = '4300311427' row_id = '4164826' arcpy.Copy_management(check_for_changes_gdb, test_gdb) crate = Crate('GeometryChange', test_gdb, test_gdb, 'GeometryChange_Dest') core.update(crate, lambda x: True) with arcpy.da.UpdateCursor(crate.source, 'Shape@XY', 'API = \'{}\''.format(row_api)) as cur: row = cur.next() row[0] = (row[0][0] + 10, row[0][1] + 10) cur.updateRow(row) changes = core._hash(crate, core.hash_gdb_path, False) self.assertEqual(len(changes.adds), 1) self.assertEqual(changes.adds.keys()[0], row_id) self.assertEqual(len(changes._deletes), 1) self.assertEqual(list(changes._deletes)[0], '3')
def test_source_row_geometry_changed_to_none(test_gdb): arcpy.Copy_management(test_gdb, TEMP_GDB) crate = Crate('GeometryToNull', TEMP_GDB, TEMP_GDB, 'GeometryToNull_Dest') core.update(crate, lambda x: True, CHANGE_DETECTION) with arcpy.da.UpdateCursor(crate.source, 'Shape@XY') as cur: for row in cur: row[0] = None cur.updateRow(row) break changes = core._hash(crate) assert len(changes._deletes) == 1 core.update(crate, lambda x: True, CHANGE_DETECTION) assert arcpy.GetCount_management(crate.destination)[0] == '3'
def test_source_row_geometry_changed_to_none(self): arcpy.Copy_management(check_for_changes_gdb, test_gdb) crate = Crate('GeometryToNull', test_gdb, test_gdb, 'GeometryToNull_Dest') core.update(crate, lambda x: True) with arcpy.da.UpdateCursor(crate.source, 'Shape@XY') as cur: row = cur.next() row[0] = None cur.updateRow(row) changes = core._hash(crate, core.hash_gdb_path, False) self.assertEqual(len(changes._deletes), 1) core.update(crate, lambda x: True) self.assertEqual(arcpy.GetCount_management(path.join(core.hash_gdb_path, crate.name))[0], '3') self.assertEqual(arcpy.GetCount_management(crate.destination)[0], '3')
def test_source_row_geometry_changed_to_none(self): arcpy.Copy_management(check_for_changes_gdb, test_gdb) crate = Crate('GeometryToNull', test_gdb, test_gdb, 'GeometryToNull_Dest') core.update(crate, lambda x: True) with arcpy.da.UpdateCursor(crate.source, 'Shape@XY') as cur: for row in cur: row[0] = None cur.updateRow(row) break changes = core._hash(crate) self.assertEqual(len(changes._deletes), 1) core.update(crate, lambda x: True) self.assertEqual(arcpy.GetCount_management(crate.destination)[0], '3')
def test_source_row_attribute_changed(self): row_name = 'MALTA' row_id = '588' arcpy.Copy_management(check_for_changes_gdb, test_gdb) crate = Crate('AttributeChange', test_gdb, test_gdb, 'AttributeChange_Dest') core.update(crate, lambda x: True) with arcpy.da.UpdateCursor(crate.source, 'SYMBOL', 'NAME = \'{}\''.format(row_name)) as cur: row = cur.next() row[0] = 99 cur.updateRow(row) changes = core._hash(crate, core.hash_gdb_path, False) self.assertEqual(len(changes.adds), 1) self.assertEqual(changes.adds.keys()[0], row_id) self.assertEqual(len(changes._deletes), 1) self.assertEqual(list(changes._deletes)[0], '4')
def test_source_row_attribute_changed(test_gdb): row_name = 'MALTA' arcpy.Copy_management(test_gdb, TEMP_GDB) crate = Crate('AttributeChange', TEMP_GDB, TEMP_GDB, 'AttributeChange_Dest') core.update(crate, lambda x: True, CHANGE_DETECTION) with arcpy.da.UpdateCursor(crate.source, 'SYMBOL', 'NAME = \'{}\''.format(row_name)) as cur: for row in cur: row[0] = 99 cur.updateRow(row) break changes = core._hash(crate) assert len(changes.adds) == 1 assert len(changes._deletes) == 1
def test_source_row_deleted(test_gdb): arcpy.Copy_management(test_gdb, TEMP_GDB) crate = Crate('RowDelete', TEMP_GDB, TEMP_GDB, 'RowDelete_Dest') core.update(crate, lambda x: True, CHANGE_DETECTION) with arcpy.da.UpdateCursor(crate.source, '*') as cur: for _ in cur: cur.deleteRow() break changes = core._hash(crate) #: all features hashes are invalid since we deleted the first row #: which changes the salt for all following rows assert len(changes.adds) == 0 assert len(changes._deletes) == 1 core.update(crate, lambda x: True, CHANGE_DETECTION) assert arcpy.GetCount_management(crate.destination)[0] == '4'
def test_source_row_deleted(self): arcpy.Copy_management(check_for_changes_gdb, test_gdb) crate = Crate('RowDelete', test_gdb, test_gdb, 'RowDelete_Dest') core.update(crate, lambda x: True) with arcpy.da.UpdateCursor(crate.source, '*') as cur: for row in cur: cur.deleteRow() break changes = core._hash(crate) #: all features hashes are invalid since we deleted the first row #: which changes the salt for all following rows self.assertEqual(len(changes.adds), 0) self.assertEqual(len(changes._deletes), 1) core.update(crate, lambda x: True) self.assertEqual(arcpy.GetCount_management(crate.destination)[0], '4')
def test_source_row_deleted(self): arcpy.Copy_management(check_for_changes_gdb, test_gdb) crate = Crate('RowDelete', test_gdb, test_gdb, 'RowDelete_Dest') core.update(crate, lambda x: True) with arcpy.da.UpdateCursor(crate.source, '*') as cur: cur.next() cur.deleteRow() changes = core._hash(crate, core.hash_gdb_path, False) #: all features hashes are invalid since we deleted the first row #: which changes the salt for all following rows self.assertEqual(len(changes.adds), 4) self.assertEqual(len(changes._deletes), 5) core.update(crate, lambda x: True) self.assertEqual(arcpy.GetCount_management(path.join(core.hash_gdb_path, crate.name))[0], '4') self.assertEqual(arcpy.GetCount_management(crate.destination)[0], '4')
def run_hash(fc1, fc2): return core._hash(Crate(fc1, check_for_changes_gdb, test_gdb, fc2), core.hash_gdb_path, False)
def run_hash(fc1, fc2): return core._hash(Crate(fc1, test_gdb, test_gdb, fc2))
def run_hash(fc1, fc2): return core._hash(Crate(fc1, check_for_changes_gdb, check_for_changes_gdb, fc2))