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.

49 lines
1.7 KiB

  1. from django.test.utils import override_settings
  2. from hc.api.models import Channel
  3. from hc.test import BaseTestCase
  4. class AddPdTestCase(BaseTestCase):
  5. def setUp(self):
  6. super().setUp()
  7. self.url = "/projects/%s/add_pd/" % self.project.code
  8. def test_instructions_work(self):
  9. self.client.login(username="[email protected]", password="password")
  10. r = self.client.get(self.url)
  11. self.assertContains(r, "Paste the Integration Key down below")
  12. def test_it_works(self):
  13. # Integration key is 32 characters long
  14. form = {"value": "12345678901234567890123456789012"}
  15. self.client.login(username="[email protected]", password="password")
  16. r = self.client.post(self.url, form)
  17. self.assertRedirects(r, self.channels_url)
  18. c = Channel.objects.get()
  19. self.assertEqual(c.kind, "pd")
  20. self.assertEqual(c.value, "12345678901234567890123456789012")
  21. def test_it_trims_whitespace(self):
  22. form = {"value": " 123456 "}
  23. self.client.login(username="[email protected]", password="password")
  24. self.client.post(self.url, form)
  25. c = Channel.objects.get()
  26. self.assertEqual(c.value, "123456")
  27. def test_it_requires_rw_access(self):
  28. self.bobs_membership.rw = False
  29. self.bobs_membership.save()
  30. self.client.login(username="[email protected]", password="password")
  31. r = self.client.get(self.url)
  32. self.assertEqual(r.status_code, 403)
  33. @override_settings(PD_ENABLED=False)
  34. def test_it_handles_disabled_integration(self):
  35. self.client.login(username="[email protected]", password="password")
  36. r = self.client.get(self.url)
  37. self.assertEqual(r.status_code, 404)