def test_update_updates_group_on_success(self, factories, pyramid_request, group, group_svc, user_svc, handle_form_submission): pyramid_request.matchdict = {'pubid': group.pubid} updated_name = 'Updated group' updated_creator = factories.User() user_svc.fetch.return_value = updated_creator updated_description = 'New description' updated_origins = ['https://a-new-site.com'] def call_on_success(request, form, on_success, on_failure): return on_success({ 'authority': pyramid_request.authority, 'creator': updated_creator.username, 'description': updated_description, 'group_type': 'open', 'name': updated_name, 'origins': updated_origins, }) handle_form_submission.side_effect = call_on_success ctrl = GroupEditController(pyramid_request) ctx = ctrl.update() assert group.creator.username == updated_creator.username assert group.description == updated_description assert group.name == updated_name assert [s.origin for s in group.scopes] == updated_origins assert ctx['form'] == self._expected_form(group)
def test_update_updates_group_membership_on_success( self, factories, pyramid_request, group_svc, user_svc, handle_form_submission): group = factories.RestrictedGroup(pubid='testgroup') pyramid_request.matchdict = {'pubid': group.pubid} member_a = factories.User() member_b = factories.User() updated_creator = factories.User() user_svc.fetch.return_value = updated_creator def call_on_success(request, form, on_success, on_failure): return on_success({ 'authority': pyramid_request.authority, 'creator': updated_creator.username, 'description': 'a desc', 'group_type': 'restricted', 'name': 'a name', 'members': [member_a.username, member_b.username], 'organization': group.organization.pubid, 'origins': ['http://www.example.com'], }) handle_form_submission.side_effect = call_on_success ctrl = GroupEditController(pyramid_request) ctrl.update() group_svc.update_membership.assert_any_call( group, [member_a.username, member_b.username])
def test_update_updates_group_members_on_success(self, factories, pyramid_request, group_svc, user_svc, handle_form_submission): group = factories.RestrictedGroup(pubid='testgroup') pyramid_request.matchdict = {'pubid': group.pubid} member_a = factories.User() member_b = factories.User() updated_creator = factories.User() user_svc.fetch.return_value = updated_creator def call_on_success(request, form, on_success, on_failure): return on_success({ 'authority': pyramid_request.authority, 'creator': updated_creator.username, 'description': 'a desc', 'group_type': 'restricted', 'name': 'a name', 'members': [member_a.username, member_b.username], 'organization': group.organization.pubid, 'origins': ['http://www.example.com'], }) handle_form_submission.side_effect = call_on_success ctrl = GroupEditController(pyramid_request) ctrl.update() group_svc.update_members.assert_any_call(group, [member_a.userid, member_b.userid])
def test_read_renders_form(self, pyramid_request, group): pyramid_request.matchdict = {'pubid': group.pubid} ctrl = GroupEditController(pyramid_request) ctx = ctrl.read() assert ctx['form'] == self._expected_form(group)
def test_delete_deletes_group(self, group, delete_group_svc, pyramid_request, routes): pyramid_request.matchdict = {"pubid": group.pubid} ctrl = GroupEditController(pyramid_request) ctrl.delete() delete_group_svc.delete.assert_called_once_with(group)
def test_read_renders_form_if_group_has_no_creator(self, pyramid_request, group): pyramid_request.matchdict = {'pubid': group.pubid} group.creator = None ctrl = GroupEditController(pyramid_request) ctx = ctrl.read() assert ctx['form'] == self._expected_form(group)
def test_delete_deletes_group(self, group, delete_group_svc, pyramid_request, routes): pyramid_request.matchdict = {"pubid": group.pubid} ctrl = GroupEditController(pyramid_request) ctrl.delete() delete_group_svc.delete.assert_called_once_with(group)
def test_read_renders_form(self, pyramid_request, factories, group): pyramid_request.matchdict = {'pubid': group.pubid} factories.Annotation(groupid=group.pubid) factories.Annotation(groupid=group.pubid) ctrl = GroupEditController(pyramid_request) ctx = ctrl.read() assert ctx['form'] == self._expected_form(group) assert ctx['pubid'] == group.pubid assert ctx['group_name'] == group.name assert ctx['member_count'] == len(group.members) assert ctx['annotation_count'] == 2
def test_read_renders_form(self, pyramid_request, factories, group): pyramid_request.matchdict = {'pubid': group.pubid} factories.Annotation(groupid=group.pubid) factories.Annotation(groupid=group.pubid) ctrl = GroupEditController(pyramid_request) ctx = ctrl.read() assert ctx['form'] == self._expected_form(group) assert ctx['pubid'] == group.pubid assert ctx['group_name'] == group.name assert ctx['member_count'] == len(group.members) assert ctx['annotation_count'] == 2
def test_it_binds_schema(self, pyramid_request, group, patch): schema = mock.Mock(spec_set=['bind']) CreateAdminGroupSchema = patch( 'h.views.admin_groups.CreateAdminGroupSchema') # noqa: N806 CreateAdminGroupSchema.return_value = schema pyramid_request.matchdict = {'pubid': group.pubid} GroupEditController(pyramid_request) schema.bind.assert_called_with(request=pyramid_request, group=group)
def test_update_updates_group_on_success(self, factories, pyramid_request, group_svc, user_svc, list_orgs_svc, handle_form_submission): group = factories.RestrictedGroup(pubid='testgroup') pyramid_request.matchdict = {'pubid': group.pubid} updated_name = 'Updated group' updated_creator = factories.User() user_svc.fetch.return_value = updated_creator updated_description = 'New description' updated_origins = ['https://a-new-site.com'] updated_members = [] 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': updated_creator.username, 'description': updated_description, 'group_type': 'open', 'name': updated_name, 'organization': updated_org.pubid, 'origins': updated_origins, 'members': updated_members, }) handle_form_submission.side_effect = call_on_success ctrl = GroupEditController(pyramid_request) ctx = ctrl.update() assert group.creator.username == updated_creator.username assert group.description == updated_description assert group.name == updated_name assert group.organization == updated_org assert [s.origin for s in group.scopes] == updated_origins assert ctx['form'] == self._expected_form(group)
def test_update_does_not_update_authority(self, pyramid_request, group, user_svc, handle_form_submission): pyramid_request.matchdict = {'pubid': group.pubid} user_svc.fetch.return_value = group.creator group.authority = 'original.com' def call_on_success(request, form, on_success, on_failure): return on_success({ 'authority': 'different.com', 'creator': group.creator.username, 'description': group.description, 'group_type': 'open', 'name': group.name, 'origins': [s.origin for s in group.scopes], }) handle_form_submission.side_effect = call_on_success ctrl = GroupEditController(pyramid_request) ctx = ctrl.update() assert group.authority == 'original.com' assert ctx['form'] == self._expected_form(group)
def test_update_updates_group_on_success(self, factories, pyramid_request, group_svc, user_svc, list_orgs_svc, handle_form_submission): group = factories.RestrictedGroup(pubid='testgroup') pyramid_request.matchdict = {'pubid': group.pubid} updated_name = 'Updated group' updated_creator = factories.User() user_svc.fetch.return_value = updated_creator updated_description = 'New description' updated_origins = ['https://a-new-site.com'] updated_members = [] 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': updated_creator.username, 'description': updated_description, 'group_type': 'open', 'name': updated_name, 'organization': updated_org.pubid, 'origins': updated_origins, 'members': updated_members, }) handle_form_submission.side_effect = call_on_success ctrl = GroupEditController(pyramid_request) ctx = ctrl.update() assert group.creator.username == updated_creator.username assert group.description == updated_description assert group.name == updated_name assert group.organization == updated_org assert [s.origin for s in group.scopes] == updated_origins assert ctx['form'] == self._expected_form(group)
def test_read_lists_organizations_in_groups_authority( self, factories, pyramid_request, group, # noqa: N803 default_org, CreateAdminGroupSchema, list_orgs_svc): pyramid_request.matchdict = {'pubid': group.pubid} GroupEditController(pyramid_request) list_orgs_svc.organizations.assert_called_with(group.authority) schema = CreateAdminGroupSchema.return_value (_, call_kwargs) = schema.bind.call_args assert call_kwargs['organizations'] == {default_org.pubid: default_org}
def test_it_binds_schema( self, pyramid_request, group, user_svc, # noqa: N803 default_org, CreateAdminGroupSchema): pyramid_request.matchdict = {'pubid': group.pubid} GroupEditController(pyramid_request) schema = CreateAdminGroupSchema.return_value schema.bind.assert_called_with( request=pyramid_request, group=group, user_svc=user_svc, organizations={default_org.pubid: default_org})
def test_raises_not_found_if_unknown_group(self, pyramid_request): pyramid_request.matchdict = {'pubid': 'unknown'} with pytest.raises(HTTPNotFound): GroupEditController(pyramid_request)