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.

55 lines
1.9 KiB

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