Ejemplo n.º 1
0
    def setUp(self):
        mock_config = MockConfig()
        self.config = mock_config.config
        self.utility = Utility(self.config)

        self.patch_convert_mapped_letter_drive_to_unc_path = mock.patch("dataio.utility.Utility.convert_mapped_letter_drive_to_unc_path")
        self.mock_convert_mapped_letter_drive_to_unc_path = self.patch_convert_mapped_letter_drive_to_unc_path.start()

        self.patch_DeleteRows_management = mock.patch("arcpy.DeleteRows_management")
        self.mock_DeleteRows_management = self.patch_DeleteRows_management.start()

        self.patch_TruncateTable_management = mock.patch("arcpy.TruncateTable_management")
        self.mock_TruncateTable_management = self.patch_TruncateTable_management.start()
Ejemplo n.º 2
0
    def setUp(self):
        mock_config = MockConfig()
        self.config = mock_config.config
        self.utility = Utility(self.config)

        self.patch_Exists = mock.patch("arcpy.Exists")
        self.mock_Exits = self.patch_Exists.start()

        self.patch_date_today = mock.patch.object(self.utility, "date_today")
        self.mock_date_today = self.patch_date_today.start()

        self.patch_todays_gdb_name = mock.patch.object(self.utility,
                                                       "todays_gdb_name")
        self.mock_todays_gdb_name = self.patch_todays_gdb_name.start()
Ejemplo n.º 3
0
class TestUtility(TestCase):
    def setUp(self):
        mock_config = MockConfig()
        self.config = mock_config.config
        self.utility = Utility(self.config)

        self.patch_Exists = mock.patch("arcpy.Exists")
        self.mock_Exits = self.patch_Exists.start()

        self.patch_date_today = mock.patch.object(self.utility, "date_today")
        self.mock_date_today = self.patch_date_today.start()

        self.patch_todays_gdb_name = mock.patch.object(self.utility,
                                                       "todays_gdb_name")
        self.mock_todays_gdb_name = self.patch_todays_gdb_name.start()

    def tearDown(self):
        self.mock_Exits = self.patch_Exists.stop()
        # self.mock_date_today = self.patch_date_today.stop()
        # self.mock_todays_gdb_name = self.patch_todays_gdb_name.stop()

    def test_date_today_calls_strftime_with_correct_date_format_argument(self):
        todays_date = mock.MagicMock(datetime.datetime.today())
        todays_date.strftime.return_value = "test string"
        return_string = self.utility.datetime_now(todays_date)
        self.assertEquals(return_string, "test string")
        self.assertEquals("%Y%m%d", todays_date.strftime.call_args[0][0])
 def create_characterization_model_dictionary(self):
     characterization_dictionary = {}
     self.model_catalog.add_models_from_model_catalog_db(self.model_catalog_db_data_io)
     # TODO - only show valid models - FYI model_catalog.add_models already does a check for valid model(DCA)
     characterization_models = self.model_catalog.characterization_models()
     for model in characterization_models:
         characterization_string = model.model_path + "   " + Utility.format_date(model.create_date) + "   " + model.created_by + " " + str(model.id)
         characterization_dictionary[characterization_string] = model
     self.characterization_model = characterization_dictionary
Ejemplo n.º 5
0
 def test_format_date_string_calls_strftime_with_correct_date_string_argument(self):
     date = mock.MagicMock(datetime.date)
     date.strftime.return_value = "date string"
     return_string = Utility.format_date(date)
     self.assertEquals(return_string, "date string")
     self.assertEquals("%m/%d/%Y %H:%M %p", date.strftime.call_args[0][0])
Ejemplo n.º 6
0
 def test_check_path_has_mapped_network_drive_calls_convert_mapped_letter_drive_to_unc_path_called_with_correct_arguments(self):
     mock_path = r"V:\test\test"
     Utility.check_path(mock_path)
     self.mock_convert_mapped_letter_drive_to_unc_path.assert_called_with("V:")
Ejemplo n.º 7
0
class TestUtility(TestCase):


    def setUp(self):
        mock_config = MockConfig()
        self.config = mock_config.config
        self.utility = Utility(self.config)

        self.patch_convert_mapped_letter_drive_to_unc_path = mock.patch("dataio.utility.Utility.convert_mapped_letter_drive_to_unc_path")
        self.mock_convert_mapped_letter_drive_to_unc_path = self.patch_convert_mapped_letter_drive_to_unc_path.start()

        self.patch_DeleteRows_management = mock.patch("arcpy.DeleteRows_management")
        self.mock_DeleteRows_management = self.patch_DeleteRows_management.start()

        self.patch_TruncateTable_management = mock.patch("arcpy.TruncateTable_management")
        self.mock_TruncateTable_management = self.patch_TruncateTable_management.start()

    def tearDown(self):
        self.mock_convert_mapped_letter_drive_to_unc_path = self.patch_convert_mapped_letter_drive_to_unc_path.stop()
        self.mock_DeleteRows_management = self.patch_DeleteRows_management.stop()
        self.mock_TruncateTable_management = self.patch_TruncateTable_management.stop()

    def test_check_path_has_mapped_network_drive_calls_convert_mapped_letter_drive_to_unc_path_called_with_correct_arguments(self):
        mock_path = r"V:\test\test"
        Utility.check_path(mock_path)
        self.mock_convert_mapped_letter_drive_to_unc_path.assert_called_with("V:")

    def test_check_path_has_mapped_network_drive_calls_convert_mapped_letter_drive_to_unc_path_returns_correct_path(self):
        mock_path = r"V:\test\test"
        self.mock_convert_mapped_letter_drive_to_unc_path.return_value = r"\\besfile1"
        return_path = self.utility.check_path(mock_path)
        self.assertEqual(return_path, r"\\besfile1\test\test")

    def test_check_path_is_unc_path_returns_correct_path(self):
        mock_path = r"\\besfile1\test\test"
        return_path = self.utility.check_path(mock_path)
        self.assertEqual(return_path, r"\\besfile1\test\test")

    def test_check_path_raise_exception_when_winError_throws_exception(self):
        mock_path = r"V:\test\test"
        self.mock_convert_mapped_letter_drive_to_unc_path.side_effect = Exception
        with self.assertRaises(Exception):
            self.utility.check_path(mock_path)

    def test_model_catalog_test_data_cleanup_calls_truncate_table_with_correct_arguments(self):
        self.utility.model_catalog_test_data_cleanup()
        feature_class_list = ["model_tracking_sde_path", "model_alt_bc_sde_path",
                                  "model_alt_hydraulic_sde_path", "model_alt_hydrologic_sde_path",
                                  "project_type_sde_path", "simulation_sde_path",
                                  "geometry_nodes_sde_path", "geometry_areas_sde_path",
                                  "geometry_links_sde_path",
                                  "results_area_sde_path", "results_link_sde_path",
                                  "results_node_sde_path", "results_node_flooding_sde_path", "storage_sde_path"]
        self.assertTrue(self.mock_TruncateTable_management.called)
        for counter, argument in enumerate(self.mock_TruncateTable_management.call_args_list):
            feature_class = argument[0][0]
            self.assertEquals(feature_class, feature_class_list[counter])

    def test_format_date_string_calls_strftime_with_correct_date_string_argument(self):
        date = mock.MagicMock(datetime.date)
        date.strftime.return_value = "date string"
        return_string = Utility.format_date(date)
        self.assertEquals(return_string, "date string")
        self.assertEquals("%m/%d/%Y %H:%M %p", date.strftime.call_args[0][0])
Ejemplo n.º 8
0
 def create_alternative_model_dictionary(self):
     alternative_dictionary = {}
     self.model_catalog.add_models_from_model_catalog_db(
         self.model_catalog_db_data_io)
     alternative_models = self.model_catalog.alternative_models()
     for model in alternative_models:
         alternative_string = model.model_name + "   " + model.model_path + "   " + model.created_by + "   " + Utility.format_date(
             model.create_date)
         alternative_dictionary[alternative_string] = model
     self.alternative_model_dict = alternative_dictionary
Ejemplo n.º 9
0
 def create_characterization_model_dictionary(self):
     characterization_dictionary = {}
     self.model_catalog.add_models_from_model_catalog_db(
         self.model_catalog_db_data_io)
     characterization_models = self.model_catalog.characterization_models()
     for model in characterization_models:
         characterization_string = model.model_name + "   " + model.model_path + "   " + model.created_by + "   " + Utility.format_date(
             model.create_date)
         characterization_dictionary[characterization_string] = model
     self.characterization_model_dict = characterization_dictionary
Ejemplo n.º 10
0
 def create_non_calibration_model_dictionary(self):
     non_calibration_dictionary = {}
     self.model_catalog.add_models_from_model_catalog_db(
         self.model_catalog_db_data_io)
     non_calibration_models = self.model_catalog.non_calibration_models()
     for model in non_calibration_models:
         non_calibration_string = model.model_name + "   " + model.model_path + "   " + model.created_by + "   " + Utility.format_date(
             model.create_date)
         non_calibration_dictionary[non_calibration_string] = model
     self.non_calibration_model_dict = non_calibration_dictionary
Ejemplo n.º 11
0
 def create_registered_model_dictionary(self):
     model_dictionary = {}
     self.model_catalog.add_models_from_model_catalog_db(
         self.model_catalog_db_data_io)
     for model in self.model_catalog.models:
         model_string = model.model_name + "   " + model.model_path + "   " + model.created_by + "   " + Utility.format_date(
             model.create_date)
         model_dictionary[model_string] = model
     self.registered_model_dict = model_dictionary
Ejemplo n.º 12
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)