def update_environment(environment_id): environment = Environments.get(environment_id) application = environment.application env_form = EditEnvironmentForm(obj=environment, formdata=http_request.form) if env_form.validate(): Environments.update(environment=environment, name=env_form.name.data) flash("application_environments_updated") return redirect( url_for( "applications.settings", application_id=application.id, fragment="application-environments", _anchor="application-environments", active_toggler=environment.id, active_toggler_section="edit", )) else: return ( render_settings_page( application=application, active_toggler=environment.id, active_toggler_section="edit", ), 400, )
def handle_update_environment(form, application=None, environment=None): if form.validate(): try: if environment: environment = Environments.update(environment=environment, name=form.name.data) flash("application_environments_updated") else: environment = Environments.create(g.current_user, application=application, name=form.name.data) flash("environment_added", environment_name=form.name.data) return environment except AlreadyExistsError: flash("application_environments_name_error", name=form.name.data) return False else: return False
def test_update_environment(): environment = EnvironmentFactory.create() assert environment.name is not "name 2" Environments.update(environment, name="name 2") assert environment.name == "name 2"