add test, simpler kwargs for flash function signature
This commit is contained in:
parent
a2d6d59ca4
commit
1dd2cdd48b
@ -203,7 +203,7 @@ def financial_verification(request_id):
|
|||||||
).execute()
|
).execute()
|
||||||
|
|
||||||
if request.review_comment:
|
if request.review_comment:
|
||||||
flash("request_review_comment", {"comment": request.review_comment})
|
flash("request_review_comment", comment=request.review_comment)
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"requests/financial_verification.html",
|
"requests/financial_verification.html",
|
||||||
|
@ -102,6 +102,6 @@ def requests_index():
|
|||||||
context = RequestsIndex(g.current_user).execute()
|
context = RequestsIndex(g.current_user).execute()
|
||||||
|
|
||||||
if context.get("num_action_required"):
|
if context.get("num_action_required"):
|
||||||
flash("requests_action_required", {"count": context.get("num_action_required")})
|
flash("requests_action_required", count=context.get("num_action_required"))
|
||||||
|
|
||||||
return render_template("requests/index.html", **context)
|
return render_template("requests/index.html", **context)
|
||||||
|
@ -62,7 +62,7 @@ def requests_form_update(screen=1, request_id=None):
|
|||||||
flash("request_incomplete")
|
flash("request_incomplete")
|
||||||
|
|
||||||
if request.review_comment:
|
if request.review_comment:
|
||||||
flash("request_review_comment", {"comment": request.review_comment})
|
flash("request_review_comment", comment=request.review_comment)
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"requests/screen-%d.html" % int(screen),
|
"requests/screen-%d.html" % int(screen),
|
||||||
|
@ -41,5 +41,5 @@ def revoke_invitation(workspace_id, token):
|
|||||||
def resend_invitation(workspace_id, token):
|
def resend_invitation(workspace_id, token):
|
||||||
invite = Invitations.resend(g.current_user, workspace_id, token)
|
invite = Invitations.resend(g.current_user, workspace_id, token)
|
||||||
send_invite_email(g.current_user.full_name, invite.token, invite.email)
|
send_invite_email(g.current_user.full_name, invite.token, invite.email)
|
||||||
flash("resent_workspace_invitation", {"user_name": invite.user_name})
|
flash("resent_workspace_invitation", user_name=invite.user_name)
|
||||||
return redirect(url_for("workspaces.workspace_members", workspace_id=workspace_id))
|
return redirect(url_for("workspaces.workspace_members", workspace_id=workspace_id))
|
||||||
|
@ -76,10 +76,7 @@ def create_member(workspace_id):
|
|||||||
invite = Invitations.create(user, new_member, form.data["email"])
|
invite = Invitations.create(user, new_member, form.data["email"])
|
||||||
send_invite_email(g.current_user.full_name, invite.token, invite.email)
|
send_invite_email(g.current_user.full_name, invite.token, invite.email)
|
||||||
|
|
||||||
flash(
|
flash("new_workspace_member", new_member=new_member, workspace=workspace)
|
||||||
"new_workspace_member",
|
|
||||||
{"new_member": new_member, "workspace": workspace},
|
|
||||||
)
|
|
||||||
|
|
||||||
return redirect(
|
return redirect(
|
||||||
url_for("workspaces.workspace_members", workspace_id=workspace.id)
|
url_for("workspaces.workspace_members", workspace_id=workspace.id)
|
||||||
@ -162,7 +159,8 @@ def update_member(workspace_id, member_id):
|
|||||||
|
|
||||||
flash(
|
flash(
|
||||||
"workspace_role_updated",
|
"workspace_role_updated",
|
||||||
{"member_name": member.user_name, "updated_role": new_role_name},
|
member_name=member.user_name,
|
||||||
|
updated_role=new_role_name,
|
||||||
)
|
)
|
||||||
|
|
||||||
return redirect(
|
return redirect(
|
||||||
@ -182,5 +180,5 @@ def update_member(workspace_id, member_id):
|
|||||||
)
|
)
|
||||||
def revoke_access(workspace_id, member_id):
|
def revoke_access(workspace_id, member_id):
|
||||||
revoked_role = Workspaces.revoke_access(g.current_user, workspace_id, member_id)
|
revoked_role = Workspaces.revoke_access(g.current_user, workspace_id, member_id)
|
||||||
flash("revoked_workspace_access", {"member_name": revoked_role.user.full_name})
|
flash("revoked_workspace_access", member_name=revoked_role.user.full_name)
|
||||||
return redirect(url_for("workspaces.workspace_members", workspace_id=workspace_id))
|
return redirect(url_for("workspaces.workspace_members", workspace_id=workspace_id))
|
||||||
|
@ -99,9 +99,8 @@ MESSAGES = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def formatted_flash(message_name, message_args=None):
|
def formatted_flash(message_name, **message_args):
|
||||||
config = MESSAGES[message_name]
|
config = MESSAGES[message_name]
|
||||||
args = message_args or {}
|
title = render_template_string(config["title_template"], **message_args)
|
||||||
title = render_template_string(config["title_template"], **args)
|
message = render_template_string(config["message_template"], **message_args)
|
||||||
message = render_template_string(config["message_template"], **args)
|
|
||||||
flash({"title": title, "message": message}, config["category"])
|
flash({"title": title, "message": message}, config["category"])
|
||||||
|
10
tests/utils/test_flash.py
Normal file
10
tests/utils/test_flash.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
from atst.utils.flash import formatted_flash as flash
|
||||||
|
from flask import get_flashed_messages
|
||||||
|
|
||||||
|
|
||||||
|
def test_flash_message():
|
||||||
|
flash("revoked_workspace_access", member_name="Lando")
|
||||||
|
messages = get_flashed_messages()
|
||||||
|
message_info = messages[0]
|
||||||
|
assert "message" in message_info
|
||||||
|
assert "Lando" in message_info["message"]
|
Loading…
x
Reference in New Issue
Block a user