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.

65 lines
2.1 KiB

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