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.

60 lines
2.1 KiB

  1. from datetime import timedelta as td
  2. from django.utils.timezone import now
  3. from hc.test import BaseTestCase
  4. class NotificationsTestCase(BaseTestCase):
  5. def test_it_saves_reports_allowed_true(self):
  6. self.profile.reports_allowed = False
  7. self.profile.save()
  8. self.client.login(username="[email protected]", password="password")
  9. form = {"reports_allowed": "on", "nag_period": "0"}
  10. r = self.client.post("/accounts/profile/notifications/", form)
  11. self.assertEqual(r.status_code, 200)
  12. self.profile.refresh_from_db()
  13. self.assertTrue(self.profile.reports_allowed)
  14. self.assertIsNotNone(self.profile.next_report_date)
  15. def test_it_saves_reports_allowed_false(self):
  16. self.profile.reports_allowed = True
  17. self.profile.next_report_date = now()
  18. self.profile.save()
  19. self.client.login(username="[email protected]", password="password")
  20. form = {"nag_period": "0"}
  21. r = self.client.post("/accounts/profile/notifications/", form)
  22. self.assertEqual(r.status_code, 200)
  23. self.profile.refresh_from_db()
  24. self.assertFalse(self.profile.reports_allowed)
  25. self.assertIsNone(self.profile.next_report_date)
  26. def test_it_saves_hourly_nag_period(self):
  27. self.client.login(username="[email protected]", password="password")
  28. form = {"nag_period": "3600"}
  29. r = self.client.post("/accounts/profile/notifications/", form)
  30. self.assertEqual(r.status_code, 200)
  31. self.profile.refresh_from_db()
  32. self.assertEqual(self.profile.nag_period.total_seconds(), 3600)
  33. self.assertIsNotNone(self.profile.next_nag_date)
  34. def test_it_does_not_save_nonstandard_nag_period(self):
  35. self.profile.nag_period = td(seconds=3600)
  36. self.profile.save()
  37. self.client.login(username="[email protected]", password="password")
  38. form = {"nag_period": "1234"}
  39. r = self.client.post("/accounts/profile/notifications/", form)
  40. self.assertEqual(r.status_code, 200)
  41. self.profile.refresh_from_db()
  42. self.assertEqual(self.profile.nag_period.total_seconds(), 3600)