Skip to content

Commit fa9d199

Browse files
authored
Merge pull request #137 from NYU-RTS/revert-136-revert-133-manager-view-allocations
Take 2, "project managers should be able to see allocations""
2 parents 481adfc + c993d71 commit fa9d199

File tree

2 files changed

+118
-297
lines changed

2 files changed

+118
-297
lines changed

coldfront/core/project/tests/test_views.py

Lines changed: 30 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
from coldfront.core.test_helpers import utils
66
from coldfront.core.test_helpers.factories import (
7+
AllocationFactory,
8+
AllocationStatusChoiceFactory,
9+
AllocationUserFactory,
10+
AllocationUserStatusChoiceFactory,
711
UserFactory,
812
ProjectFactory,
913
ProjectUserFactory,
@@ -32,17 +36,18 @@ def setUpTestData(cls):
3236
cls.project_user = project_user.user
3337

3438
manager_role = ProjectUserRoleChoiceFactory(name="Manager")
35-
pi_user = ProjectUserFactory(
36-
project=cls.project, role=manager_role, user=cls.project.pi
37-
)
39+
pi_user = ProjectUserFactory(project=cls.project, role=manager_role, user=cls.project.pi)
3840
cls.pi_user = pi_user.user
41+
cls.manager_user = ProjectUserFactory(project=cls.project, role=manager_role)
3942
cls.admin_user = UserFactory(is_staff=True, is_superuser=True)
4043
cls.nonproject_user = UserFactory(is_staff=False, is_superuser=False)
4144

4245
attributetype = PAttributeTypeFactory(name="string")
43-
cls.projectattributetype = ProjectAttributeTypeFactory(
44-
attribute_type=attributetype
45-
)
46+
cls.projectattributetype = ProjectAttributeTypeFactory(attribute_type=attributetype)
47+
48+
cls.allocation = AllocationFactory(status=AllocationStatusChoiceFactory(name="active"), project=cls.project)
49+
active_ausc = AllocationUserStatusChoiceFactory(name="Active")
50+
cls.pi_as_alloc_user = AllocationUserFactory(allocation=cls.allocation, status=active_ausc)
4651

4752
def project_access_tstbase(self, url):
4853
"""Test basic access control for project views. For all project views:
@@ -94,9 +99,7 @@ def test_projectdetail_request_allocation_button_visibility(self):
9499
# pi can see request allocation button
95100
utils.page_contains_for_user(self, self.pi_user, self.url, button_text)
96101
# non-manager user cannot see request allocation button
97-
utils.page_does_not_contain_for_user(
98-
self, self.project_user, self.url, button_text
99-
)
102+
utils.page_does_not_contain_for_user(self, self.project_user, self.url, button_text)
100103

101104
def test_projectdetail_edituser_button_visibility(self):
102105
"""Test visibility of projectdetail edit button across user levels"""
@@ -105,24 +108,22 @@ def test_projectdetail_edituser_button_visibility(self):
105108
# pi can see edit button
106109
utils.page_contains_for_user(self, self.pi_user, self.url, "fa-user-edit")
107110
# non-manager user cannot see edit button
108-
utils.page_does_not_contain_for_user(
109-
self, self.project_user, self.url, "fa-user-edit"
110-
)
111+
utils.page_does_not_contain_for_user(self, self.project_user, self.url, "fa-user-edit")
111112

112113
def test_projectdetail_addnotification_button_visibility(self):
113114
"""Test visibility of projectdetail add notification button across user levels"""
114115
# admin can see add notification button
115-
utils.page_contains_for_user(
116-
self, self.admin_user, self.url, "Add Notification"
117-
)
116+
utils.page_contains_for_user(self, self.admin_user, self.url, "Add Notification")
118117
# pi cannot see add notification button
119-
utils.page_does_not_contain_for_user(
120-
self, self.pi_user, self.url, "Add Notification"
121-
)
118+
utils.page_does_not_contain_for_user(self, self.pi_user, self.url, "Add Notification")
122119
# non-manager user cannot see add notification button
123-
utils.page_does_not_contain_for_user(
124-
self, self.project_user, self.url, "Add Notification"
125-
)
120+
utils.page_does_not_contain_for_user(self, self.project_user, self.url, "Add Notification")
121+
122+
def test_manager_can_view_allocations(self):
123+
"""Project Manager should be able to view allocations on the project
124+
without being a user on the Allocation"""
125+
response = utils.login_and_get_page(self.client, self.manager_user.user, self.url)
126+
self.assertEqual(len(response.context["allocations"]), 1)
126127

127128

128129
class ProjectCreateTest(ProjectViewTestBase):
@@ -152,9 +153,7 @@ def setUpTestData(cls):
152153
"""Set up users and project for testing"""
153154
super(ProjectAttributeCreateTest, cls).setUpTestData()
154155
int_attributetype = PAttributeTypeFactory(name="Int")
155-
cls.int_projectattributetype = ProjectAttributeTypeFactory(
156-
attribute_type=int_attributetype
157-
)
156+
cls.int_projectattributetype = ProjectAttributeTypeFactory(attribute_type=int_attributetype)
158157
cls.url = f"/project/{cls.project.pk}/project-attribute-create/"
159158

160159
def test_project_access(self):
@@ -180,9 +179,7 @@ def test_project_attribute_create_post(self):
180179
},
181180
)
182181
redirect_url = f"/project/{self.project.pk}/"
183-
self.assertRedirects(
184-
response, redirect_url, status_code=302, target_status_code=200
185-
)
182+
self.assertRedirects(response, redirect_url, status_code=302, target_status_code=200)
186183

187184
def test_project_attribute_create_post_required_values(self):
188185
"""ProjectAttributeCreate correctly flags missing project or value"""
@@ -195,9 +192,7 @@ def test_project_attribute_create_post_required_values(self):
195192
"value": "test_value",
196193
},
197194
)
198-
self.assertFormError(
199-
response.context["form"], "project", "This field is required."
200-
)
195+
self.assertFormError(response.context["form"], "project", "This field is required.")
201196
# missing value
202197
response = self.client.post(
203198
self.url,
@@ -206,9 +201,7 @@ def test_project_attribute_create_post_required_values(self):
206201
"project": self.project.pk,
207202
},
208203
)
209-
self.assertFormError(
210-
response.context["form"], "value", "This field is required."
211-
)
204+
self.assertFormError(response.context["form"], "value", "This field is required.")
212205

213206
def test_project_attribute_create_value_type_match(self):
214207
"""ProjectAttributeCreate correctly flags value-type mismatch"""
@@ -223,9 +216,7 @@ def test_project_attribute_create_value_type_match(self):
223216
"project": self.project.pk,
224217
},
225218
)
226-
self.assertFormError(
227-
response.context["form"], None, "Invalid Value True. Value must be an int."
228-
)
219+
self.assertFormError(response.context["form"], None, "Invalid Value True. Value must be an int.")
229220

230221

231222
class ProjectAttributeUpdateTest(ProjectViewTestBase):
@@ -281,9 +272,7 @@ def setUpTestData(cls):
281272
super(ProjectListViewTest, cls).setUpTestData()
282273
# add 100 projects to test pagination, permissions, search functionality
283274
additional_projects = [ProjectFactory() for i in list(range(100))]
284-
cls.additional_projects = [
285-
p for p in additional_projects if p.pi.last_name != cls.project.pi.last_name
286-
]
275+
cls.additional_projects = [p for p in additional_projects if p.pi.last_name != cls.project.pi.last_name]
287276
cls.url = "/project/"
288277

289278
### ProjectListView access tests ###
@@ -305,9 +294,7 @@ def test_project_list_display_members(self):
305294
response = utils.login_and_get_page(self.client, self.project_user, self.url)
306295
self.assertEqual(len(response.context["object_list"]), 1)
307296
proj_user = self.project.projectuser_set.get(user=self.project_user)
308-
proj_user.status, _ = ProjectUserStatusChoice.objects.get_or_create(
309-
name="Removed"
310-
)
297+
proj_user.status, _ = ProjectUserStatusChoice.objects.get_or_create(name="Removed")
311298
proj_user.save()
312299
response = utils.login_and_get_page(self.client, self.project_user, self.url)
313300
self.assertEqual(len(response.context["object_list"]), 0)
@@ -335,10 +322,7 @@ def test_project_list_displayall_permission_project_user(self):
335322
def test_project_list_search(self):
336323
"""Test that project list search works."""
337324
url_base = self.url + "?show_all_projects=on"
338-
url = (
339-
f"{url_base}&last_name={self.project.pi.last_name}"
340-
+ f"&school={self.project.school.description}"
341-
)
325+
url = f"{url_base}&last_name={self.project.pi.last_name}" + f"&school={self.project.school.description}"
342326
# search by project project_title
343327
response = utils.login_and_get_page(self.client, self.admin_user, url)
344328
self.assertEqual(len(response.context["object_list"]), 1)

0 commit comments

Comments
 (0)