-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mark sounds as dirty when renaming users
- Loading branch information
Showing
2 changed files
with
19 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
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 |
---|---|---|
|
@@ -41,6 +41,7 @@ | |
from general.tasks import DELETE_USER_DELETE_SOUNDS_ACTION_NAME, DELETE_USER_KEEP_SOUNDS_ACTION_NAME | ||
from sounds.models import License, Sound, Pack, DeletedSound, Download, PackDownload | ||
from utils.mail import transform_unique_email | ||
from utils.test_helpers import create_user_and_sounds | ||
|
||
|
||
class UserRegistrationAndActivation(TestCase): | ||
|
@@ -883,6 +884,8 @@ def test_resend_activation_code_from_username(self): | |
|
||
class ChangeUsernameTest(TestCase): | ||
|
||
fixtures = ['licenses'] | ||
|
||
def test_change_username_creates_old_username(self): | ||
# Create user and check no OldUsername objects exist | ||
userA = User.objects.create_user('userA', email='[email protected]') | ||
|
@@ -972,6 +975,19 @@ def test_change_username_form_profile_page(self): | |
self.assertEqual(userA.username, 'userANewNewName') # ...username has not changed... | ||
self.assertEqual(OldUsername.objects.filter(user=userA).count(), 2) # ...and no new OldUsername objects created | ||
|
||
def test_change_username_mark_sounds_dirty(self): | ||
# Thest that changing username of a user that has sounds marks her sounds as dirty | ||
user, _, _ = create_user_and_sounds(num_sounds=3, num_packs=0) | ||
Sound.objects.filter(user=user).update(is_index_dirty=False) | ||
self.client.force_login(user) | ||
resp = self.client.post(reverse('accounts-edit'), data={'profile-username': ['userANewNewName'], 'profile-ui_theme_preference': 'f'}) | ||
self.assertRedirects(resp, reverse('accounts-edit')) | ||
user.refresh_from_db() | ||
self.assertEqual(user.username, 'userANewNewName') | ||
self.assertEqual(OldUsername.objects.filter(user=user).count(), 1) | ||
ss = Sound.objects.filter(user=user, is_index_dirty=True) | ||
self.assertEqual(ss.count(), 3) | ||
|
||
@override_settings(USERNAME_CHANGE_MAX_TIMES=2) | ||
def test_change_username_form_admin(self): | ||
User.objects.create_user('superuser', password='testpass', is_superuser=True, is_staff=True) | ||
|