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.

39 lines
1.3 KiB

  1. from datetime import timedelta as td
  2. from django.core import signing
  3. from hc.test import BaseTestCase
  4. class UnsubscribeReportsTestCase(BaseTestCase):
  5. def test_token_works(self):
  6. self.profile.nag_period = td(hours=1)
  7. self.profile.save()
  8. token = signing.Signer().sign("foo")
  9. url = "/accounts/unsubscribe_reports/alice/?token=%s" % token
  10. r = self.client.get(url)
  11. self.assertContains(r, "You have been unsubscribed")
  12. self.profile.refresh_from_db()
  13. self.assertFalse(self.profile.reports_allowed)
  14. self.assertEqual(self.profile.nag_period.total_seconds(), 0)
  15. def test_bad_token_gets_rejected(self):
  16. url = "/accounts/unsubscribe_reports/alice/?token=invalid"
  17. r = self.client.get(url)
  18. self.assertContains(r, "Incorrect Link")
  19. def test_signed_username_works(self):
  20. sig = signing.TimestampSigner(salt="reports").sign("alice")
  21. url = "/accounts/unsubscribe_reports/%s/" % sig
  22. r = self.client.get(url)
  23. self.assertContains(r, "You have been unsubscribed")
  24. self.profile.refresh_from_db()
  25. self.assertFalse(self.profile.reports_allowed)
  26. def test_bad_signature_gets_rejected(self):
  27. url = "/accounts/unsubscribe_reports/invalid/"
  28. r = self.client.get(url)
  29. self.assertContains(r, "Incorrect Link")