def test_GIVEN_select_submit_WHEN_post_THEN_redirect_to_index_page_job_submitted(self): self.model_run_service.update_model_run(self.user, "test", constants.DEFAULT_SCIENCE_CONFIGURATION) self.model_run_service.store_parameter_values({'1': 12}, self.user) self.parameter_service.save_new_parameters([[constants.JULES_PARAM_LATLON_REGION, True], [constants.JULES_PARAM_DRIVE_DATA_START, dt.datetime(1901, 1, 1)], [constants.JULES_PARAM_SPINUP_START, dt.datetime(1905, 1, 1)]], [], self.user.id) response = self.app.post( url=url(controller='model_run', action='submit'), params={ 'submit': u'Submit' } ) assert_that(response.status_code, is_(302), "Response is redirect") assert_that(urlparse(response.response.location).path, is_(url(controller='model_run', action='index')), "url") session = Session() row = session.query("name").from_statement( """ SELECT s.name FROM model_runs m JOIN model_run_statuses s on s.id = m.status_id WHERE m.user_id = :userid """) \ .params({'userid': self.user.id}) \ .one() assert_that(row.name, is_(constants.MODEL_RUN_STATUS_SUBMIT_FAILED), "model run status")
def test_GIVEN_select_submit_and_user_over_quota_WHEN_post_THEN_redirect_to_index_page_job_not_submitted(self): big_model_run = self.create_run_model(storage_in_mb=self.user.storage_quota_in_gb * 1024 + 1, name="big_run", user=self.user) self.model_run_service.update_model_run(self.user, "test", constants.DEFAULT_SCIENCE_CONFIGURATION) self.model_run_service.store_parameter_values({'1': 12}, self.user) response = self.app.post( url=url(controller='model_run', action='submit'), params={ 'submit': u'Submit' } ) assert_that(response.status_code, is_(302), "Response is redirect") assert_that(urlparse(response.response.location).path, is_(url(controller='model_run', action='index')), "url") session = Session() row = session.query("name").from_statement( """ SELECT s.name FROM model_runs m JOIN model_run_statuses s on s.id = m.status_id WHERE m.user_id = :userid AND m.id != :model_run_id """) \ .params({'userid': self.user.id, 'model_run_id': big_model_run.id}) \ .one() assert_that(row.name, is_(constants.MODEL_RUN_STATUS_CREATED), "model run status")
def assert_parameter_of_model_being_created_is_a_value(self, parameter_id, expected_parameter_value): """ Assert that the parameter value is correct for the model being created :param parameter_id: the id of the parameter to assert the value of :param expected_parameter_value: expected parameters value :return:Nothing """ session = Session() row = session.query("value").from_statement( """ SELECT pv.value FROM model_runs m JOIN model_run_statuses s on s.id = m.status_id JOIN parameter_values pv on pv.model_run_id = m.id JOIN parameters p on pv.parameter_id = p.id WHERE s.name=:status AND p.id = :parameter_id """ ).params(status=constants.MODEL_RUN_STATUS_CREATED, parameter_id=parameter_id).one() assert_that(row.value, is_(expected_parameter_value), "parameter value")
def assert_model_definition(self, expected_username, expected_science_configuration, expected_name, expected_description): """ Check that a model definition is correct in the database. Throws assertion error if there is no match Arguments: expected_name -- the expected name expected_science_configuration -- the expected science configuration id """ session = Session() row = session.query("username", "name", "science_configuration_id", "description").from_statement( """ SELECT u.username, m.name, m.science_configuration_id, m.description FROM model_runs m JOIN model_run_statuses s on s.id = m.status_id JOIN users u on u.id = m.user_id WHERE s.name=:status AND u.username = :username """ ).params(status=constants.MODEL_RUN_STATUS_CREATED, username=expected_username).one() assert_that(row.username, is_(expected_username), "username") assert_that(row.name, is_(expected_name), "model run name") assert_that(row.science_configuration_id, is_(expected_science_configuration), "science_configuration_id") assert_that(row.description, is_(expected_description), "description")