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.

32 lines
1.0 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, "You have been 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")