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.

79 lines
2.8 KiB

10 years ago
10 years ago
10 years ago
6 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, project=self.project)
  7. self.check.save()
  8. self.url = "/checks/%s/name/" % self.check.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, "/checks/")
  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. # Bob's current team is not set
  25. self.bobs_profile.current_team = None
  26. self.bobs_profile.save()
  27. # But this should still work:
  28. self.client.login(username="[email protected]", password="password")
  29. r = self.client.post(self.url, data={"name": "Bob Was Here"})
  30. self.assertRedirects(r, "/checks/")
  31. def test_it_checks_ownership(self):
  32. payload = {"name": "Charlie Sent This"}
  33. self.client.login(username="[email protected]", password="password")
  34. r = self.client.post(self.url, data=payload)
  35. self.assertEqual(r.status_code, 404)
  36. def test_it_handles_bad_uuid(self):
  37. url = "/checks/not-uuid/name/"
  38. payload = {"name": "Alice Was Here"}
  39. self.client.login(username="[email protected]", password="password")
  40. r = self.client.post(url, data=payload)
  41. self.assertEqual(r.status_code, 404)
  42. def test_it_handles_missing_uuid(self):
  43. # Valid UUID but there is no check for it:
  44. url = "/checks/6837d6ec-fc08-4da5-a67f-08a9ed1ccf62/name/"
  45. payload = {"name": "Alice Was Here"}
  46. self.client.login(username="[email protected]", password="password")
  47. r = self.client.post(url, data=payload)
  48. self.assertEqual(r.status_code, 404)
  49. def test_it_sanitizes_tags(self):
  50. payload = {"tags": " foo bar\r\t \n baz \n"}
  51. self.client.login(username="[email protected]", password="password")
  52. self.client.post(self.url, data=payload)
  53. self.check.refresh_from_db()
  54. self.assertEqual(self.check.tags, "foo bar baz")
  55. def test_it_rejects_get(self):
  56. self.client.login(username="[email protected]", password="password")
  57. r = self.client.get(self.url)
  58. self.assertEqual(r.status_code, 405)