From e1c3beb4e9dc84700c8864b43f0a3d3c44393293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Mon, 26 Jul 2021 13:07:05 +0300 Subject: [PATCH] Add test cases for manager operations --- hc/accounts/tests/test_project.py | 41 +++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/hc/accounts/tests/test_project.py b/hc/accounts/tests/test_project.py index b68a9ccf..aaeed31c 100644 --- a/hc/accounts/tests/test_project.py +++ b/hc/accounts/tests/test_project.py @@ -199,10 +199,23 @@ class ProjectTestCase(BaseTestCase): self.assertEqual(len(mail.outbox), 0) - def test_it_requires_owner_to_add_team_member(self): + def test_it_lets_manager_add_team_member(self): + # Bob is a manager: + self.bobs_membership.role = "m" + self.bobs_membership.save() + self.client.login(username="bob@example.org", password="password") - form = {"invite_team_member": "1", "email": "frank@example.org", "role": "r"} + form = {"invite_team_member": "1", "email": "frank@example.org", "role": "w"} + r = self.client.post(self.url, form) + self.assertEqual(r.status_code, 200) + + Member.objects.get(project=self.project, user__email="frank@example.org") + + def test_it_does_not_allow_regular_member_invite_team_members(self): + self.client.login(username="bob@example.org", password="password") + + form = {"invite_team_member": "1", "email": "frank@example.org", "role": "w"} r = self.client.post(self.url, form) self.assertEqual(r.status_code, 403) @@ -216,7 +229,7 @@ class ProjectTestCase(BaseTestCase): r = self.client.post(self.url, form) self.assertEqual(r.status_code, 403) - def test_it_removes_team_member(self): + def test_it_lets_owner_remove_team_member(self): self.client.login(username="alice@example.org", password="password") form = {"remove_team_member": "1", "email": "bob@example.org"} @@ -225,10 +238,28 @@ class ProjectTestCase(BaseTestCase): self.assertFalse(Member.objects.exists()) - def test_it_requires_owner_to_remove_team_member(self): + def test_it_lets_manager_remove_team_member(self): + # Bob is a manager: + self.bobs_membership.role = "m" + self.bobs_membership.save() + + # Bob will try to remove this membership: + Member.objects.create(user=self.charlie, project=self.project) + self.client.login(username="bob@example.org", password="password") + form = {"remove_team_member": "1", "email": "charlie@example.org"} + r = self.client.post(self.url, form) + self.assertEqual(r.status_code, 200) - form = {"remove_team_member": "1", "email": "bob@example.org"} + q = Member.objects.filter(user=self.charlie, project=self.project) + self.assertFalse(q.exists()) + + def test_it_does_not_allow_regular_member_remove_team_member(self): + # Bob will try to remove this membership: + Member.objects.create(user=self.charlie, project=self.project) + + self.client.login(username="bob@example.org", password="password") + form = {"remove_team_member": "1", "email": "charlie@example.org"} r = self.client.post(self.url, form) self.assertEqual(r.status_code, 403)