Skip to content

Commit

Permalink
Add unit test for allowing inactive users to do password reset
Browse files Browse the repository at this point in the history
  • Loading branch information
rstorey committed Oct 17, 2019
1 parent ecfcf9e commit 911c3bf
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
27 changes: 27 additions & 0 deletions concordia/tests/test_registration_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Tests for user registration-related views
"""
from django.core import mail
from django.test import TestCase, override_settings
from django.urls import reverse

from .utils import CacheControlAssertions, CreateTestUsers, JSONAssertMixin


@override_settings(RATELIMIT_ENABLE=False)
class ConcordiaViewTests(
JSONAssertMixin, CacheControlAssertions, TestCase, CreateTestUsers
):
def test_inactiveUserCanPasswordReset(self):
"""
Test the ability to activate a user account based on password reset
"""
self.user = self.create_inactive_user("tester")

self.client.post(reverse("password_reset"), {"email": self.user.email})

self.assertEqual(len(mail.outbox), 1)


# def test_userActivationViaEmailConfirmation(self):
# self.user = self.create_inactive_user("tester")
19 changes: 14 additions & 5 deletions concordia/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,23 +174,32 @@ def login_user(self):

self.client.login(username=self.user.username, password=self.user.password)

def create_test_user(self, username, **kwargs):
"""
Creates a test User account
"""

def create_user(self, username, is_active=True, **kwargs):
if "email" not in kwargs:
kwargs["email"] = f"{username}@example.com"

user = User.objects.create_user(username=username, **kwargs)
fake_pw = token_hex(24)
user.is_active = is_active
user.set_password(fake_pw)
user.save()

user.password = fake_pw

return user

def create_test_user(self, username, **kwargs):
"""
Creates an activated test User account
"""
return self.create_user(username, is_active=True, **kwargs)

def create_inactive_user(self, username, **kwargs):
"""
Creates an inactive test User account
"""
return self.create_user(username, is_active=False, **kwargs)


class CacheControlAssertions(object):
def assertUncacheable(self, response):
Expand Down

0 comments on commit 911c3bf

Please sign in to comment.