def update_template(service_id, template_id): try: service = get_model_services(service_id=service_id) except DataError: return jsonify(result="error", message="Invalid service id"), 400 except NoResultFound: return jsonify(result="error", message="Service not found"), 404 try: template = get_model_templates(template_id=template_id) except DataError: return jsonify(result="error", message="Invalid template id"), 400 except NoResultFound: return jsonify(result="error", message="Template not found"), 404 if request.method == 'DELETE': status_code = 202 delete_model_template(template) else: status_code = 200 # TODO there has got to be a better way to do the next three lines upd_temp, errors = template_schema.load(request.get_json()) if errors: return jsonify(result="error", message=errors), 400 upd_temp.service = service update_dict, errors = template_schema.dump(upd_temp) # TODO FIX ME # Remove update_temp model which is added to db.session db.session.rollback() try: save_model_template(template, update_dict=update_dict) except DAOException as e: return jsonify(result="error", message=str(e)), 400 return jsonify(data=template_schema.dump(template).data), status_code
def test_delete_template(notify_api, notify_db, notify_db_session, sample_template): assert Template.query.count() == 1 delete_model_template(sample_template) assert Template.query.count() == 0