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.

83 lines
3.0 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. def test_team_access_works(self):
  16. payload = {"name": "Bob Was Here"}
  17. # Logging in as bob, not alice. Bob has team access so this
  18. # should work.
  19. self.client.login(username="[email protected]", password="password")
  20. self.client.post(self.url, data=payload)
  21. self.check.refresh_from_db()
  22. self.assertEqual(self.check.name, "Bob Was Here")
  23. def test_it_allows_cross_team_access(self):
  24. self.client.login(username="[email protected]", password="password")
  25. r = self.client.post(self.url, data={"name": "Bob Was Here"})
  26. self.assertRedirects(r, self.redirect_url)
  27. def test_it_checks_ownership(self):
  28. payload = {"name": "Charlie Sent This"}
  29. self.client.login(username="[email protected]", password="password")
  30. r = self.client.post(self.url, data=payload)
  31. self.assertEqual(r.status_code, 404)
  32. def test_it_requires_rw_access(self):
  33. self.bobs_membership.role = "r"
  34. self.bobs_membership.save()
  35. payload = {"name": "Charlie Sent This"}
  36. self.client.login(username="[email protected]", password="password")
  37. r = self.client.post(self.url, data=payload)
  38. self.assertEqual(r.status_code, 403)
  39. def test_it_handles_bad_uuid(self):
  40. url = "/checks/not-uuid/name/"
  41. payload = {"name": "Alice Was Here"}
  42. self.client.login(username="[email protected]", password="password")
  43. r = self.client.post(url, data=payload)
  44. self.assertEqual(r.status_code, 404)
  45. def test_it_handles_missing_uuid(self):
  46. # Valid UUID but there is no check for it:
  47. url = "/checks/6837d6ec-fc08-4da5-a67f-08a9ed1ccf62/name/"
  48. payload = {"name": "Alice Was Here"}
  49. self.client.login(username="[email protected]", password="password")
  50. r = self.client.post(url, data=payload)
  51. self.assertEqual(r.status_code, 404)
  52. def test_it_sanitizes_tags(self):
  53. payload = {"tags": " foo bar\r\t \n baz \n"}
  54. self.client.login(username="[email protected]", password="password")
  55. self.client.post(self.url, data=payload)
  56. self.check.refresh_from_db()
  57. self.assertEqual(self.check.tags, "foo bar baz")
  58. def test_it_rejects_get(self):
  59. self.client.login(username="[email protected]", password="password")
  60. r = self.client.get(self.url)
  61. self.assertEqual(r.status_code, 405)