-
Notifications
You must be signed in to change notification settings - Fork 0
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
f89f5fc
commit ddabf34
Showing
3 changed files
with
88 additions
and
3 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Empty file.
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,88 @@ | ||
import unittest | ||
|
||
from django.test import TestCase | ||
|
||
from accounts.forms import CustomUserCreationForm | ||
|
||
|
||
class CustomUserCreationFormTest(TestCase): | ||
def setUp(self): | ||
self.username = "testuser" | ||
self.email = "[email protected]" | ||
self.first_name = "Test" | ||
self.last_name = "User" | ||
self.password1 = "sadilar2024" | ||
self.password2 = "sadilar2024" | ||
|
||
def test_valid_data(self): | ||
form = CustomUserCreationForm( | ||
{ | ||
"username": self.username, | ||
"email": self.email, | ||
"first_name": self.first_name, | ||
"last_name": self.last_name, | ||
"password1": self.password1, | ||
"password2": self.password2, | ||
} | ||
) | ||
|
||
self.assertTrue(form.is_valid()) | ||
|
||
def test_blank_data(self): | ||
form = CustomUserCreationForm({}) | ||
self.assertFalse(form.is_valid()) | ||
|
||
self.assertEqual( | ||
form.errors, | ||
{ | ||
"username": ["This field is required."], | ||
"email": ["This field is required."], | ||
"first_name": ["This field is required."], | ||
"last_name": ["This field is required."], | ||
"password1": ["This field is required."], | ||
"password2": ["This field is required."], | ||
}, | ||
) | ||
|
||
def test_invalid_email(self): | ||
form = CustomUserCreationForm( | ||
{ | ||
"username": self.username, | ||
"email": "not a valid email", | ||
"first_name": self.first_name, | ||
"last_name": self.last_name, | ||
"password1": self.password1, | ||
"password2": self.password2, | ||
} | ||
) | ||
self.assertFalse(form.is_valid()) | ||
self.assertEqual( | ||
form.errors, | ||
{ | ||
"email": ["Enter a valid email address."], | ||
}, | ||
) | ||
|
||
def test_passwords_do_not_match(self): | ||
form = CustomUserCreationForm( | ||
{ | ||
"username": self.username, | ||
"email": self.email, | ||
"first_name": self.first_name, | ||
"last_name": self.last_name, | ||
"password1": self.password1, | ||
"password2": "wrong password", | ||
} | ||
) | ||
|
||
self.assertFalse(form.is_valid()) | ||
self.assertEqual( | ||
form.errors, | ||
{ | ||
"password2": ["The two password fields didn’t match."], | ||
}, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |