-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing test case: assertFormError has changed in Django 4.1 and so ol…
…der versions of Django won't support the form I'm using in the tests.
- Loading branch information
Showing
1 changed file
with
32 additions
and
25 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import django | ||
from django.contrib.auth import get_user, get_user_model | ||
from django.contrib.auth.tokens import default_token_generator | ||
from django.core import mail | ||
|
@@ -82,26 +83,29 @@ def test_account(self): | |
|
||
self.client.logout() | ||
|
||
# Create another account with the same user name | ||
settings.ACCOUNTS_VERIFICATION_REQUIRED = False | ||
data = self.account_data("test1") | ||
form = ProfileForm(data=data) | ||
self.assertFormError(form, 'username', 'This username is already registered') | ||
if django.VERSION[0:1] >= (4, 1): | ||
# This form of assertFormError is only available since Django 4.1 | ||
|
||
# Create another account with the same user name, but case is different | ||
data['username'] = 'TEST1' | ||
form = ProfileForm(data=data) | ||
self.assertFormError(form, 'username', 'This username is already registered') | ||
# Create another account with the same user name | ||
settings.ACCOUNTS_VERIFICATION_REQUIRED = False | ||
data = self.account_data("test1") | ||
form = ProfileForm(data=data) | ||
self.assertFormError(form, 'username', 'This username is already registered') | ||
|
||
# Create another account with a different username, but same email | ||
data['username'] = 'test3' | ||
form = ProfileForm(data=data) | ||
self.assertFormError(form, 'email', 'This email is already registered') | ||
# Create another account with the same user name, but case is different | ||
data['username'] = 'TEST1' | ||
form = ProfileForm(data=data) | ||
self.assertFormError(form, 'username', 'This username is already registered') | ||
|
||
# Create another account with a different username, but same email with different case | ||
data['email'] = '[email protected]' | ||
form = ProfileForm(data=data) | ||
self.assertFormError(form, 'email', 'This email is already registered') | ||
# Create another account with a different username, but same email | ||
data['username'] = 'test3' | ||
form = ProfileForm(data=data) | ||
self.assertFormError(form, 'email', 'This email is already registered') | ||
|
||
# Create another account with a different username, but same email with different case | ||
data['email'] = '[email protected]' | ||
form = ProfileForm(data=data) | ||
self.assertFormError(form, 'email', 'This email is already registered') | ||
|
||
|
||
def test_account_login(self): | ||
|
@@ -222,12 +226,15 @@ def test_account_password_reset(self): | |
self._verify_password_reset_email(new_user, emails) | ||
self.client.logout() | ||
|
||
# Reset password with invalid username | ||
rdata = {'username': 'badusername'} | ||
form = PasswordResetForm(data=rdata) | ||
self.assertFormError(form, None, 'Invalid username/email') | ||
if django.VERSION[0:1] >= (4, 1): | ||
# This form of assertFormError is only available since Django 4.1 | ||
|
||
# Reset password with invalid username | ||
rdata = {'username': 'badusername'} | ||
form = PasswordResetForm(data=rdata) | ||
self.assertFormError(form, None, 'Invalid username/email') | ||
|
||
# Reset password with invalid email | ||
rdata = {'username': '[email protected]'} | ||
form = PasswordResetForm(data=rdata) | ||
self.assertFormError(form, None, 'Invalid username/email') | ||
# Reset password with invalid email | ||
rdata = {'username': '[email protected]'} | ||
form = PasswordResetForm(data=rdata) | ||
self.assertFormError(form, None, 'Invalid username/email') |