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.

53 lines
1.8 KiB

  1. from datetime import timedelta as td
  2. import time
  3. from django.core import signing
  4. from django.utils.timezone import now
  5. from hc.test import BaseTestCase
  6. from mock import patch
  7. class UnsubscribeReportsTestCase(BaseTestCase):
  8. def test_it_unsubscribes(self):
  9. self.profile.next_report_date = now()
  10. self.profile.nag_period = td(hours=1)
  11. self.profile.next_nag_date = now()
  12. self.profile.save()
  13. sig = signing.TimestampSigner(salt="reports").sign("alice")
  14. url = "/accounts/unsubscribe_reports/%s/" % sig
  15. r = self.client.post(url)
  16. self.assertContains(r, "Unsubscribed")
  17. self.profile.refresh_from_db()
  18. self.assertFalse(self.profile.reports_allowed)
  19. self.assertIsNone(self.profile.next_report_date)
  20. self.assertEqual(self.profile.nag_period.total_seconds(), 0)
  21. self.assertIsNone(self.profile.next_nag_date)
  22. def test_bad_signature_gets_rejected(self):
  23. url = "/accounts/unsubscribe_reports/invalid/"
  24. r = self.client.get(url)
  25. self.assertContains(r, "Incorrect Link")
  26. def test_it_serves_confirmation_form(self):
  27. sig = signing.TimestampSigner(salt="reports").sign("alice")
  28. url = "/accounts/unsubscribe_reports/%s/" % sig
  29. r = self.client.get(url)
  30. self.assertContains(r, "Please press the button below")
  31. self.assertNotContains(r, "submit()")
  32. def test_aged_signature_autosubmits(self):
  33. with patch("django.core.signing.time") as mock_time:
  34. mock_time.time.return_value = time.time() - 301
  35. signer = signing.TimestampSigner(salt="reports")
  36. sig = signer.sign("alice")
  37. url = "/accounts/unsubscribe_reports/%s/" % sig
  38. r = self.client.get(url)
  39. self.assertContains(r, "Please press the button below")
  40. self.assertContains(r, "submit()")