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_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)