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.

40 lines
1.4 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. def setUp(self):
  7. super(AddPdConnectTestCase, self).setUp()
  8. self.url = "/projects/%s/add_pdc/" % self.project.code
  9. def test_it_works(self):
  10. session = self.client.session
  11. session["pd"] = "1234567890AB" # 12 characters
  12. session.save()
  13. self.client.login(username="[email protected]", password="password")
  14. url = self.url + "1234567890AB/?service_key=123"
  15. r = self.client.get(url, follow=True)
  16. self.assertRedirects(r, self.channels_url)
  17. c = Channel.objects.get()
  18. self.assertEqual(c.kind, "pd")
  19. self.assertEqual(c.pd_service_key, "123")
  20. self.assertEqual(c.project, self.project)
  21. @override_settings(PD_VENDOR_KEY=None)
  22. def test_it_requires_vendor_key(self):
  23. self.client.login(username="[email protected]", password="password")
  24. r = self.client.get(self.url)
  25. self.assertEqual(r.status_code, 404)
  26. def test_it_requires_rw_access(self):
  27. self.bobs_membership.rw = False
  28. self.bobs_membership.save()
  29. self.client.login(username="[email protected]", password="password")
  30. r = self.client.get(self.url)
  31. self.assertEqual(r.status_code, 403)