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.

42 lines
1.5 KiB

  1. from django.test.utils import override_settings
  2. from hc.api.models import Channel
  3. from hc.test import BaseTestCase
  4. @override_settings(PD_VENDOR_KEY="foo")
  5. class AddPdTestCase(BaseTestCase):
  6. url = "/integrations/add_pd/"
  7. def test_instructions_work(self):
  8. self.client.login(username="[email protected]", password="password")
  9. r = self.client.get(self.url)
  10. self.assertContains(r, "If your team uses")
  11. def test_it_works(self):
  12. session = self.client.session
  13. session["pd"] = "1234567890AB" # 12 characters
  14. session.save()
  15. self.client.login(username="[email protected]", password="password")
  16. url = "/integrations/add_pd/1234567890AB/?service_key=123"
  17. r = self.client.get(url)
  18. self.assertEqual(r.status_code, 302)
  19. c = Channel.objects.get()
  20. self.assertEqual(c.kind, "pd")
  21. self.assertEqual(c.pd_service_key, "123")
  22. def test_it_validates_code(self):
  23. session = self.client.session
  24. session["pd"] = "1234567890AB" # 12 characters
  25. session.save()
  26. self.client.login(username="[email protected]", password="password")
  27. url = "/integrations/add_pd/XXXXXXXXXXXX/?service_key=123"
  28. r = self.client.get(url)
  29. self.assertEqual(r.status_code, 400)
  30. @override_settings(PD_VENDOR_KEY=None)
  31. def test_it_requires_vendor_key(self):
  32. r = self.client.get("/integrations/add_pd/")
  33. self.assertEqual(r.status_code, 404)