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.

42 lines
1.4 KiB

9 years ago
9 years ago
9 years ago
9 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 Channel
  4. class ChannelChecksTestCase(TestCase):
  5. def setUp(self):
  6. self.alice = User(username="alice")
  7. self.alice.set_password("password")
  8. self.alice.save()
  9. self.channel = Channel(user=self.alice, kind="email")
  10. self.channel.value = "[email protected]"
  11. self.channel.save()
  12. def test_it_works(self):
  13. url = "/integrations/%s/checks/" % self.channel.code
  14. self.client.login(username="alice", password="password")
  15. r = self.client.get(url)
  16. self.assertContains(r, "[email protected]", status_code=200)
  17. def test_it_checks_owner(self):
  18. mallory = User(username="mallory")
  19. mallory.set_password("password")
  20. mallory.save()
  21. # channel does not belong to mallory so this should come back
  22. # with 403 Forbidden:
  23. url = "/integrations/%s/checks/" % self.channel.code
  24. self.client.login(username="mallory", password="password")
  25. r = self.client.get(url)
  26. assert r.status_code == 403
  27. def test_missing_channel(self):
  28. # Valid UUID but there is no channel for it:
  29. url = "/integrations/6837d6ec-fc08-4da5-a67f-08a9ed1ccf62/checks/"
  30. self.client.login(username="alice", password="password")
  31. r = self.client.get(url)
  32. assert r.status_code == 404