def test_GIVEN_user_uploaded_driving_data_previously_WHEN_page_submit_THEN_moved_to_next_page(self): # 1. User visits driving data page and chooses 'upload' # 2. They upload their data # 3. They click submit (the driving data is now stored). # 4. They return to the driving data page and submit again without changing anything # This is acceptable, they should be moved on. In fact no database saves need to occur. self._add_model_run_being_created(self.user) self.upload_valid_user_driving_data() data_service = DatasetService() ds_id = data_service.get_id_for_user_upload_driving_dataset() response = self.app.post( url(controller='model_run', action='driving_data'), params={ 'driving_dataset': ds_id, 'submit': u'Next', 'lat': u'1800', 'lon': u'-181', 'dt_start': u'2011-02-02 11:00', 'dt_end': u'2017-02-02 11:00', 'driving-file': u'' }) assert_that(response.status_code, is_(302), "Response is redirect") assert_that(urlparse(response.response.location).path, is_(url(controller='model_run', action='extents')), "url")
def upload_valid_user_driving_data(self): data_service = DatasetService() ds_id = data_service.get_id_for_user_upload_driving_dataset() return self.app.post( url(controller='model_run', action='driving_data'), params={ 'driving_dataset': ds_id, 'submit': u'Upload', 'lat': u'55', 'lon': u'45', 'dt_start': u'2000-01-01 00:00', 'dt_end': u'2000-01-01 02:00'}, upload_files=[('driving-file', 'file.txt', self.sample_file_contents)] )
def test_GIVEN_no_user_driving_data_uploaded_WHEN_upload_THEN_errors_shown(self): self._add_model_run_being_created(self.user) data_service = DatasetService() ds_id = data_service.get_id_for_user_upload_driving_dataset() response = self.app.post( url(controller='model_run', action='driving_data'), params={ 'driving_dataset': ds_id, 'submit': u'Upload', 'lat': u'1800', 'lon': u'-181', 'dt_start': u'2011-02-02 11:00', 'dt_end': u'2017-02-02 11:00', 'driving-file': u'' }) assert_that(response.normal_body, contains_string('You must select a driving data file'))
def test_GIVEN_user_driving_data_but_invalid_dates_WHEN_upload_data_THEN_errors_returned(self): self._add_model_run_being_created(self.user) data_service = DatasetService() ds_id = data_service.get_id_for_user_upload_driving_dataset() response = self.app.post( url(controller='model_run', action='driving_data'), params={ 'driving_dataset': ds_id, 'submit': u'Upload', 'lat': u'45', 'lon': u'55', 'dt_start': u'2017-02-02 11:00', 'dt_end': u'this-is-not-a-date'}, upload_files=[('driving-file', 'file.txt', self.sample_file_contents)] ) assert_that(response.normal_body, contains_string('Enter date as YYYY-MM-DD HH:MM'))
def test_GIVEN_user_driving_data_but_invalid_lat_lon_WHEN_upload_data_THEN_errors_returned(self): self._add_model_run_being_created(self.user) data_service = DatasetService() ds_id = data_service.get_id_for_user_upload_driving_dataset() response = self.app.post( url(controller='model_run', action='driving_data'), params={ 'driving_dataset': ds_id, 'submit': u'Upload', 'lat': u'1800', 'lon': u'-181', 'dt_start': u'2011-02-02 11:00', 'dt_end': u'2017-02-02 11:00'}, upload_files=[('driving-file', 'file.txt', self.sample_file_contents)] ) assert_that(response.normal_body, contains_string('Latitude must be between -90 and 90')) assert_that(response.normal_body, contains_string('Longitude must be between -180 and 180'))
def test_GIVEN_valid_user_driving_data_selected_WHEN_page_submit_THEN_proceeds_to_next_page(self): self._add_model_run_being_created(self.user) self.upload_valid_user_driving_data() data_service = DatasetService() ds_id = data_service.get_id_for_user_upload_driving_dataset() response = self.app.post( url(controller='model_run', action='driving_data'), params={ 'driving_dataset': ds_id, 'submit': u'Next', 'lat': u'55', 'lon': u'45', 'dt_start': u'2000-01-01 00:00', 'dt_end': u'2000-01-01 03:00'}, upload_files=[('driving-file', 'file.txt', self.sample_file_contents)] ) assert_that(response.status_code, is_(302), "Response is redirect") assert_that(urlparse(response.response.location).path, is_(url(controller='model_run', action='extents')), "url")
def test_GIVEN_upload_dataset_chosen_but_no_uploaded_dataset_WHEN_page_submit_THEN_error_shown(self): # 1. User visits driving data page # 2. User chooses upload data but doesn't actually upload anything # 3. User clicks submit # This is bad and an error should appear self._add_model_run_being_created(self.user) data_service = DatasetService() ds_id = data_service.get_id_for_user_upload_driving_dataset() response = self.app.post( url(controller='model_run', action='driving_data'), params={ 'driving_dataset': ds_id, 'submit': u'Next', 'lat': u'1800', 'lon': u'-181', 'dt_start': u'2011-02-02 11:00', 'dt_end': u'2017-02-02 11:00', 'driving-file': u'' }) assert_that(response.normal_body, contains_string('You must upload a driving data file'))
def test_GIVEN_user_driving_data_previously_selected_then_changed_on_page_WHEN_page_submit_THEN_data_not_changed( self): # This is understood to be the correct action - unless the 'upload' button is clicked, the user # driving data does not get processed. self._add_model_run_being_created(self.user) self.upload_valid_user_driving_data() self.app.get( url(controller='model_run', action='driving_data')) data_service = DatasetService() ds_id = data_service.get_id_for_user_upload_driving_dataset() self.app.post( url(controller='model_run', action='driving_data'), params={ 'driving_dataset': ds_id, 'submit': u'Next', 'lat': u'12', 'lon': u'17', 'dt_start': u'1990-01-01 00:00', 'dt_end': u'1990-01-01 03:00'}, upload_files=[('driving-file', 'file2.txt', self.sample_file_contents)] ) self.check_valid_user_driving_data_params_stored()
def create_model_run_with_user_uploaded_driving_data(self): # Set up the model as if we'd gone through all the previous pages # and uploaded our own driving data # The Create page self.model_name = u'Run with my own driving data' self.model_description = u'This is a description of a model_run' self.science_config = self.model_run_service.get_scientific_configurations()[0] model_science_config_id = self.science_config['id'] response = self.app.post(url=url(controller='model_run', action='create'), params={ 'name': self.model_name, 'science_configuration': str(model_science_config_id), 'description': self.model_description }) assert response.status_code == 302 # The Driving Data page self.sample_file_contents = "# solar long rain snow temp wind press humid\n" \ "# sw_down lw_down tot_rain tot_snow t wind pstar q\n" \ "# i i i i i i i i\n" \ "3.3 187.8 0.0 0.0 259.10 3.610 102400.5 1.351E-03\n" \ "89.5 185.8 0.0 0.0 259.45 3.140 102401.9 1.357E-03\n" \ "142.3 186.4 0.0 0.0 259.85 2.890 102401.0 1.369E-03\n" \ "# ----- data for later times ----" data_service = DatasetService() self.create_two_driving_datasets() ds_id = data_service.get_id_for_user_upload_driving_dataset() response = self.app.post( url(controller='model_run', action='driving_data'), params={ 'driving_dataset': ds_id, 'submit': u'Upload', 'lat': u'55', 'lon': u'45', 'dt_start': u'2000-01-01 00:00', 'dt_end': u'2000-01-01 02:00'}, upload_files=[('driving-file', 'file.txt', self.sample_file_contents)] ) assert response.status_code == 302 # The Extents page self.lat_n, self.lat_s = 55, 55 self.lon_w, self.lon_e = 45, 45 self.date_start = datetime.datetime(2000, 1, 1, 0, 0, 0) self.date_end = datetime.datetime(2000, 1, 1, 0, 2, 0) response = self.app.post(url(controller='model_run', action='extents'), params={ 'submit': u'Next', 'site': u'single', 'lat': self.lat_n, 'lon': self.lon_e, 'start_date': self.date_start.strftime("%Y-%m-%d"), 'end_date': self.date_end.strftime("%Y-%m-%d") }) assert response.status_code == 302 # The Output Variables page response = self.app.post(url(controller='model_run', action='output'), params={ 'submit': u'Next', 'ov_select_6': 1, 'ov_hourly_6': 1, 'ov_monthly_6': 1, 'ov_select_11': 1, 'ov_yearly_11': 1, 'ov_monthly_11': 1 }) assert response.status_code == 302