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.5 KiB

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