Skip to content

Commit

Permalink
Merge pull request #409 from macropin/joshblum/test-cmd
Browse files Browse the repository at this point in the history
use deleted_count in tests
  • Loading branch information
joshblum committed Feb 16, 2021
2 parents 426c808 + 49c241f commit d770e7f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions registration/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,8 @@ def test_expired_user_deletion_activation_window(self):
days=settings.ACCOUNT_ACTIVATION_DAYS + 1)
expired_user.save()

self.registration_profile.objects.delete_expired_users()
deleted_count = self.registration_profile.objects.delete_expired_users()
self.assertEqual(deleted_count, 1)
self.assertEqual(self.registration_profile.objects.count(), 1)
self.assertRaises(UserModel().DoesNotExist,
UserModel().objects.get, username='bob')
Expand All @@ -450,7 +451,8 @@ def test_expired_user_deletion_ignore_activated(self):
days=settings.ACCOUNT_ACTIVATION_DAYS + 1)
user.save()

self.registration_profile.objects.delete_expired_users()
deleted_count = self.registration_profile.objects.delete_expired_users()
self.assertEqual(deleted_count, 0)
self.assertEqual(self.registration_profile.objects.count(), 1)
self.assertEqual(UserModel().objects.get(username='bob'), user)

Expand All @@ -473,10 +475,12 @@ def test_expired_user_deletion_missing_user(self):
days=settings.ACCOUNT_ACTIVATION_DAYS + 1)
expired_user.save()
# Ensure that we cleanup the expired profile even if the user does not
# exist
expired_user.delete()
# exist. We simulate this with raw SQL, calling `expired_user.delete()`
# would result in the profile being deleted on cascade.
UserModel().objects.raw('DELETE FROM users WHERE username="bob"')

self.registration_profile.objects.delete_expired_users()
deleted_count = self.registration_profile.objects.delete_expired_users()
self.assertEqual(deleted_count, 1)
self.assertEqual(self.registration_profile.objects.count(), 1)
self.assertRaises(UserModel().DoesNotExist,
UserModel().objects.get, username='bob')
Expand All @@ -498,7 +502,8 @@ def test_manually_registered_account(self):
active_user.is_active = True
active_user.save()

self.registration_profile.objects.delete_expired_users()
deleted_count = self.registration_profile.objects.delete_expired_users()
self.assertEqual(deleted_count, 0)
self.assertEqual(self.registration_profile.objects.count(), 1)
self.assertEqual(UserModel().objects.get(username='bob'), active_user)

Expand Down

2 comments on commit d770e7f

@quroom
Copy link
Contributor

@quroom quroom commented on d770e7f Feb 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for that. you made it instaed of me.
I will make testcode too from now with PR.
Thanks.

@joshblum
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no problem, thanks for your help!

Please sign in to comment.