示例#1
0
    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 setUp(self):

        self.config = Config(test_flag)
        self.model_catalog_db_data_io = ModelCatalogDbDataIo(self.config)
        self.simulation_data_io = SimulationDataIo(
            self.config, self.model_catalog_db_data_io)
        self.simulation = Simulation(self.config)
        self.simulation.id = 999998
        self.simulation.storm_id = 1
        self.simulation.dev_scenario_id = 1

        self.patch_simulation_path = mock.patch.object(self.simulation, "path")
        self.mock_simulation_path = self.patch_simulation_path.start()

        self.mock_simulation_path.return_value = r"\\besfile1\ccsp\03_WP2_Planning_Support_Tools\03_RRAD\CCSP_Data_Management_ToolBox\Test_Cases\Taggart\BaseR011018V4ic\sim\D25yr6h"

        self.model_catalog_dataio = ModelCatalogDbDataIo(self.config)
        self.model_dataio = ModelDataIo(self.config, self.model_catalog_dataio)
        self.model_catalog = ModelCatalog(self.config)
        self.model = Model.initialize_with_current_id(
            self.config, self.model_catalog_dataio)

        self.model.parent_model_id = 555
        self.model.model_request_id = 777
        self.model.project_phase_id = 1
        self.model.engine_type_id = 1
        self.model.create_date = None
        self.model.deploy_date = None  # TODO NEEDS TO BE EXTRACTED FROM CONFIG FILE
        self.model.run_date = None  # TODO NEEDS TO BE EXTRACTED FROM CONFIG FILE
        self.model.extract_date = None  # TODO NEEDS TO BE EXTRACTED FROM CONFIG FILE
        self.model.created_by = getpass.getuser()
        self.model_name = "This is what I call my model"
        self.model.model_path = r"\\besfile1\CCSP\03_WP2_Planning_Support_Tools\03_RRAD\CCSP_Data_Management_ToolBox\Test_Cases\Taggart\Final"
        self.model.project_type_id = 1
        self.model.model_purpose_id = self.config.model_purpose_id[
            "Characterization"]
        self.model.model_calibration_file = "C:\Temp\Cal"
        self.model.model_status_id = self.config.model_status_id["Working"]
        self.model.model_alteration_file = "C:\Temp\BC"
        self.model.project_num = "E10TEST"
        self.model.create_date = datetime.datetime.today()
        self.model.create_model_alterations_bc([["Stage"]],
                                               self.model_catalog_dataio)
        self.model.create_model_alterations_hydrologic(
            [["Area Factor"]], self.model_catalog_dataio)
        self.model.create_model_alterations_hydraulic(
            [["Pipe Roughness"]], self.model_catalog_dataio)
        self.model.create_project_types(["Storm"], self.model_catalog_dataio)
        self.model.create_simulations(self.model_dataio)
        self.model_dataio.set_model_to_read_write(self.model)
示例#3
0
    def test_config_init_with_test_flag_as_false_sde_path_to_prod_server(self):
        with mock.patch("businessclasses.config.Config.retrieve_domain_as_dict"
                        ) as mock_retrieve_domain_as_dict:
            test_bool = "PROD"
            mock_retrieve_domain_as_dict.return_value = {"dict1": 1}
            config = Config(test_bool)
            sde_connections = r"\\besfile1\CCSP\03_WP2_Planning_Support_Tools\03_RRAD\CCSP_Data_Management_ToolBox\connection_files"
            model_catalog_prod_sde = r"BESDBPROD1.MODELCATALOG.sde"
            EMGAATS_prod_sde = r"BESDBPROD1.EMGAATS.sde"
            ASM_WORK_prod_sde = r"BESDBPROD1.ASM_WORK.sde"

            model_catalog_prod_sde_path = os.path.join(sde_connections,
                                                       model_catalog_prod_sde)
            EMGAATS_prod_sde_path = os.path.join(sde_connections,
                                                 EMGAATS_prod_sde)
            ASM_WORK_prod_sde_path = os.path.join(sde_connections,
                                                  ASM_WORK_prod_sde)

            self.assertEquals(config.model_catalog_sde_path,
                              model_catalog_prod_sde_path)
            self.assertEquals(config.EMGAATS_sde_path, EMGAATS_prod_sde_path)
            self.assertEquals(config.ASM_WORK_sde_path, ASM_WORK_prod_sde_path)
    def setUp(self):

        self.config = Config(test_flag)
        cip_numbers = self.config.unique_cip_numbers
        self.model_catalog_dataio = ModelCatalogDbDataIo(self.config)
        self.model_dataio = ModelDataIo(self.config, self.model_catalog_dataio)
        self.model_catalog = ModelCatalog(self.config)
        self.model = Model.initialize_with_current_id(
            self.config, self.model_catalog_dataio)

        self.model.parent_model_id = 555
        self.model.model_request_id = 777
        self.model.project_phase_id = 1
        self.model.engine_type_id = 1
        self.model.create_date = None
        self.model.created_by = getpass.getuser()
        self.model.model_path = r"\\besfile1\ccsp\Models\OAK\2Cali\Final"  ## does this one have all the required storms?
        self.model.deploy_date = None  # TODO NEEDS TO BE EXTRACTED FROM CONFIG FILE
        self.model.run_date = None  # TODO NEEDS TO BE EXTRACTED FROM CONFIG FILE
        self.model.set_extract_date(self.model_dataio)
        self.model.project_type_id = 1
        self.model.model_purpose_id = self.config.model_purpose_id[
            "Calibration"]
        self.model.model_calibration_file = "C:\Temp\Cal"
        self.model.model_status_id = self.config.model_status_id["Working"]
        self.model.model_alteration_file = "C:\Temp\BC"
        self.model.project_num = "E10TEST"
        self.model.create_date = datetime.datetime.today()
        self.model.create_model_alterations_bc([["Stage"]],
                                               self.model_catalog_dataio)
        self.model.create_model_alterations_hydrologic(
            [["Area Factor"]], self.model_catalog_dataio)
        self.model.create_model_alterations_hydraulic(
            [["Pipe Roughness"]], self.model_catalog_dataio)
        self.model.create_project_types(["Storm"], self.model_catalog_dataio)
        self.model.create_simulations(self.model_dataio)
        self.model_dataio.set_model_to_read_write(self.model)
def create_citywide_hybrid():
    start = time.time()
    #config = Config('TEST')
    config = Config('PROD')
    dme_master_hybrid = DmeMasterHybrid(config)
    dme_master_hybrid_db_data_io = DmeMasterHybridDbDataIo(config)

    start = time.time()
    test_dme_links = dme_master_hybrid.create_dme_links(dme_master_hybrid_db_data_io)
    print "   Creating DME links - duration: " + str(time.time() - start) + " seconds"

    start = time.time()
    test_master_links = dme_master_hybrid.create_master_links(dme_master_hybrid_db_data_io)
    print "   Creating master links - duration: " + str(time.time() - start) + " seconds"

    dme_master_links = []
    start = time.time()
    test_dme_links.sort(key=lambda x: x.global_id, reverse=True)
    test_master_links.sort(key=lambda x: x.global_id, reverse=True)
    invalid_counter = 0

    for dme_link in test_dme_links:
        dme_master_link = DmeMasterLink(config)
        dme_master_link.global_id = dme_link.global_id
        dme_master_link.us_node_name = dme_link.us_node_name
        dme_master_link.ds_node_name = dme_link.ds_node_name
        dme_master_link.compkey = dme_link.compkey
        dme_master_link.diameter = dme_link.diameter
        dme_master_link.geometry = dme_link.geometry

        for index, master_link in enumerate(test_master_links):
            if dme_link.global_id == master_link.global_id:
                diameter = 0
                valid_us_depth = False
                valid_ds_depth = False
                valid_diameter = False
                valid_dme_diameter = False
                valid_master_diameter = False
                valid_ies = (master_link.us_ie != 0 and master_link.ds_ie != 0)
                if (dme_link.diameter > 0) and dme_link.diameter is not None:
                    valid_dme_diameter = True
                if (master_link.diameter > 0) and master_link.diameter is not None:
                    valid_master_diameter = True

                if valid_dme_diameter:
                    diameter = dme_link.diameter
                    valid_diameter = True
                elif valid_master_diameter:
                    diameter = master_link.diameter
                    valid_diameter = True
                else:
                    #print "         Invalid Diameter"
                    invalid_counter += 1
                    diameter = 4
                    valid_diameter = False

                if valid_diameter and valid_ies:
                    min_depth = (diameter / 12.0 + 1.0)
                    if master_link.us_depth > min_depth:
                        valid_us_depth = True
                    if master_link.ds_depth > min_depth:
                        valid_ds_depth = True

                if valid_us_depth and valid_ds_depth:
                    dme_master_link.us_depth = master_link.us_depth
                    dme_master_link.ds_depth = master_link.ds_depth
                    dme_master_link.us_ie = master_link.us_ie
                    dme_master_link.ds_ie = master_link.ds_ie
                    dme_master_link.link_id = master_link.link_id
                    dme_master_link.us_depth_source = "Master"
                    dme_master_link.ds_depth_source = "Master"
                else:
                    dme_master_link.us_depth = 10
                    dme_master_link.ds_depth = 10
                    if valid_us_depth:
                        dme_master_link.us_depth = master_link.us_depth
                        dme_master_link.us_depth_source = "Master"
                    else:
                        dme_master_link.us_depth = 10
                        dme_master_link.us_depth_source = "10_ft_fill_Master"
                    if valid_ds_depth:
                        dme_master_link.ds_depth = master_link.ds_depth
                        dme_master_link.ds_depth_source = "Master"
                    else:
                        dme_master_link.ds_depth = 10
                        dme_master_link.ds_depth_source = "10_ft_fill_Master"
                dme_master_link.diameter = diameter
                dme_master_links.append(dme_master_link)
                test_master_links.pop(index)
                break
        else:
            dme_master_link.us_depth = 10
            dme_master_link.ds_depth = 10
            dme_master_link.us_ie = None
            dme_master_link.ds_ie = None
            dme_master_link.link_id = None
            dme_master_link.us_depth_source = "10ftFill"
            dme_master_link.ds_depth_source = "10ftFill"
            dme_master_link.diameter = 4
            dme_master_links.append(dme_master_link)

    if invalid_counter > 0:
        print "   Records with Invalid Diameter: " + str(invalid_counter)
    print "   Data conditioning - duration: " + str(time.time() - start) + " seconds"

    start = time.time()
    dme_master_hybrid_db_data_io.append_dme_master_links_to_db(dme_master_links)
    #dme_master_hybrid_db_data_io.copy_dme_master_links_to_db(dme_master_links)
    print "   Writing result - duration: " + str(time.time() - start) + " seconds"
    pass

#FOR TESTING/ RUNNING INDEPENDENTLY
#create_citywide_hybrid()
示例#6
0
class TestConfig(TestCase):
    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 tearDown(self):
        self.mock_search_cursor_instance = self.patch_search_cursor.stop()
        self.mock_list_of_domains = self.patch_list_of_domains.stop()

# TODO need to add a test for Dry does not follow logic of D for design + storm name like all of the other storms

    def test_standard_simulation_names(self):
        standard_simulation_names = [
            'D25yr6h', 'D25yr6h-50', 'D25yr6h-BO', 'D10yr6h', 'D10yr6h-50',
            'D10yr6h-BO'
        ]
        output_simulation_names = self.config_mock.standard_simulation_names()
        self.assertEquals(output_simulation_names, standard_simulation_names)

    def test_reverse_dict_returns_reverse_dict(self):
        test_dictionary = {0: "one", 1: "two", 2: "three"}
        reverse_dictionary = {"one": 0, "two": 1, "three": 2}
        test_reverse = self.config_real.reverse_dict(test_dictionary)
        self.assertEquals(test_reverse, reverse_dictionary)

    def test_retrieve_domain_as_dict_calls_list_of_domains_with_correct_arguments(
            self):
        self.config_real.retrieve_domain_as_dict(
            "Engine_Type", self.config_real.model_catalog_sde_path)
        self.mock_list_of_domains.assert_called_with(
            self.config_real.model_catalog_sde_path)

    def test_retrieve_domain_as_dict_returns_correct_dict(self):
        mock_domain1 = mock.MagicMock(arcpy.da.Domain)
        mock_domain1.name = "Engine_Type"
        mock_domain1.codedValues = {1: "EMGAATS"}
        mock_domain2 = mock.MagicMock(arcpy.da.Domain)
        mock_domain2.name = "Storm_Type"
        self.mock_list_of_domains.return_value = [mock_domain1, mock_domain2]
        domain_dict_of_scenarios = self.config_real.retrieve_domain_as_dict(
            "Engine_Type", self.config_real.model_catalog_sde_path)
        self.assertEquals(domain_dict_of_scenarios, {1: "EMGAATS"})

    def test_retrieve_engine_type_domain_as_dict_called_with_correct_domain_name(
            self):
        with mock.patch.object(
                self.config_real,
                "retrieve_domain_as_dict") as mock_retrieve_domain_as_dict:
            self.config_real.retrieve_engine_type_domain_as_dict()
            mock_retrieve_domain_as_dict.assert_called_with(
                "Engine_Type", self.config_real.model_catalog_sde_path)

    def test_retrieve_model_alt_bc_domain_as_dict_called_with_correct_domain_name(
            self):
        with mock.patch.object(
                self.config_real,
                "retrieve_domain_as_dict") as mock_retrieve_domain_as_dict:
            self.config_real.retrieve_model_alt_bc_domain_as_dict()
            mock_retrieve_domain_as_dict.assert_called_with(
                "Model_Alt_BC", self.config_real.model_catalog_sde_path)

    def test_retrieve_model_alt_hydraulic_domain_as_dict_called_with_correct_domain_name(
            self):
        with mock.patch.object(
                self.config_real,
                "retrieve_domain_as_dict") as mock_retrieve_domain_as_dict:
            self.config_real.retrieve_model_alt_hydraulic_domain_as_dict()
            mock_retrieve_domain_as_dict.assert_called_with(
                "Model_Alt_Hydraulic", self.config_real.model_catalog_sde_path)

    def test_retrieve_model_alt_hydrologic_domain_as_dict_called_with_correct_domain_name(
            self):
        with mock.patch.object(
                self.config_real,
                "retrieve_domain_as_dict") as mock_retrieve_domain_as_dict:
            self.config_real.retrieve_model_alt_hydrologic_domain_as_dict()
            mock_retrieve_domain_as_dict.assert_called_with(
                "Model_Alt_Hydrologic",
                self.config_real.model_catalog_sde_path)

    def test_retrieve_model_purpose_domain_as_dict_called_with_correct_domain_name(
            self):
        with mock.patch.object(
                self.config_real,
                "retrieve_domain_as_dict") as mock_retrieve_domain_as_dict:
            self.config_real.retrieve_model_purpose_domain_as_dict()
            mock_retrieve_domain_as_dict.assert_called_with(
                "Model_Purpose", self.config_real.model_catalog_sde_path)

    def test_retrieve_model_status_domain_as_dict_called_with_correct_domain_name(
            self):
        with mock.patch.object(
                self.config_real,
                "retrieve_domain_as_dict") as mock_retrieve_domain_as_dict:
            self.config_real.retrieve_model_status_domain_as_dict()
            mock_retrieve_domain_as_dict.assert_called_with(
                "Model_Status", self.config_real.model_catalog_sde_path)

    def test_retrieve_proj_phase_domain_as_dict_called_with_correct_domain_name(
            self):
        with mock.patch.object(
                self.config_real,
                "retrieve_domain_as_dict") as mock_retrieve_domain_as_dict:
            self.config_real.retrieve_proj_phase_domain_as_dict()
            mock_retrieve_domain_as_dict.assert_called_with(
                "Proj_Phase", self.config_real.model_catalog_sde_path)

    def test_retrieve_proj_type_domain_as_dict_called_with_correct_domain_name(
            self):
        with mock.patch.object(
                self.config_real,
                "retrieve_domain_as_dict") as mock_retrieve_domain_as_dict:
            self.config_real.retrieve_proj_type_domain_as_dict()
            mock_retrieve_domain_as_dict.assert_called_with(
                "Proj_Type", self.config_real.model_catalog_sde_path)

    def test_retrieve_dict_from_db_calls_search_cursor_with_correct_arguments(
            self):
        self.config_real.retrieve_dict_from_db(self.key_field,
                                               self.value_fields,
                                               self.db_table)
        self.mock_search_cursor_instance.assert_called_with(
            "db_table_path", ["key_field", "field1", "field2"])

    def test_retrieve_dict_from_db_has_multiple_fields_returns_correct_dictionary(
            self):
        return_dict = {1: ("02yr6h", "D"), 2: ("05yr6h", "D")}
        storm_dict = self.config_real.retrieve_dict_from_db(
            self.key_field, self.value_fields, self.db_table)
        self.assertEqual(storm_dict, return_dict)

    def test_retrieve_dict_from_db_has_one_field_returns_correct_dictionary(
            self):
        return_dict = {1: "EX", 2: "50"}
        self.value_fields = ["field1"]
        self.mock_search_cursor_instance.return_value = self.mock_dev_scenario_search_cursor
        storm_dict = self.config_real.retrieve_dict_from_db(
            self.key_field, self.value_fields, self.db_table)
        self.assertEqual(storm_dict, return_dict)

    def test_retrieve_storm_dict_calls_retrieve_dict_from_db_with_correct_arguments(
            self):
        with mock.patch.object(
                self.config_real,
                "retrieve_dict_from_db") as mock_retrieve_dict_from_db:
            self.config_real.retrieve_storm_dict()
            mock_retrieve_dict_from_db.assert_called_with(
                "storm_id", ["storm_name", "storm_type"],
                self.config_real.storms_sde_path)

    def test_retrieve_storm_dict_returns_correct_value(self):
        with mock.patch.object(
                self.config_real,
                "retrieve_dict_from_db") as mock_retrieve_dict_from_db:
            mock_retrieve_dict_from_db.return_value = "return value"
            return_value = self.config_real.retrieve_storm_dict()
            self.assertEqual(return_value, "return value")

    def test_retrieve_dev_scenario_dict_calls_retrieve_dict_from_db_with_correct_arguments(
            self):
        with mock.patch.object(
                self.config_real,
                "retrieve_dict_from_db") as mock_retrieve_dict_from_db:
            self.config_real.retrieve_dev_scenario_dict()
            mock_retrieve_dict_from_db.assert_called_with(
                "dev_scenario_id", ["dev_scenario"],
                self.config_real.dev_scenarios_sde_path)

    def test_retrieve_dev_scenario_dict_returns_correct_value(self):
        with mock.patch.object(
                self.config_real,
                "retrieve_dict_from_db") as mock_retrieve_dict_from_db:
            mock_retrieve_dict_from_db.return_value = "return value"
            return_value = self.config_real.retrieve_dev_scenario_dict()
            self.assertEqual(return_value, "return value")

    def test_retrieve_cip_analysis_request_dict_is_called_with_correct_arguments(
            self):
        with mock.patch.object(
                self.config_real,
                "retrieve_dict_from_db") as mock_retrieve_dict_from_db:
            self.config_real.retrieve_cip_analysis_request_dict()
            mock_retrieve_dict_from_db.assert_called_with(
                "AR_ID", ["ProjectNumber"],
                self.config_real.analysis_requests_sde_path)

    def test_retrieve_cip_analysis_request_dict_returns_correct_value(self):
        with mock.patch.object(
                self.config_real,
                "retrieve_dict_from_db") as mock_retrieve_dict_from_db:
            mock_retrieve_dict_from_db.return_value = {
                "key1": "value",
                "key2": None
            }
            return_value = self.config_real.retrieve_cip_analysis_request_dict(
            )
            self.assertEqual(return_value, {"key1": "value"})

    def test_get_unique_values_returns_unique_values(self):
        input_dict = {"key1": "value", "key2": "value", "key3": "value1"}
        unique_values = self.config_real.get_unique_values(input_dict)
        self.assertItemsEqual(unique_values, ["value", "value1"])

    def test_get_unique_values_case_insensitive_returns_unique_values_regardless_of_case(
            self):
        input_dict = {"key1": "value", "key2": "Value", "key3": "value1"}
        unique_values = self.config_real.get_unique_values_case_insensitive(
            input_dict)
        self.assertItemsEqual(unique_values, ["VALUE", "VALUE1"])

    def test_get_keys_based_on_value_returns_correct_keys(self):
        test_dict = {"Key1": "value", "Key2": "value", "Key3": "bad_value"}
        test_value = "value"
        check_keys = self.config_real.get_keys_based_on_value(
            test_dict, test_value)
        self.assertItemsEqual(check_keys, ["Key1", "Key2"])

    def test_get_keys_based_on_value_case_insensitive_returns_correct_keys_regardless_of_value_case(
            self):
        test_dict = {"Key1": "value", "Key2": "VALUE", "Key3": "bad_value"}
        test_value = "value"
        return_keys = self.config_real.get_keys_based_on_value_case_insensitive(
            test_dict, test_value)
        self.assertItemsEqual(return_keys, ["Key1", "Key2"])

    def test_get_cip_analysis_requests_returns_correct_cip_requests(self):
        self.config_real.cip_analysis_requests = {
            "Key1": "e1000",
            "Key2": "E1000",
            "Key3": "bad_value"
        }
        cip_number = "E1000"
        cip_analysis_requests = self.config_real.get_cip_analysis_requests(
            cip_number)
        self.assertItemsEqual(cip_analysis_requests, ["Key1", "Key2"])

    def test_get_unique_cip_numbers_returns_cip_numbers_without_empty_unicode_string(
            self):
        input_dict = {
            "key1": "value1",
            "key2": "Value",
            "key3": "value",
            "key4": u''
        }
        self.config_real.cip_analysis_requests = input_dict
        unique_values = self.config_real.get_unique_cip_numbers()
        self.assertItemsEqual(unique_values, ["VALUE", "VALUE1"])
        self.assertEqual(unique_values[0], "VALUE1")
        self.assertEqual(unique_values[1], "VALUE")

    def test_retrieve_required_storm_and_dev_scenario_ids_with_purpose_characterization_calls_search_cursor_with_correct_arguments(
            self):
        model_purpose = "Characterization"
        model_project_phase = "Planning"
        self.mock_search_cursor_instance.return_value = self.mock_search_cursor_for_required_simulation_list
        self.config_real.retrieve_required_storm_and_dev_scenario_ids(
            model_purpose, model_project_phase)
        self.mock_search_cursor_instance.assert_called_with(
            self.config_real.required_simulations_sde_path, [
                "storm_name", "storm_type", "dev_scenario",
                "ccsp_characterization"
            ])

    def test_retrieve_required_storm_and_dev_scenario_ids_with_purpose_characterization_returns_correct_list_of_required_simulations(
            self):
        model_purpose = "Characterization"
        model_project_phase = "Planning"
        self.mock_search_cursor_instance.return_value = self.mock_search_cursor_for_required_simulation_list
        required_simulations = self.config_real.retrieve_required_storm_and_dev_scenario_ids(
            model_purpose, model_project_phase)
        self.assertEqual(required_simulations, [(2, 2)])

    def test_retrieve_required_storm_and_dev_scenario_ids_throws_exception_when_storm_name_not_in_storm_id_dict(
            self):
        model_purpose = "Characterization"
        model_project_phase = "Planning"
        self.mock_search_cursor_for_required_simulation_list.__iter__.return_value = iter(
            [("02yr6h", "D", "EX", 0), ("incorrect_storm_name", "D", "50", 1)])
        self.mock_search_cursor_instance.return_value = self.mock_search_cursor_for_required_simulation_list
        with self.assertRaises(
                InvalidStormNameOrStormTypeInRequiredSimulationsTable):
            self.config_real.retrieve_required_storm_and_dev_scenario_ids(
                model_purpose, model_project_phase)

    def test_retrieve_required_storm_and_dev_scenario_ids_throws_exception_when_dev_scenario_not_in_dev_scenario_dict(
            self):
        model_purpose = "Characterization"
        model_project_phase = "Planning"
        self.mock_search_cursor_for_required_simulation_list.__iter__.return_value = iter(
            [("02yr6h", "D", "EX", 0),
             ("05yr6h", "D", "incorrect_dev_scenario", 1)])
        self.mock_search_cursor_instance.return_value = self.mock_search_cursor_for_required_simulation_list
        with self.assertRaises(InvalidDevScenarioInRequiredSimulationsTable):
            self.config_real.retrieve_required_storm_and_dev_scenario_ids(
                model_purpose, model_project_phase)

    def test_retrieve_required_storm_and_dev_scenario_ids_throws_exception_with_invalid_project_phase(
            self):
        model_purpose = "Characterization"
        model_project_phase = "invalid_project_phase"
        self.mock_search_cursor_for_required_simulation_list.__iter__.return_value = iter(
            [("02yr6h", "D", "EX", 0),
             ("05yr6h", "D", "incorrect_dev_scenario", 1)])
        self.mock_search_cursor_instance.return_value = self.mock_search_cursor_for_required_simulation_list
        with self.assertRaises(InvalidProjectPhase):
            self.config_real.retrieve_required_storm_and_dev_scenario_ids(
                model_purpose, model_project_phase)

    def test_retrieve_required_storm_and_dev_scenario_ids_throws_exception_with_invalid_model_purpose(
            self):
        model_purpose = "Invalid_model_purpose"
        model_project_phase = "Planning"
        self.mock_search_cursor_for_required_simulation_list.__iter__.return_value = iter(
            [("02yr6h", "D", "EX", 0),
             ("05yr6h", "D", "incorrect_dev_scenario", 1)])
        self.mock_search_cursor_instance.return_value = self.mock_search_cursor_for_required_simulation_list
        with self.assertRaises(InvalidModelPurposeException):
            self.config_real.retrieve_required_storm_and_dev_scenario_ids(
                model_purpose, model_project_phase)

    def test_config_init_with_test_flag_as_true_sde_path_to_test_server(self):
        with mock.patch("businessclasses.config.Config.retrieve_domain_as_dict"
                        ) as mock_retrieve_domain_as_dict:
            test_bool = "TEST"
            mock_retrieve_domain_as_dict.return_value = {"dict1": 1}
            config = Config(test_bool)
            sde_connections = r"\\besfile1\CCSP\03_WP2_Planning_Support_Tools\03_RRAD\CCSP_Data_Management_ToolBox\connection_files"
            model_catalog_test_sde = r"BESDBTEST1.MODELCATALOG.sde"
            EMGAATS_test_sde = r"BESDBTEST1.EMGAATS.sde"
            ASM_WORK_test_sde = r"BESDBTEST1.ASM_WORK.sde"

            model_catalog_test_sde_path = os.path.join(sde_connections,
                                                       model_catalog_test_sde)
            EMGAATS_test_sde_path = os.path.join(sde_connections,
                                                 EMGAATS_test_sde)
            ASM_WORK_test_sde_path = os.path.join(sde_connections,
                                                  ASM_WORK_test_sde)

            self.assertEquals(config.model_catalog_sde_path,
                              model_catalog_test_sde_path)
            self.assertEquals(config.EMGAATS_sde_path, EMGAATS_test_sde_path)
            self.assertEquals(config.ASM_WORK_sde_path, ASM_WORK_test_sde_path)

    def test_config_init_with_test_flag_as_false_sde_path_to_prod_server(self):
        with mock.patch("businessclasses.config.Config.retrieve_domain_as_dict"
                        ) as mock_retrieve_domain_as_dict:
            test_bool = "PROD"
            mock_retrieve_domain_as_dict.return_value = {"dict1": 1}
            config = Config(test_bool)
            sde_connections = r"\\besfile1\CCSP\03_WP2_Planning_Support_Tools\03_RRAD\CCSP_Data_Management_ToolBox\connection_files"
            model_catalog_prod_sde = r"BESDBPROD1.MODELCATALOG.sde"
            EMGAATS_prod_sde = r"BESDBPROD1.EMGAATS.sde"
            ASM_WORK_prod_sde = r"BESDBPROD1.ASM_WORK.sde"

            model_catalog_prod_sde_path = os.path.join(sde_connections,
                                                       model_catalog_prod_sde)
            EMGAATS_prod_sde_path = os.path.join(sde_connections,
                                                 EMGAATS_prod_sde)
            ASM_WORK_prod_sde_path = os.path.join(sde_connections,
                                                  ASM_WORK_prod_sde)

            self.assertEquals(config.model_catalog_sde_path,
                              model_catalog_prod_sde_path)
            self.assertEquals(config.EMGAATS_sde_path, EMGAATS_prod_sde_path)
            self.assertEquals(config.ASM_WORK_sde_path, ASM_WORK_prod_sde_path)
from businessclasses.config import Config
from businessclasses.dme_master_hybrid import DmeMasterHybrid
from businessclasses.dme_master_link import DmeMasterLink
from dataio.dme_master_hybrid_db_data_io import DmeMasterHybridDbDataIo
import time

start = time.time()

config = Config('TEST')
dme_master_hybrid = DmeMasterHybrid(config)
dme_master_hybrid_db_data_io = DmeMasterHybridDbDataIo(config)

## will write out result for a subset of mlinks specified in CCSP.MASTER_LINK_NAMES (specified in view)
## 1. create in memory version of DME links
## 2. create in memory version of EMGAATS links which have already been subset to project area
## 3. overwrite information from EMGAATS links to DME links where global_ids match
## 4. append result to CCSP.DME_MASTER_HYBRID

start = time.time()
test_dme_pipes = dme_master_hybrid.create_dme_links(
    dme_master_hybrid_db_data_io)
print time.time() - start

start = time.time()
test_ccsp_master_links = dme_master_hybrid.create_ccsp_master_links(
    dme_master_hybrid_db_data_io)
print time.time() - start

dme_master_links = []
start = time.time()
示例#8
0
from businessclasses.config import Config
from dataio.utility import Utility

config = Config("TEST")
utility = Utility(config)

print("Cleaning model catalog test data")
utility.model_catalog_test_data_cleanup()
utility.set_current_ids_to_zero(config.model_catalog_current_id_table_sde_path)