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.

43 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 AddPdConnectTestCase(BaseTestCase):
  6. url = "/integrations/add_pdc/"
  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 = self.url + "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. self.assertEqual(c.project, self.project)
  23. def test_it_validates_code(self):
  24. session = self.client.session
  25. session["pd"] = "1234567890AB" # 12 characters
  26. session.save()
  27. self.client.login(username="[email protected]", password="password")
  28. url = self.url + "XXXXXXXXXXXX/?service_key=123"
  29. r = self.client.get(url)
  30. self.assertEqual(r.status_code, 400)
  31. @override_settings(PD_VENDOR_KEY=None)
  32. def test_it_requires_vendor_key(self):
  33. r = self.client.get(self.url)
  34. self.assertEqual(r.status_code, 404)