def setUp(self): mock_config = MockConfig() self.config_mock = mock_config.config self.config_real = Config("TEST") self.mock_search_cursor = mock.MagicMock(arcpy.da.SearchCursor) self.mock_search_cursor.__iter__.return_value = iter([ (1, "02yr6h", "D"), (2, "05yr6h", "D") ]) self.mock_search_cursor_for_required_simulation_list = mock.MagicMock( arcpy.da.SearchCursor) self.mock_search_cursor_for_required_simulation_list.__iter__.return_value = iter( [("02yr6h", "D", "EX", 0), ("05yr6h", "D", "50", 1)]) self.mock_dev_scenario_search_cursor = mock.MagicMock( arcpy.da.SearchCursor) self.mock_dev_scenario_search_cursor.__iter__.return_value = iter([ (1, "EX"), (2, "50") ]) self.patch_list_of_domains = mock.patch("arcpy.da.ListDomains") self.mock_list_of_domains = self.patch_list_of_domains.start() self.patch_search_cursor = mock.patch("arcpy.da.SearchCursor") self.mock_search_cursor_instance = self.patch_search_cursor.start() self.mock_search_cursor_instance.return_value = self.mock_search_cursor self.key_field = "key_field" self.value_fields = ["field1", "field2"] self.db_table = "db_table_path"
def test_list_by_remaining_days(self): borrows = Borrows(MockConfig(), [ mock_borrows.make_borrow(-1), mock_borrows.make_borrow(-1), mock_borrows.make_borrow(0), mock_borrows.make_borrow(1) ]) self.assertEqual(2, sum(1 for _ in borrows.list_by_remaining_days(1))) self.assertEqual(1, sum(1 for _ in borrows.list_by_remaining_days(0))) self.assertEqual(1, sum(1 for _ in borrows.list_by_remaining_days(-1))) self.assertEqual(0, sum(1 for _ in borrows.list_by_remaining_days(7)))
def setUp(self): model_path = "String" mock_config = MockConfig() self.db_data_io = DbDataIo(mock_config) self.config = mock_config.config self.simulation = Simulation(self.config) self.simulation.model_path = model_path self.simulation.storm_id = 1 self.simulation.dev_scenario_id = 1 self.simulation_data_io = SimulationDataIo(mock_config, self.db_data_io) self.mock_model = mock.MagicMock(Model) area1 = AreaResults(mock_config) area2 = AreaResults(mock_config) self.mock_areas = [area1, area2] self.simulation.areas = self.mock_areas self.patch_area_field_attribute_lookup = mock.patch( "businessclasses.area.Area.input_field_attribute_lookup") self.mock_area_field_attribute_lookup = self.patch_area_field_attribute_lookup.start( ) self.patch_create_objects_from_table_with_current_id = mock.patch( "dataio.db_data_io.DbDataIo.create_objects_from_table_with_current_id" ) self.mock_create_objects_from_table_with_current_id = self.patch_create_objects_from_table_with_current_id.start( ) self.mock_create_objects_from_table_with_current_id.return_value = self.mock_areas self.patch_copy_area_results_to_memory = mock.patch( "dataio.simulation_data_io.SimulationDataIo.copy_area_results_to_memory" ) self.mock_copy_area_results_to_memory = self.patch_copy_area_results_to_memory.start( ) self.patch_delete_management = mock.patch("arcpy.Delete_management") self.mock_delete_management = self.patch_delete_management.start() self.patch_os_path_exists = mock.patch("os.path.exists") self.mock_os_path_exists = self.patch_os_path_exists.start() self.field_attribute_lookup_create_object = OrderedDict() self.field_attribute_lookup_create_object["id_db"] = "id" self.field_attribute_lookup_create_object["parent_id_db"] = "parent_id"
def setUp(self): mock_config = MockConfig() self.mock_simulation = mock.MagicMock(Simulation) self.mock_simulation.storm_id = 1 self.area = AreaResults(mock_config.config)
def setUp(self): mock_config = MockConfig() self.config = mock_config.config self.mock_db_data_io = mock.Mock() self.mock_db_data_io.retrieve_current_id.return_value = 1
def test_load_cache(self, mocked_requests_get): loader = BorrowsLoader(MockConfig()) borrows_1 = loader.load() borrows_2 = loader.load() mocked_requests_get.assert_called_once()
def test_load(self, mocked_requests_get): borrows = BorrowsLoader(MockConfig()).load() mocked_requests_get.assert_called_once() self.assertEqual(borrows, mock_borrows)
def test_ctor_fail(self): with self.assertRaises(Exception): Borrows(MockConfig(), None)
def test_ctor_ok(self): try: Borrows(MockConfig(), []) except: self.fail()
def setUp(self): mock_config = MockConfig() self.config = mock_config.config self.model_catalog = ModelCatalog(self.config) self.model1 = mock.MagicMock(Model) self.model1.id = 1 self.model1.model_purpose_id = self.config.model_purpose_id[ "Calibration"] self.model1.simulations = [] self.model1.model_alterations = [] self.model1.project_types = [] self.model1.model_path = "model_path1" self.model1.create_date = "create_date1" self.model1.created_by = "created_by2" self.model2 = mock.MagicMock(Model) self.model2.id = 2 self.model2.model_purpose_id = self.config.model_purpose_id[ "Characterization"] self.model2.simulations = [] self.model2.model_alterations = [] self.model2.project_types = [] self.model2.model_path = "model_path2" self.model2.create_date = "create_date2" self.model2.created_by = "created_by2" self.simulation1 = mock.MagicMock(Simulation) self.simulation1.id = 1 self.simulation1.parent_id = 1 self.simulation2 = mock.MagicMock(Simulation) self.simulation2.id = 2 self.simulation2.parent_id = 2 self.model_alt_bc1 = mock.MagicMock(ModelAltBc) self.model_alt_bc1.id = 1 self.model_alt_bc1.parent_id = 1 self.model_alt_bc2 = mock.MagicMock(ModelAltBc) self.model_alt_bc2.id = 2 self.model_alt_bc2.parent_id = 2 self.model_alt_hydra1 = mock.MagicMock(ModelAltHydraulic) self.model_alt_hydra1.id = 1 self.model_alt_hydra1.parent_id = 1 self.model_alt_hydra2 = mock.MagicMock(ModelAltHydraulic) self.model_alt_hydra2.id = 2 self.model_alt_hydra2.parent_id = 2 self.model_alt_hydro1 = mock.MagicMock(ModelAltHydrologic) self.model_alt_hydro1.id = 1 self.model_alt_hydro1.parent_id = 1 self.model_alt_hydro2 = mock.MagicMock(ModelAltHydrologic) self.model_alt_hydro2.id = 2 self.model_alt_hydro2.parent_id = 2 self.proj_type1 = mock.MagicMock(ProjectType) self.proj_type1.id = 1 self.proj_type1.parent_id = 1 self.proj_type2 = mock.MagicMock(ProjectType) self.proj_type2.id = 2 self.proj_type2.parent_id = 2 self.model_catalog_db_data_io = mock.MagicMock(ModelCatalogDbDataIo) self.model_catalog_db_data_io.workspace = "in_memory" self.patch_create_objects_from_database = mock.patch.object( self.model_catalog_db_data_io, "create_objects_from_database") self.mock_create_objects_from_database = self.patch_create_objects_from_database.start( )