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.

45 lines
1.5 KiB

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