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.

43 lines
1.5 KiB

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