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.

35 lines
1.1 KiB

6 years ago
6 years ago
  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.accounts.models import Project
  6. from hc.api.models import Check
  7. from hc.test import BaseTestCase
  8. class PruneUsersTestCase(BaseTestCase):
  9. year_ago = timezone.now() - timedelta(days=365)
  10. def test_it_removes_old_never_logged_in_users(self):
  11. self.charlie.date_joined = self.year_ago
  12. self.charlie.save()
  13. # Charlie has one demo check
  14. project =Project.objects.create(owner=self.charlie)
  15. Check(user=self.charlie, project=project).save()
  16. Command().handle()
  17. self.assertEqual(User.objects.filter(username="charlie").count(), 0)
  18. self.assertEqual(Check.objects.count(), 0)
  19. def test_it_leaves_team_members_alone(self):
  20. self.bob.date_joined = self.year_ago
  21. self.bob.last_login = self.year_ago
  22. self.bob.save()
  23. Command().handle()
  24. # Bob belongs to a team so should not get removed
  25. self.assertEqual(User.objects.filter(username="bob").count(), 1)