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.

63 lines
2.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
10 years ago
9 years ago
9 years ago
  1. from django.contrib.auth.models import User
  2. from hc.api.models import Check
  3. from hc.test import BaseTestCase
  4. class UpdateNameTestCase(BaseTestCase):
  5. def setUp(self):
  6. super(UpdateNameTestCase, self).setUp()
  7. self.check = Check(user=self.alice)
  8. self.check.save()
  9. def test_it_works(self):
  10. url = "/checks/%s/name/" % self.check.code
  11. payload = {"name": "Alice Was Here"}
  12. self.client.login(username="[email protected]", password="password")
  13. r = self.client.post(url, data=payload)
  14. self.assertRedirects(r, "/checks/")
  15. check = Check.objects.get(code=self.check.code)
  16. assert check.name == "Alice Was Here"
  17. def test_it_checks_ownership(self):
  18. charlie = User(username="charlie", email="[email protected]")
  19. charlie.set_password("password")
  20. charlie.save()
  21. url = "/checks/%s/name/" % self.check.code
  22. payload = {"name": "Charlie Sent This"}
  23. self.client.login(username="[email protected]", password="password")
  24. r = self.client.post(url, data=payload)
  25. assert r.status_code == 403
  26. def test_it_handles_bad_uuid(self):
  27. url = "/checks/not-uuid/name/"
  28. payload = {"name": "Alice Was Here"}
  29. self.client.login(username="[email protected]", password="password")
  30. r = self.client.post(url, data=payload)
  31. assert r.status_code == 400
  32. def test_it_handles_missing_uuid(self):
  33. # Valid UUID but there is no check for it:
  34. url = "/checks/6837d6ec-fc08-4da5-a67f-08a9ed1ccf62/name/"
  35. payload = {"name": "Alice Was Here"}
  36. self.client.login(username="[email protected]", password="password")
  37. r = self.client.post(url, data=payload)
  38. assert r.status_code == 404
  39. def test_it_sanitizes_tags(self):
  40. url = "/checks/%s/name/" % self.check.code
  41. payload = {"tags": " foo bar\r\t \n baz \n"}
  42. self.client.login(username="[email protected]", password="password")
  43. self.client.post(url, data=payload)
  44. check = Check.objects.get(id=self.check.id)
  45. self.assertEqual(check.tags, "foo bar baz")