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.

75 lines
2.8 KiB

  1. from hc.api.models import Channel, Check
  2. from hc.test import BaseTestCase
  3. class TransferTestCase(BaseTestCase):
  4. def setUp(self):
  5. super().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.client.login(username="[email protected]", password="password")
  14. payload = {"project": self.project.code}
  15. r = self.client.post(self.url, payload, follow=True)
  16. self.assertRedirects(r, "/checks/%s/details/" % self.check.code)
  17. self.assertContains(r, "Check transferred successfully")
  18. check = Check.objects.get()
  19. self.assertEqual(check.project, self.project)
  20. def test_it_obeys_check_limit(self):
  21. # Alice's projects cannot accept checks due to limits:
  22. self.profile.check_limit = 0
  23. self.profile.save()
  24. self.client.login(username="[email protected]", password="password")
  25. payload = {"project": self.project.code}
  26. r = self.client.post(self.url, payload)
  27. self.assertEqual(r.status_code, 400)
  28. def test_it_reassigns_channels(self):
  29. alices_mail = Channel.objects.create(kind="email", project=self.project)
  30. bobs_mail = Channel.objects.create(kind="email", project=self.bobs_project)
  31. self.check.channel_set.add(bobs_mail)
  32. self.client.login(username="[email protected]", password="password")
  33. payload = {"project": self.project.code}
  34. self.client.post(self.url, payload)
  35. # alices_mail should be the only assigned channel:
  36. self.assertEqual(self.check.channel_set.get(), alices_mail)
  37. def test_it_checks_check_ownership(self):
  38. self.client.login(username="[email protected]", password="password")
  39. # Charlie tries to transfer Alice's check into his project
  40. payload = {"project": self.charlies_project.code}
  41. r = self.client.post(self.url, payload)
  42. self.assertEqual(r.status_code, 404)
  43. def test_it_checks_project_access(self):
  44. self.client.login(username="[email protected]", password="password")
  45. # Alice tries to transfer her check into Charlie's project
  46. payload = {"project": self.charlies_project.code}
  47. r = self.client.post(self.url, payload)
  48. self.assertEqual(r.status_code, 404)
  49. def test_it_requires_rw_access(self):
  50. self.bobs_membership.role = "r"
  51. self.bobs_membership.save()
  52. payload = {"project": self.project.code}
  53. self.client.login(username="[email protected]", password="password")
  54. r = self.client.post(self.url, payload)
  55. self.assertEqual(r.status_code, 403)