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.

36 lines
1.2 KiB

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