Esempio n. 1
0
    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.default_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])
Esempio n. 2
0
    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)
Esempio n. 3
0
    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)
Esempio n. 4
0
    def test_delete_deletes_group(self, group, group_svc, delete_group_svc,
                                  pyramid_request, routes):
        group_svc.fetch.return_value = group

        ctrl = GroupEditController(pyramid_request)

        ctrl.delete()

        delete_group_svc.delete.assert_called_once_with(group)
Esempio n. 5
0
    def test_read_renders_form_if_group_has_no_creator(self, pyramid_request,
                                                       group, group_svc):
        group.creator = None
        group_svc.fetch.return_value = group
        ctrl = GroupEditController(pyramid_request)

        ctx = ctrl.read()

        assert ctx['form'] == self._expected_form(group)
Esempio n. 6
0
    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
Esempio n. 7
0
    def test_read_lists_organizations_in_groups_authority(
            self, factories, pyramid_request, group, default_org,
            CreateAdminGroupSchema, list_orgs_svc, group_svc):
        group_svc.fetch.return_value = group

        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}
Esempio n. 8
0
    def test_it_binds_schema(self, pyramid_request, group, user_svc,
                             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})
Esempio n. 9
0
    def test_update_updates_group_on_success(self, factories, pyramid_request,
                                             group_create_svc, user_svc,
                                             list_orgs_svc,
                                             handle_form_submission,
                                             group_svc):
        group = factories.RestrictedGroup(pubid='testgroup')
        group_svc.fetch.return_value = group

        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)
Esempio n. 10
0
    def test_raises_not_found_if_unknown_group(self, pyramid_request,
                                               group_svc):
        group_svc.fetch.return_value = None

        with pytest.raises(HTTPNotFound):
            GroupEditController(pyramid_request)
Esempio n. 11
0
 def test_raises_not_found_if_unknown_group(self, pyramid_request):
     pyramid_request.matchdict = {'pubid': 'unknown'}
     with pytest.raises(HTTPNotFound):
         GroupEditController(pyramid_request)