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.

74 lines
2.9 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",
  35. project=self.project)
  36. bobs_mail = Channel.objects.create(kind="email",
  37. project=self.bobs_project)
  38. self.check.channel_set.add(bobs_mail)
  39. self.client.login(username="[email protected]", password="password")
  40. payload = {"project": self.project.code}
  41. self.client.post(self.url, payload)
  42. # alices_mail should be the only assigned channel:
  43. self.assertEqual(self.check.channel_set.get(), alices_mail)
  44. def test_it_checks_check_ownership(self):
  45. self.client.login(username="[email protected]", password="password")
  46. # Charlie tries to transfer Alice's check into his project
  47. payload = {"project": self.charlies_project.code}
  48. r = self.client.post(self.url, payload)
  49. self.assertEqual(r.status_code, 404)
  50. def test_it_checks_project_access(self):
  51. self.client.login(username="[email protected]", password="password")
  52. # Alice tries to transfer her check into Charlie's project
  53. payload = {"project": self.charlies_project.code}
  54. r = self.client.post(self.url, payload)
  55. self.assertEqual(r.status_code, 404)