test_cutoff_date.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from datetime import timedelta
  2. from unittest.mock import Mock
  3. from django.utils import timezone
  4. from ...conf.test import override_dynamic_settings
  5. from ..cutoffdate import get_cutoff_date
  6. def test_cutoff_date_for_no_user_is_calculated_from_setting(dynamic_settings):
  7. cutoff_date = get_cutoff_date(dynamic_settings)
  8. valid_cutoff_date = timezone.now() - timedelta(
  9. days=dynamic_settings.readtracker_cutoff
  10. )
  11. assert cutoff_date < valid_cutoff_date
  12. def test_cutoff_date_for_recently_joined_user_is_their_join_date(dynamic_settings):
  13. user = Mock(is_authenticated=True, joined_on=timezone.now())
  14. cutoff_date = get_cutoff_date(dynamic_settings, user)
  15. assert cutoff_date == user.joined_on
  16. @override_dynamic_settings(readtracker_cutoff=5)
  17. def test_cutoff_date_for_old_user_is_calculated_from_setting(dynamic_settings):
  18. user = Mock(is_authenticated=True, joined_on=timezone.now() - timedelta(days=6))
  19. cutoff_date = get_cutoff_date(dynamic_settings, user)
  20. valid_cutoff_date = timezone.now() - timedelta(
  21. days=dynamic_settings.readtracker_cutoff
  22. )
  23. assert cutoff_date < valid_cutoff_date
  24. assert cutoff_date > user.joined_on
  25. def test_cutoff_date_for_anonymous_user_is_calculated_from_setting(dynamic_settings):
  26. user = Mock(is_authenticated=False)
  27. cutoff_date = get_cutoff_date(dynamic_settings, user)
  28. valid_cutoff_date = timezone.now() - timedelta(
  29. days=dynamic_settings.readtracker_cutoff
  30. )
  31. assert cutoff_date < valid_cutoff_date