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.

72 lines
2.8 KiB

  1. from hc.api.models import Channel, Check
  2. from hc.test import BaseTestCase
  3. class TrabsferTestCase(BaseTestCase):
  4. def setUp(self):
  5. super(TrabsferTestCase, self).setUp()
  6. self.check = Check.objects.create(project=self.bobs_project)
  7. self.url = "/checks/%s/transfer/" % self.check.code
  8. def test_it_serves_form(self):
  9. self.client.login(username="[email protected]", password="password")
  10. r = self.client.get(self.url)
  11. self.assertContains(r, "Transfer to Another Project")
  12. def test_it_works(self):
  13. self.bobs_profile.current_project = self.bobs_project
  14. self.bobs_profile.save()
  15. self.client.login(username="[email protected]", password="password")
  16. payload = {"project": self.project.code}
  17. r = self.client.post(self.url, payload, follow=True)
  18. self.assertRedirects(r, "/checks/%s/details/" % self.check.code)
  19. self.assertContains(r, "Check transferred successfully")
  20. check = Check.objects.get()
  21. self.assertEqual(check.project, self.project)
  22. # Bob's current project should have been updated
  23. self.bobs_profile.refresh_from_db()
  24. self.assertEqual(self.bobs_profile.current_project, self.project)
  25. def test_it_obeys_check_limit(self):
  26. # Alice's projects cannot accept checks due to limits:
  27. self.profile.check_limit = 0
  28. self.profile.save()
  29. self.client.login(username="[email protected]", password="password")
  30. payload = {"project": self.project.code}
  31. r = self.client.post(self.url, payload)
  32. self.assertEqual(r.status_code, 400)
  33. def test_it_reassigns_channels(self):
  34. alices_mail = Channel.objects.create(kind="email", project=self.project)
  35. bobs_mail = Channel.objects.create(kind="email", project=self.bobs_project)
  36. self.check.channel_set.add(bobs_mail)
  37. self.client.login(username="[email protected]", password="password")
  38. payload = {"project": self.project.code}
  39. self.client.post(self.url, payload)
  40. # alices_mail should be the only assigned channel:
  41. self.assertEqual(self.check.channel_set.get(), alices_mail)
  42. def test_it_checks_check_ownership(self):
  43. self.client.login(username="[email protected]", password="password")
  44. # Charlie tries to transfer Alice's check into his project
  45. payload = {"project": self.charlies_project.code}
  46. r = self.client.post(self.url, payload)
  47. self.assertEqual(r.status_code, 404)
  48. def test_it_checks_project_access(self):
  49. self.client.login(username="[email protected]", password="password")
  50. # Alice tries to transfer her check into Charlie's project
  51. payload = {"project": self.charlies_project.code}
  52. r = self.client.post(self.url, payload)
  53. self.assertEqual(r.status_code, 404)