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.

74 lines
2.6 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(UpdateNameTestCase, self).setUp()
  6. self.check = Check(user=self.alice)
  7. self.check.save()
  8. def test_it_works(self):
  9. url = "/checks/%s/name/" % self.check.code
  10. payload = {"name": "Alice Was Here"}
  11. self.client.login(username="[email protected]", password="password")
  12. r = self.client.post(url, data=payload)
  13. self.assertRedirects(r, "/checks/")
  14. check = Check.objects.get(code=self.check.code)
  15. assert check.name == "Alice Was Here"
  16. def test_team_access_works(self):
  17. url = "/checks/%s/name/" % self.check.code
  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(url, data=payload)
  23. check = Check.objects.get(code=self.check.code)
  24. assert check.name == "Bob Was Here"
  25. def test_it_checks_ownership(self):
  26. url = "/checks/%s/name/" % self.check.code
  27. payload = {"name": "Charlie Sent This"}
  28. self.client.login(username="[email protected]", password="password")
  29. r = self.client.post(url, data=payload)
  30. assert r.status_code == 403
  31. def test_it_handles_bad_uuid(self):
  32. url = "/checks/not-uuid/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. assert r.status_code == 400
  37. def test_it_handles_missing_uuid(self):
  38. # Valid UUID but there is no check for it:
  39. url = "/checks/6837d6ec-fc08-4da5-a67f-08a9ed1ccf62/name/"
  40. payload = {"name": "Alice Was Here"}
  41. self.client.login(username="[email protected]", password="password")
  42. r = self.client.post(url, data=payload)
  43. assert r.status_code == 404
  44. def test_it_sanitizes_tags(self):
  45. url = "/checks/%s/name/" % self.check.code
  46. payload = {"tags": " foo bar\r\t \n baz \n"}
  47. self.client.login(username="[email protected]", password="password")
  48. self.client.post(url, data=payload)
  49. check = Check.objects.get(id=self.check.id)
  50. self.assertEqual(check.tags, "foo bar baz")
  51. def test_it_rejects_get(self):
  52. url = "/checks/%s/name/" % self.check.code
  53. self.client.login(username="[email protected]", password="password")
  54. r = self.client.get(url)
  55. self.assertEqual(r.status_code, 405)