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.

51 lines
1.7 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
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 RemoveChannelTestCase(TestCase):
  5. def setUp(self):
  6. super(RemoveChannelTestCase, 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/remove/" % self.channel.code
  15. self.client.login(username="[email protected]", password="password")
  16. r = self.client.post(url)
  17. self.assertRedirects(r, "/integrations/")
  18. assert Channel.objects.count() == 0
  19. def test_it_handles_bad_uuid(self):
  20. url = "/integrations/not-uuid/remove/"
  21. self.client.login(username="[email protected]", password="password")
  22. r = self.client.post(url)
  23. assert r.status_code == 400
  24. def test_it_checks_owner(self):
  25. url = "/integrations/%s/remove/" % self.channel.code
  26. mallory = User(username="mallory", email="[email protected]")
  27. mallory.set_password("password")
  28. mallory.save()
  29. self.client.login(username="[email protected]", password="password")
  30. r = self.client.post(url)
  31. assert r.status_code == 403
  32. def test_it_handles_missing_uuid(self):
  33. # Valid UUID but there is no channel for it:
  34. url = "/integrations/6837d6ec-fc08-4da5-a67f-08a9ed1ccf62/remove/"
  35. self.client.login(username="[email protected]", password="password")
  36. r = self.client.post(url)
  37. assert r.status_code == 404