Skip to content

Commit 836b0fb

Browse files
committed
Fix tests: Logout must now be a post not get request. Use mark_safe on SubmitButtonWidget.
1 parent 438ed1c commit 836b0fb

3 files changed

Lines changed: 15 additions & 12 deletions

File tree

hypha/apply/review/forms.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from django import forms
22
from django.core.exceptions import NON_FIELD_ERRORS
33
from django.utils.html import escape
4+
from django.utils.safestring import mark_safe
45

56
from hypha.apply.review.options import NA
67
from hypha.apply.stream_forms.forms import StreamBaseForm
@@ -113,10 +114,12 @@ def calculate_score(self, data):
113114
class SubmitButtonWidget(forms.Widget):
114115
def render(self, name, value, attrs=None, renderer=None):
115116
disabled = "disabled" if attrs.get("disabled") else ""
116-
return '<input type="submit" name="{name}" value="{value}" class="btn btn-primary" {disabled}>'.format(
117-
disabled=disabled,
118-
name=escape(name),
119-
value=escape(name.title()),
117+
return mark_safe(
118+
'<input type="submit" name="{name}" value="{value}" class="btn btn-primary" {disabled}>'.format(
119+
disabled=disabled,
120+
name=escape(name),
121+
value=escape(name.title()),
122+
)
120123
)
121124

122125

hypha/apply/users/tests/test_middleware.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,8 @@ def test_unverified_user_can_access_allowed_urls(self):
4141
if "success" in path:
4242
submission = ApplicationSubmissionFactory()
4343
path = str(path) + f"{submission.id}/"
44-
response = self.client.get(path, follow=True)
44+
if "logout" in path:
45+
response = self.client.post(path, follow=True)
46+
else:
47+
response = self.client.get(path, follow=True)
4548
self.assertEqual(response.status_code, 200)

hypha/templates/includes/user_menu.html

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,10 @@
8686
</form>
8787
{% endif %}
8888
<hr />
89-
<a
90-
href="{% url 'users:logout' %}"
91-
title="Log out"
92-
class="block py-2 px-3 font-semibold text-center transition-all hover:font-semibold text-error border-x hover:bg-error/10 focus-visible:outline-dashed"
93-
>
94-
{% trans "Log out" %}
95-
</a>
89+
<form id="logout-form" method="post" action="{% url 'users:logout' %}">
90+
{% csrf_token %}
91+
<button class="block py-2 px-3 w-full font-semibold text-center transition-all cursor-pointer hover:font-semibold text-error border-x hover:bg-error/10 focus-visible:outline-dashed" title="Log out" type="submit">{% trans "Log out" %}</button>
92+
</form>
9693
</div>
9794
</div>
9895
{% else %}

0 commit comments

Comments
 (0)