-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Kipchirchir Sigei <arapgodsmack@gmail.com>
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 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,27 @@ | ||
from onadata.apps.main.admin import CustomUserChangeForm, CustomUserCreationForm | ||
from onadata.apps.main.tests.test_base import TestBase | ||
|
||
|
||
class TestUserValidation(TestBase): | ||
def test_custom_user_creation_form_invalid_username(self): | ||
# Try to create a user with a hyphenated username | ||
form_data = { | ||
"username": "john-doe", | ||
"password1": "testpassword", | ||
"password2": "testpassword", | ||
} | ||
form = CustomUserCreationForm(data=form_data) | ||
self.assertFalse(form.is_valid()) | ||
self.assertIn("username", form.errors) | ||
errors = form.errors.get("username")[0] | ||
self.assertEqual(str(errors), "Usernames cannot contain hyphens.") | ||
|
||
def test_custom_user_change_form_invalid_username(self): | ||
# Try to change a user's username to one with a hyphen | ||
user = self._create_user("bob-user", "bob") | ||
form_data = {"username": "bob-user-1"} | ||
form = CustomUserChangeForm(data=form_data, instance=user) | ||
self.assertFalse(form.is_valid()) | ||
self.assertIn("username", form.errors) | ||
errors = form.errors.get("username")[0] | ||
self.assertEqual(str(errors), "Usernames cannot contain hyphens.") |