def setUp(self): self.editor.startEditing() # All of the tests use this updater which has write rows and remove rows determined by the compare tables function self.updater = Updater(weaver_attributes=self.weaver_attributes, folioIds=self.folio_ids, match_fields=self.match_fields, write_table=self.version_gdb_table, read_rows=self.add_rows, remove_rows=self.exist_rows, version_sde=self.version_sde_file, editor=self.editor)
def setUp(self): self.editor.startEditing(False, True) # All of the tests use this updater which has write rows and remove rows determined by the compare tables function self.updater = Updater(match_fields=self.match_fields, write_table=self.version_gdb_table, read_rows=self.add_rows, remove_rows=self.exist_rows, version_sde=self.version_sde_file, editor=self.editor)
class TestGDBTableUpdater(TestCase): @classmethod def setUpClass(cls): tool = PythonTool() parameters = tool.getParameterInfo() params = tool.processParameters(parameters=parameters) out_f = params["connection_folder"] out_n = params["edit_connection_name"] plat = params["platform"] inst = params["instance"] cls.weaver_attributes = params["table_attributes"] edit_version_name = params["edit_version_name"] sql_table = params["sql_table"] gdb_table = params["gdb_table"] gdb_table_name = params["gdb_table_name"] opt = params["opt"] cls.sde_file = params["gis_gdb"] manager = Manager(opt=opt, connection_folder=out_f, target_sde=cls.sde_file, new_version=edit_version_name, new_connection=out_n, platform=plat, instance=inst) manager.clean_previous() cls.version_sde_file = manager.connect_version() result = Tool.compare_tables(sql_table=sql_table, gdb_table=gdb_table) cls.match_fields = result["match_fields"] cls.add_rows = result["add_rows"] cls.exist_rows = result["exist_rows"] cls.folio_ids = result["folioIds"] env.workspace = cls.version_sde_file cls.editor = da.Editor(cls.version_sde_file) cls.version_gdb_table = arcpy.ListTables("*{}*".format(gdb_table_name))[0] def setUp(self): self.editor.startEditing() # All of the tests use this updater which has write rows and remove rows determined by the compare tables function self.updater = Updater(weaver_attributes=self.weaver_attributes, folioIds=self.folio_ids, match_fields=self.match_fields, write_table=self.version_gdb_table, read_rows=self.add_rows, remove_rows=self.exist_rows, version_sde=self.version_sde_file, editor=self.editor) # def test_count_pid(self): # result = self.updater.count_pid() # if not len(self.updater.read_rows): # self.assertEquals(result, {}) # else: # self.assertTrue(result) def test_delete_rows(self): # change this to a folio in to be removed result = self.updater.delete_rows() if not len(self.updater.remove_rows): self.assertEquals(0, result) else: self.assertGreater(result, 0) def test_insert_rows(self): result = self.updater.insert_rows() if not len(self.updater.read_rows): self.assertEquals(0, result) else: self.assertEquals(len(self.updater.read_rows), result) def test_update_table(self): result = self.updater.update_table() if len(self.updater.read_rows) == len(self.updater.remove_rows): self.assertEqual(result[0], result[1]) elif len(self.updater.read_rows) < len(self.updater.remove_rows): self.assertGreater(result[0], result[1]) elif len(self.updater.read_rows) > len(self.updater.remove_rows): self.assertLess(result[0], result[1]) def test_perform_update(self): result = self.updater.perform_update() self.assertTrue(result) def tearDown(self): self.updater = None self.editor.stopEditing(False) @classmethod def tearDownClass(cls): for x in [cls.version_sde_file]: try: os.remove(x) except: pass del cls.editor
class TestLeaseTableUpdater(TestCase): @classmethod def setUpClass(cls): tool = LeaseUpdateTool() params = tool.getParameterInfo() params = tool.processParameters(parameters=params) out_f = params["connection_folder"] out_n = params["edit_connection_name"] plat = params["platform"] inst = params["instance"] edit_version_name = params["edit_version_name"] sql_table = params["sql_table"] gdb_table = params["gdb_table"] gdb_table_name = params["gdb_table_name"] opt = params["opt"] cls.sde_file = params["gis_gdb"] manager = Manager(opt=opt, connection_folder=out_f, target_sde=cls.sde_file, new_version=edit_version_name, new_connection=out_n, platform=plat, instance=inst) manager.clean_previous() cls.version_sde_file = manager.connect_version() cls.join_field = params["join_field"] cls.agreement_field = params["agreement_field"] cls.leasehold_field = params["leasehold_field"] result = Tool.compare_tables(sql_table=sql_table, gdb_table=gdb_table) cls.match_fields = result["match_fields"] cls.add_rows = result["add_rows"] cls.exist_rows = result["exist_rows"] env.workspace = cls.version_sde_file cls.editor = da.Editor(cls.version_sde_file) cls.version_gdb_table = arcpy.ListTables("*{}*".format(gdb_table_name))[0] def setUp(self): self.editor.startEditing(False, True) # All of the tests use this updater which has write rows and remove rows determined by the compare tables function self.updater = Updater(match_fields=self.match_fields, write_table=self.version_gdb_table, read_rows=self.add_rows, remove_rows=self.exist_rows, version_sde=self.version_sde_file, editor=self.editor) def test_delete_rows(self): # change this to a folio in to be removed result = self.updater.delete_rows() if not len(self.updater.remove_rows): self.assertEquals(0, result) else: self.assertGreater(result, 0) def test_insert_rows(self): result = self.updater.insert_rows() if not len(self.updater.read_rows): self.assertEquals(0, result) else: self.assertEquals(len(self.updater.read_rows), result) def test_update_table(self): result = self.updater.update_table() if len(self.updater.read_rows) == len(self.updater.remove_rows): self.assertEqual(result[0], result[1]) elif len(self.updater.read_rows) < len(self.updater.remove_rows): self.assertGreater(result[0], result[1]) elif len(self.updater.read_rows) > len(self.updater.remove_rows): self.assertLess(result[0], result[1]) def test_perform_update(self): result = self.updater.perform_update() self.assertTrue(result) def test_concatenate(self): result = self.updater.concatenate(self.join_field, self.agreement_field, self.leasehold_field) self.assertTrue(result) def tearDown(self): self.updater = None self.editor.stopEditing(False)
def setUp(self): self.editor.startEditing() self.updater = Updater(weaver_attributes=self.weaver_attributes, folioIds=self.folio_ids, match_fields=self.match_fields, write_table=self.version_gdb_table, read_rows=self.add_rows, remove_rows=self.exist_rows, version_sde=self.version_sde_file, editor=self.editor)
def execute(self, parameters, messages): """The method calls classes defined in external files.""" arcpy.AddMessage("WeaverGDBUpdate.execute()") params = self.process_parameters(parameters=parameters) connection_folder = params["connection_folder"] platform = params["platform"] instance = params["instance"] sde_file = params["gis_gdb"] table_db = params["table_db"] bldgs = params["bldgs"] sql_table = params["sql_table"] gdb_table = params["gdb_table"] gdb_table_name = params["gdb_table_name"] buildings_name = params["buildings_name"] edit_connection_name = params["edit_connection_name"] edit_version_name = params["edit_version_name"] building_attributes = params["building_attributes"] weaver_attributes = params["weaver_attributes"] opt = params["opt"] try: # These values need to be removed when the user parameters are created result = UpdateNoiseMitSDE.compare_tables(sql_table=sql_table, gdb_table=gdb_table) compare_result = result["compare_result"] folioIds = result["folioIds"] match_fields = result["match_fields"] add_rows = result["add_rows"] exist_rows = result["exist_rows"] # compare result if True means that changes need to be made to the GDB Table and thus the Buildings if compare_result: arcpy.AddMessage({"# rows to add": len(add_rows), "# rows to remove": len(exist_rows)}) # create VersionManager class object to create new version, connect to it, # and create an sde connection file, set as current workspace version_manager = VersionManager(opt, connection_folder, sde_file, edit_version_name, edit_connection_name, platform, instance) version_manager.clean_previous() version_sde_file = version_manager.connect_version() if os.path.exists(version_sde_file): arcpy.AddMessage(version_sde_file) else: raise Exception("version_sde_file not created") editor = da.Editor(version_sde_file) editor.startEditing() env.workspace = version_sde_file gdb_table = arcpy.ListTables("*{}*".format(gdb_table_name))[0] if arcpy.Exists(gdb_table): # create GDBTableUpdater class object weaver_updater = GDBTableUpdater(weaver_attributes, folioIds, match_fields, gdb_table, add_rows, exist_rows, version_sde_file, editor) # should return True when editing is complete table_updated = weaver_updater.perform_update() # create BuildingUpdater class object version_buildings = self.get_versioned_fc(version_sde_file, buildings_name) if arcpy.Exists(version_buildings): try: building_updater = BuildingsUpdater(folioIds, version_buildings, gdb_table, building_attributes, weaver_attributes, version_sde_file, editor) # should return True when editing it complete buildings_updated = building_updater.update_buildings() editor.stopEditing(True) del editor try: version_manager.rec_post() except Exception as e: arcpy.AddError("Exception occurred during the rec/post operation, " + "the edits were saved in the version however the version will be removed without the " + "edits having been posted to the default version :: {} :: {}".format(e.message, traceback.print_exc())) except Exception as e: editor.stopEditing(False) del editor arcpy.AddError("Exception occured during buildings updates, edits have not been saved :: {}"\ ":: {}".format(e.message, traceback.print_exc())) else: editor.stopEditing(False) del editor arcpy.AddError("Unable to determine the buildings feature class\ using the version connection") else: editor.stopEditing(False) del editor arcpy.AddError("Unable to determine the gdb table\ using the version connection") version_manager.clean_previous() del version_manager # Verify that the edits where posted # TODO- determine failproof methods for isolating the changed features and viewing the change env.workspace = sde_file fields = [x for x in building_attributes.itervalues()] cursor = da.SearchCursor(bldgs, fields, "{} in ('{}')".format(building_attributes["Folio Number"], "','".join(folioIds))) try: values = cursor.next() arcpy.AddMessage("This is an edited row in the buildings table :: {}".format(values)) except StopIteration: arcpy.AddMessage("No buildings found with folioIDs in {}".format(folioIds)) del cursor else: arcpy.AddMessage("The files are identical, no edits needed") return True except: exc_type, exc_value, exc_traceback = sys.exc_info() arcpy.AddError(repr(traceback.format_exception(exc_type, exc_value, exc_traceback)))