This repository was archived by the owner on Aug 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
792440d
commit 7ac0fb2
Showing
7 changed files
with
99 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -307,6 +307,8 @@ def setUp(self): | |
self.url = reverse('accounts:signup') | ||
self.response = self.client.get(self.url) | ||
|
||
|
||
|
||
def test_csrf(self): | ||
"""Test for csrf token.""" | ||
self.assertContains(self.response, 'csrfmiddlewaretoken') | ||
|
@@ -324,3 +326,73 @@ def test_signup_view_is_rendered(self): | |
"""Tests if `accounts/signup.html` and `base.html` is used.""" | ||
self.assertTemplateUsed(self.response, 'accounts/signup.html') | ||
self.assertTemplateUsed(self.response, 'base.html') | ||
|
||
# unable to link, need assistance | ||
def test_contains_login_link(self): | ||
"""Test if it contains `signup` link.""" | ||
url = reverse('accounts:login') | ||
self.assertContains(self.response, f'href="{url}"') | ||
|
||
|
||
def test_form_inputs(self): | ||
"""The view must contain three inputs: csrf, username, first_name, last_name | ||
email, password1, password2""" | ||
self.assertContains(self.response, '<input', 7) | ||
self.assertContains(self.response, 'type="text"', 4) | ||
self.assertContains(self.response, 'type="password"', 2) | ||
|
||
|
||
|
||
|
||
class SignupPostTest(TestCase): | ||
"""Tests the login `POST` requests.""" | ||
|
||
def setUp(self): | ||
"""Set ups the user and url for this test.""" | ||
self.url = reverse('accounts:signup') | ||
|
||
def test_successfull_post_signup(self): | ||
data = { | ||
'username': 'testusername', | ||
'first_name': 'testfirstname', | ||
'last_name': 'testlastname', | ||
'email': '[email protected]', | ||
'password1': 'testpassword', | ||
'password2': 'testpassword', | ||
|
||
} | ||
|
||
response = self.client.post(self.url, data) | ||
|
||
user = User.objects.get(username = data['username']) | ||
self.assertEqual(user.first_name, data['first_name']) | ||
self.assertEqual(user.last_name, data['last_name']) | ||
self.assertEqual(user.email, data['email']) | ||
self.assertFalse(user.is_active) | ||
self.assertTrue(user) | ||
|
||
self.assertTemplateUsed(response, 'accounts/email_sent.html') | ||
self.assertTemplateUsed(response, 'base.html') | ||
self.assertEqual(response.status_code, 200) | ||
|
||
def test_password_mismatch(self): | ||
|
||
data = { | ||
'username': 'testusername1', | ||
'first_name': 'testfirstname', | ||
'last_name': 'testlastname', | ||
'email': '[email protected]', | ||
'password1': 'testpassword', | ||
'password2': 'testpassword1', | ||
|
||
} | ||
|
||
response = self.client.post(reverse('accounts:signup'), data) | ||
|
||
error_messages = ["The two password fields didn't match."] | ||
self.assertFormError(response, 'form', 'password1', error_messages) | ||
self.assertFalse(User.objects.exists(username = data['username'])) | ||
|
||
self.assertTemplateUsed(response, 'accounts/signup.html') | ||
self.assertTemplateUsed(response, 'base.html') | ||
self.assertEqual(response.status_code, 200) |
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