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.

84 lines
3.1 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
9 years ago
  1. from hc.api.models import Check
  2. from hc.test import BaseTestCase
  3. class UpdateNameTestCase(BaseTestCase):
  4. def setUp(self):
  5. super().setUp()
  6. self.check = Check.objects.create(project=self.project)
  7. self.url = "/checks/%s/name/" % self.check.code
  8. self.redirect_url = "/projects/%s/checks/" % self.project.code
  9. def test_it_works(self):
  10. self.client.login(username="[email protected]", password="password")
  11. r = self.client.post(self.url, data={"name": "Alice Was Here"})
  12. self.assertRedirects(r, self.redirect_url)
  13. self.check.refresh_from_db()
  14. self.assertEqual(self.check.name, "Alice Was Here")
  15. self.assertEqual(self.check.slug, "alice-was-here")
  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.check.refresh_from_db()
  23. self.assertEqual(self.check.name, "Bob Was Here")
  24. def test_it_allows_cross_team_access(self):
  25. self.client.login(username="[email protected]", password="password")
  26. r = self.client.post(self.url, data={"name": "Bob Was Here"})
  27. self.assertRedirects(r, self.redirect_url)
  28. def test_it_checks_ownership(self):
  29. payload = {"name": "Charlie Sent This"}
  30. self.client.login(username="[email protected]", password="password")
  31. r = self.client.post(self.url, data=payload)
  32. self.assertEqual(r.status_code, 404)
  33. def test_it_requires_rw_access(self):
  34. self.bobs_membership.role = "r"
  35. self.bobs_membership.save()
  36. payload = {"name": "Charlie Sent This"}
  37. self.client.login(username="[email protected]", password="password")
  38. r = self.client.post(self.url, data=payload)
  39. self.assertEqual(r.status_code, 403)
  40. def test_it_handles_bad_uuid(self):
  41. url = "/checks/not-uuid/name/"
  42. payload = {"name": "Alice Was Here"}
  43. self.client.login(username="[email protected]", password="password")
  44. r = self.client.post(url, data=payload)
  45. self.assertEqual(r.status_code, 404)
  46. def test_it_handles_missing_uuid(self):
  47. # Valid UUID but there is no check for it:
  48. url = "/checks/6837d6ec-fc08-4da5-a67f-08a9ed1ccf62/name/"
  49. payload = {"name": "Alice Was Here"}
  50. self.client.login(username="[email protected]", password="password")
  51. r = self.client.post(url, data=payload)
  52. self.assertEqual(r.status_code, 404)
  53. def test_it_sanitizes_tags(self):
  54. payload = {"tags": " foo bar\r\t \n baz \n"}
  55. self.client.login(username="[email protected]", password="password")
  56. self.client.post(self.url, data=payload)
  57. self.check.refresh_from_db()
  58. self.assertEqual(self.check.tags, "foo bar baz")
  59. def test_it_rejects_get(self):
  60. self.client.login(username="[email protected]", password="password")
  61. r = self.client.get(self.url)
  62. self.assertEqual(r.status_code, 405)