You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.0 KiB

  1. from datetime import timedelta
  2. from django.contrib.auth.models import User
  3. from django.utils import timezone
  4. from hc.accounts.management.commands.pruneusers import Command
  5. from hc.api.models import Check
  6. from hc.test import BaseTestCase
  7. class PruneUsersTestCase(BaseTestCase):
  8. year_ago = timezone.now() - timedelta(days=365)
  9. def test_it_removes_old_never_logged_in_users(self):
  10. self.charlie.date_joined = self.year_ago
  11. self.charlie.save()
  12. # Charlie has one demo check
  13. Check(user=self.charlie).save()
  14. Command().handle()
  15. self.assertEqual(User.objects.filter(username="charlie").count(), 0)
  16. self.assertEqual(Check.objects.count(), 0)
  17. def test_it_leaves_team_members_alone(self):
  18. self.bob.date_joined = self.year_ago
  19. self.bob.last_login = self.year_ago
  20. self.bob.save()
  21. Command().handle()
  22. # Bob belongs to a team so should not get removed
  23. self.assertEqual(User.objects.filter(username="bob").count(), 1)