コード例 #1
0
 def setUp(self):
     dap_client_factory = DapClientFactory()
     dap_client_factory.get_land_cover_dap_client = self._mock_get_land_cover_dap_client
     dap_client_factory.get_soil_properties_dap_client = self._mock_get_soil_properties_dap_client
     self.land_cover_service = LandCoverService(dap_client_factory=dap_client_factory)
     self.model_run_service = ModelRunService()
     self.dataset_service = DatasetService()
     self.parameter_service = ParameterService()
     self.clean_database()
     self.user = self.login()
     self.create_model_run_ready_for_submit()
コード例 #2
0
    def test_GIVEN_thredds_not_working_WHEN_get_default_cover_THEN_zeros_returned(self):
        self.clean_database()
        self.user = self.login()
        self.create_model_run_with_user_uploaded_driving_data()

        def _get_broken_dap_client(url, key):
            return MockLandCoverDapClient("broken_url", key)

        dap_client_factory = DapClientFactory()
        dap_client_factory.get_land_cover_dap_client = _get_broken_dap_client
        self.land_cover_service = LandCoverService(dap_client_factory=dap_client_factory)

        model_run = self.model_run_service.get_model_being_created_with_non_default_parameter_values(self.user)
        fractional_vals = self.land_cover_service.get_default_fractional_cover(model_run, self.user)
        assert_that(fractional_vals, is_([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]))
コード例 #3
0
    def setUp(self):
        self.start_delta = datetime.timedelta(hours=1)
        self.end_delta = datetime.timedelta(hours=2)

        def _create_mock_dap_client(var_name):

            def _gtia(date):
                return date + self.start_delta

            def _gtib(date):
                return date - self.end_delta

            def _data(lat, lon, date):
                return len(var_name) * lat * lon + date

            def _desc():
                return var_name + "_desc"

            def _lat_lon_index(lat, lon):
                return lat, lon

            def _time_index(date):
                start = datetime.datetime(1900, 1, 1)
                secs = (date - start).total_seconds()
                return int(secs / (60 * 30))

            mock_dap_client = MagicMock()
            mock_dap_client.get_time_immediately_after = _gtia
            mock_dap_client.get_time_immediately_before = _gtib
            mock_dap_client.get_data_at = _data
            mock_dap_client.get_longname = _desc
            mock_dap_client.get_lat_lon_index = _lat_lon_index
            mock_dap_client.get_time_index = _time_index
            return mock_dap_client

        def _create_dap_client(url):
            if "file1" in url:
                return _create_mock_dap_client("variable1")
            elif "file2" in url:
                return _create_mock_dap_client("v2")

        mock_dap_client_factory = DapClientFactory()
        mock_dap_client_factory.get_dap_client = MagicMock(side_effect=_create_dap_client)

        self.download_helper = AsciiDownloadHelper("test_url", dap_client_factory=mock_dap_client_factory)
        self.model_run_service = ModelRunService()
        self.nvars = 2
        self.period = 30 * 60
        with session_scope(Session) as session:
            driving_data = DrivingDataset()
            driving_data.name = "Test Driving Dataset"

            pv1 = DrivingDatasetParameterValue(self.model_run_service, driving_data,
                                               constants.JULES_PARAM_DRIVE_DATA_PERIOD, self.period)
            pv2 = DrivingDatasetParameterValue(self.model_run_service, driving_data,
                                               constants.JULES_PARAM_DRIVE_NVARS, self.nvars)
            pv3 = DrivingDatasetParameterValue(self.model_run_service, driving_data,
                                               constants.JULES_PARAM_DRIVE_VAR, "'var1'    'var2'")
            pv4 = DrivingDatasetParameterValue(self.model_run_service, driving_data,
                                               constants.JULES_PARAM_DRIVE_INTERP, "'i'    'nf'")
            ddl1 = DrivingDatasetLocation()
            ddl1.base_url = "data/file1.nc"
            ddl1.var_name = "var1"
            ddl1.driving_dataset = driving_data

            ddl2 = DrivingDatasetLocation()
            ddl2.base_url = "data/file2.nc"
            ddl2.var_name = "var2"
            ddl2.driving_dataset = driving_data

            session.add_all([driving_data])
        self.driving_data = DatasetService().get_driving_dataset_by_id(driving_data.id)