def test_update_proxies_to_update_service_on_success( self, factories, pyramid_request, user_service, list_organizations_service, handle_form_submission, group_update_service, group, GroupScope, ): fetched_user = factories.User() user_service.fetch.return_value = fetched_user updated_org = factories.Organization() list_organizations_service.organizations.return_value.append( updated_org) def call_on_success( # pylint:disable=unused-argument request, form, on_success, on_failure): return on_success({ "creator": fetched_user.username, "description": "New description", "group_type": "open", "name": "Updated group", "organization": updated_org.pubid, "scopes": ["http://somewhereelse.com", "http://www.gladiolus.org"], "members": [], "enforce_scope": False, }) handle_form_submission.side_effect = call_on_success view = GroupEditViews(GroupContext(group), pyramid_request) response = view.update() group_update_service.update.assert_called_once_with( group, organization=updated_org, creator=fetched_user, description="New description", name="Updated group", scopes=[ GroupScope(scope=scope) for scope in ["http://somewhereelse.com", "http://www.gladiolus.org"] ], enforce_scope=False, ) assert response["form"] == self._expected_form(group)
def test_update_proxies_to_update_svc_on_success( self, factories, pyramid_request, user_svc, list_orgs_svc, handle_form_submission, group_update_svc, group, GroupScope, ): fetched_user = factories.User() user_svc.fetch.return_value = fetched_user updated_org = factories.Organization() list_orgs_svc.organizations.return_value.append(updated_org) def call_on_success(request, form, on_success, on_failure): return on_success({ "creator": fetched_user.username, "description": "New description", "group_type": "open", "name": "Updated group", "organization": updated_org.pubid, "origins": ["http://somewhereelse.com", "http://www.gladiolus.org"], "members": [], "enforce_scope": False, }) handle_form_submission.side_effect = call_on_success view = GroupEditViews(group, pyramid_request) ctx = view.update() group_update_svc.update.assert_called_once_with( group, organization=updated_org, creator=fetched_user, description="New description", name="Updated group", scopes=[ GroupScope(origin=o) for o in ["http://somewhereelse.com", "http://www.gladiolus.org"] ], enforce_scope=False, ) assert ctx["form"] == self._expected_form(group)
def test_update_updates_group_members_on_success( self, factories, pyramid_request, group_create_svc, user_svc, group_members_svc, handle_form_submission, list_orgs_svc, ): group = factories.RestrictedGroup( pubid="testgroup", organization=factories.Organization() ) list_orgs_svc.organizations.return_value = [group.organization] fetched_user = factories.User() user_svc.fetch.return_value = fetched_user def call_on_success(request, form, on_success, on_failure): return on_success( { "authority": pyramid_request.default_authority, "creator": fetched_user.username, "description": "a desc", "group_type": "restricted", "name": "a name", "members": ["phil", "sue"], "organization": group.organization.pubid, "scopes": ["http://www.example.com"], "enforce_scope": group.enforce_scope, } ) handle_form_submission.side_effect = call_on_success view = GroupEditViews(group, pyramid_request) view.update() group_members_svc.update_members.assert_any_call( group, [fetched_user.userid, fetched_user.userid] )
def test_update_updates_group_members_on_success( self, factories, pyramid_request, group_create_svc, user_service, group_members_svc, handle_form_submission, list_orgs_svc, ): group = factories.RestrictedGroup( pubid="testgroup", organization=factories.Organization() ) list_orgs_svc.organizations.return_value = [group.organization] fetched_user = factories.User() user_service.fetch.return_value = fetched_user def call_on_success(request, form, on_success, on_failure): return on_success( { "authority": pyramid_request.default_authority, "creator": fetched_user.username, "description": "a desc", "group_type": "restricted", "name": "a name", "members": ["phil", "sue"], "organization": group.organization.pubid, "scopes": ["http://www.example.com"], "enforce_scope": group.enforce_scope, } ) handle_form_submission.side_effect = call_on_success view = GroupEditViews(group, pyramid_request) view.update() group_members_svc.update_members.assert_any_call( group, [fetched_user.userid, fetched_user.userid] )
def test_update_proxies_to_update_svc_on_success( self, factories, pyramid_request, user_svc, list_orgs_svc, handle_form_submission, group_update_svc, group, GroupScope, ): fetched_user = factories.User() user_svc.fetch.return_value = fetched_user updated_org = factories.Organization() list_orgs_svc.organizations.return_value.append(updated_org) def call_on_success(request, form, on_success, on_failure): return on_success( { "creator": fetched_user.username, "description": "New description", "group_type": "open", "name": "Updated group", "organization": updated_org.pubid, "scopes": ["http://somewhereelse.com", "http://www.gladiolus.org"], "members": [], "enforce_scope": False, } ) handle_form_submission.side_effect = call_on_success view = GroupEditViews(group, pyramid_request) ctx = view.update() group_update_svc.update.assert_called_once_with( group, organization=updated_org, creator=fetched_user, description="New description", name="Updated group", scopes=[ GroupScope(scope=o) for o in ["http://somewhereelse.com", "http://www.gladiolus.org"] ], enforce_scope=False, ) assert ctx["form"] == self._expected_form(group)