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.

63 lines
2.2 KiB

  1. from hc.api.models import Channel
  2. from hc.test import BaseTestCase
  3. class UpdateChannelNameTestCase(BaseTestCase):
  4. def setUp(self):
  5. super().setUp()
  6. self.channel = Channel(kind="email", project=self.project)
  7. self.channel.save()
  8. self.url = "/integrations/%s/name/" % self.channel.code
  9. def test_it_works(self):
  10. payload = {"name": "My work email"}
  11. self.client.login(username="[email protected]", password="password")
  12. r = self.client.post(self.url, data=payload)
  13. self.assertRedirects(r, self.channels_url)
  14. self.channel.refresh_from_db()
  15. self.assertEqual(self.channel.name, "My work email")
  16. def test_team_access_works(self):
  17. payload = {"name": "Bob was here"}
  18. # Logging in as bob, not alice. Bob has team access so this
  19. # should work.
  20. self.client.login(username="[email protected]", password="password")
  21. self.client.post(self.url, data=payload)
  22. self.channel.refresh_from_db()
  23. self.assertEqual(self.channel.name, "Bob was here")
  24. def test_it_checks_ownership(self):
  25. payload = {"name": "Charlie Sent This"}
  26. self.client.login(username="[email protected]", password="password")
  27. r = self.client.post(self.url, data=payload)
  28. self.assertEqual(r.status_code, 404)
  29. def test_it_handles_missing_uuid(self):
  30. # Valid UUID but there is no check for it:
  31. url = "/integrations/6837d6ec-fc08-4da5-a67f-08a9ed1ccf62/name/"
  32. payload = {"name": "Alice Was Here"}
  33. self.client.login(username="[email protected]", password="password")
  34. r = self.client.post(url, data=payload)
  35. self.assertEqual(r.status_code, 404)
  36. def test_it_rejects_get(self):
  37. self.client.login(username="[email protected]", password="password")
  38. r = self.client.get(self.url)
  39. self.assertEqual(r.status_code, 405)
  40. def test_it_requires_rw_access(self):
  41. self.bobs_membership.role = "r"
  42. self.bobs_membership.save()
  43. payload = {"name": "My work email"}
  44. self.client.login(username="[email protected]", password="password")
  45. r = self.client.post(self.url, data=payload)
  46. self.assertEqual(r.status_code, 403)