-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added password change views and basic tests. (#363)
- Loading branch information
1 parent
225aaaf
commit dfffba2
Showing
7 changed files
with
149 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from __future__ import annotations | ||
|
||
from django.core import mail | ||
from django.test import Client | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
|
||
from home.factories import UserFactory | ||
|
||
|
||
class AuthViewTests(TestCase): | ||
"""As we have only overridden the templates, these tests will check the views | ||
render without error with our templates but no other functionality will be tested. | ||
""" | ||
|
||
@classmethod | ||
def setUpTestData(cls): | ||
cls.user = UserFactory.create() | ||
|
||
def setUp(self): | ||
self.client = Client() | ||
|
||
def test_password_change_form(self): | ||
self.client.force_login(self.user) | ||
response = self.client.get(reverse("password_change")) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertContains(response, "Djangonaut Space") | ||
self.assertContains(response, "Update password") | ||
|
||
def test_password_change_done(self): | ||
self.client.force_login(self.user) | ||
response = self.client.get(reverse("password_change_done")) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertContains(response, "Djangonaut Space") | ||
self.assertContains(response, "Your password has been updated successfully!") | ||
|
||
def test_password_reset_form(self): | ||
response = self.client.get(reverse("password_reset")) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertContains(response, "Djangonaut Space") | ||
self.assertContains(response, "Forgotten your password?") | ||
|
||
def test_password_reset_confirm(self): | ||
response = self.client.post( | ||
reverse("password_reset"), {"email": "[email protected]"} | ||
) | ||
self.assertEqual(response.status_code, 302) | ||
self.assertEqual(len(mail.outbox), 1) | ||
token = response.context[0]["token"] | ||
uid = response.context[0]["uid"] | ||
reset_confirm_url = reverse( | ||
"password_reset_confirm", kwargs={"token": token, "uidb64": uid} | ||
) | ||
response = self.client.get(reset_confirm_url, follow=True) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertContains(response, "Djangonaut Space") | ||
self.assertContains(response, "Reset password") | ||
self.assertContains(response, "Change password") | ||
|
||
def test_password_reset_done(self): | ||
response = self.client.get(reverse("password_reset_done")) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertContains(response, "Djangonaut Space") | ||
self.assertContains( | ||
response, | ||
"emailed you instructions for setting your password, if an account exists " | ||
"with the email you entered. You should receive them shortly.", | ||
) | ||
|
||
def test_password_reset_complete(self): | ||
response = self.client.get(reverse("password_reset_complete")) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertContains(response, "Djangonaut Space") | ||
self.assertContains( | ||
response, "Your password has been set. You may go ahead and log in now." | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{% extends "base.html" %} | ||
{% load i18n wagtailcore_tags static %} | ||
|
||
{% block title %}{% translate "Password update success | Djangonaut Space" %}{% endblock %} | ||
{% block meta_title %}{% translate "Password update success | Djangonaut Space" %}{% endblock %} | ||
|
||
|
||
{% block extra_css %} | ||
<link rel="stylesheet" href="{% static 'css/registration.css' %}"> | ||
{% endblock extra_css %} | ||
|
||
{% block content %} | ||
<main class="section my-3 mx-5"> | ||
<div class="section-container"> | ||
<div class="row pt-4 pb-4"> | ||
<div class="col"> | ||
<p>{% translate "Your password has been updated successfully!" %}</p> | ||
</div> | ||
</div> | ||
</div> | ||
</main> | ||
{% endblock content %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{% extends "base.html" %} | ||
{% load i18n wagtailcore_tags static %} | ||
|
||
{% block title %}{% translate "Password update | Djangonaut Space" %}{% endblock %} | ||
{% block meta_title %}{% translate "Password update | Djangonaut Space" %}{% endblock %} | ||
|
||
|
||
{% block extra_css %} | ||
<link rel="stylesheet" href="{% static 'css/registration.css' %}"> | ||
{% endblock extra_css %} | ||
|
||
{% block content %} | ||
<main class="section my-3 mx-5"> | ||
<div class="section-container"> | ||
<h1 class="text-5xl mb-6">{% translate "Update password" %}</h1> | ||
<div class="row"> | ||
<div class="col"> | ||
<form method="post"> | ||
{% csrf_token %} | ||
{{ form }} | ||
<button type="submit">{% translate "Update password" %}</button> | ||
</form> | ||
</div> | ||
<div class="col"></div> | ||
</div> | ||
</div> | ||
</main> | ||
{% endblock content %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{% extends "emails/base.html" %} | ||
{% block preheader %}Djangonaut Space - Password Reset{% endblock preheader %} | ||
{% block before_cta %} | ||
<p style="font-family: Helvetica, sans-serif; font-size: 16px; font-weight: normal; margin: 0; margin-bottom: 16px;"> | ||
You're receiving this email because you requested a password reset for your user account at {{ site_name }}. | ||
</p> | ||
<p style="font-family: Helvetica, sans-serif; font-size: 16px; font-weight: normal; margin: 0; margin-bottom: 16px;"> | ||
Your username, in case you’ve forgotten: {{ user.get_username }} | ||
</p> | ||
{% endblock before_cta %} | ||
{% block cta_button %}<a href="{{ protocol }}://{{ domain }}/reset/{{ uid }}/{{ token }}/" target="_blank" style="border: solid 2px #5c0287; border-radius: 4px; box-sizing: border-box; cursor: pointer; display: inline-block; font-size: 16px; font-weight: bold; margin: 0; padding: 12px 24px; text-decoration: none; text-transform: capitalize; background-color: #5c0287; border-color: #5c0287; color: #ffffff;">Reset Password</a>{% endblock cta_button %} |