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.

47 lines
1.4 KiB

10 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. assert r.status_code == 302
  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