Skip to content

Commit 06715e2

Browse files
mkovaluaadlius
authored andcommitted
implement unit test for component project contributors from parent project updating
1 parent 4f5acbc commit 06715e2

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

api/nodes/views.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,6 @@ def get_serializer_context(self):
505505
context['default_email'] = 'default'
506506
return context
507507

508-
509508
def patch(self, request, *args, **kwargs):
510509
"""
511510
Override the default patch behavior to handle the special case

api_tests/nodes/views/test_node_contributors_detail_update.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ def project(self, user, contrib):
3232
)
3333
return project
3434

35+
@pytest.fixture()
36+
def component_project_and_parent_project(self, user, contrib):
37+
# both need to be in same method to keep root same as parent
38+
parent_project = ProjectFactory(creator=user)
39+
parent_project.add_contributor(
40+
contrib,
41+
permissions=permissions.WRITE,
42+
visible=True,
43+
save=True
44+
)
45+
component_project = ProjectFactory(creator=user)
46+
component_project.root = parent_project
47+
component_project.save()
48+
return component_project, parent_project
49+
3550
@pytest.fixture()
3651
def url_creator(self, user, project):
3752
return f'/{API_BASE}nodes/{project._id}/contributors/{user._id}/'
@@ -414,3 +429,22 @@ def test_change_admin_self_with_other_admin(self, app, user, contrib, project, u
414429
attributes = res.json['data']['attributes']
415430
assert attributes['permission'] == permissions.WRITE
416431
assert project.get_permissions(user) == [permissions.READ, permissions.WRITE]
432+
433+
def test_update_component_project_with_parent_contributors(self, app, user, component_project_and_parent_project):
434+
def exists_unique_parent_contributors(parent_project, component_project):
435+
return parent_project.contributors.exclude(
436+
id__in=component_project.contributors.values_list('id', flat=True)
437+
).exists()
438+
component_project, parent_project = component_project_and_parent_project
439+
assert exists_unique_parent_contributors(parent_project, component_project)
440+
res = app.patch_json_api(
441+
f'/{API_BASE}nodes/{component_project._id}/contributors/?copy_contributors_from_parent_project=true',
442+
{
443+
'data': {
444+
'type': 3
445+
}
446+
},
447+
auth=user.auth
448+
)
449+
assert res.status_code == 200
450+
assert not exists_unique_parent_contributors(parent_project, component_project)

0 commit comments

Comments
 (0)