def test_GIVEN_name_is_duplicate_WHEN_post_THEN_error_thrown(self):

        duplicate_name = u'duplicate name'
        user = self.login()
        model_run_service = ModelRunService()
        model_run_service.update_model_run(user, duplicate_name, constants.DEFAULT_SCIENCE_CONFIGURATION, "description which is unique")
        model_run = model_run_service.get_model_run_being_created_or_default(user)
        with model_run_service.transaction_scope() as session:
            model_run.change_status(session, constants.MODEL_RUN_STATUS_COMPLETED)

        response = self.app.post(
            url=url(controller='model_run', action='create'),
            params={
                'name': duplicate_name,
                'science_configuration': unicode(constants.DEFAULT_SCIENCE_CONFIGURATION),
                'description': u'a description'
            }
        )

        assert_that(response.normal_body, contains_string("Name can not be the same as another model run"))
    def test_GIVEN_name_is_duplicate_but_run_is_owned_by_another_user_WHEN_post_THEN_success(self):

        duplicate_name = u'duplicate name'
        user = self.login("test_different")
        model_run_service = ModelRunService()
        model_run_service.update_model_run(user, duplicate_name, constants.DEFAULT_SCIENCE_CONFIGURATION, "description which is unique")
        model_run = model_run_service.get_model_run_being_created_or_default(user)
        with model_run_service.transaction_scope() as session:
            model_run.change_status(session, constants.MODEL_RUN_STATUS_COMPLETED)

        user = self.login("test")
        response = self.app.post(
            url=url(controller='model_run', action='create'),
            params={
                'name': duplicate_name,
                'science_configuration': unicode(constants.DEFAULT_SCIENCE_CONFIGURATION),
                'description': u'a description'
            }
        )

        assert_that(response.status_code, is_(302), "Response is redirect")
        assert_that(urlparse(response.response.location).path, is_(url(controller='model_run', action='driving_data')), "url")
Esempio n. 3
0
    def create_run_model(self, storage_in_mb, name, user, status=constants.MODEL_RUN_STATUS_COMPLETED):
        """
        Create a model run
        :param storage_in_mb: storage_in_mb for the model
        :param name: name of the model run
        :param user: user who has created the model run
        :param status: the status, default to complete
        :return:the model run
        """
        model_run_service = ModelRunService()
        with model_run_service.transaction_scope() as session:
            model_run = model_run_service._create_new_model_run(session, user)
            session.add(model_run)
            model_run.name = name
            science_configuration = model_run_service._get_science_configuration(
                constants.DEFAULT_SCIENCE_CONFIGURATION, session)
            model_run.science_configuration_id = science_configuration.id
            model_run.code_version = science_configuration.code_version
            model_run.description = "testing"
            model_run_service._copy_parameter_set_into_model(science_configuration.parameter_values, model_run, session)
            model_run.storage_in_mb = storage_in_mb
            model_run.change_status(session, status)

        return model_run