-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1804 from MTG/issue1516
Profile updates enabled for antique usernames containing spaces
- Loading branch information
Showing
2 changed files
with
44 additions
and
2 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
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 |
---|---|---|
|
@@ -1085,7 +1085,30 @@ def test_oldusername_username_unique_case_insensitiveness(self): | |
OldUsername.objects.create(user=userA, username='newUserAUsername') | ||
with self.assertRaises(IntegrityError): | ||
OldUsername.objects.create(user=userA, username='NewUserAUsername') | ||
|
||
def test_username_whitespace(self): | ||
"""Test that for usernames created before stronger validation was applied, whitespaces are a valid character | ||
but for new edited ones they are not.""" | ||
userA = User.objects.create_user('user A', email='[email protected]', password='testpass') | ||
self.client.force_login(userA) | ||
|
||
# Test save profile without changing username with whitespaces | ||
resp = self.client.post(reverse('accounts-edit'), data={'profile-username': ['user A'], 'profile-ui_theme_preference': 'f'}) | ||
self.assertRedirects(resp, reverse('accounts-edit')) | ||
self.assertEqual(OldUsername.objects.filter(user=userA).count(), 0) | ||
|
||
# Test save profile changing username (no whitespaces) | ||
resp = self.client.post(reverse('accounts-edit'), data={'profile-username': ['userANewName'], 'profile-ui_theme_preference': 'f'}) | ||
self.assertRedirects(resp, reverse('accounts-edit')) | ||
userA.refresh_from_db() | ||
self.assertEqual(OldUsername.objects.filter(user=userA).count(), 1) | ||
|
||
# Test save profile changing username (whitespaces -> fail) | ||
resp = self.client.post(reverse('accounts-edit'), data={'profile-username': ['userA SpaceName'], 'profile-ui_theme_preference': 'f'}) | ||
self.assertEqual(resp.status_code, 200) | ||
userA.refresh_from_db() | ||
self.assertEqual(userA.username, 'userANewName') | ||
self.assertEqual(OldUsername.objects.filter(user=userA).count(), 1) | ||
|
||
class ChangeEmailViaAdminTestCase(TestCase): | ||
|
||
|