def test_post_creates_group_on_success(self, factories, pyramid_request, group_svc, handle_form_submission, type_, default_org): name = 'My new group' creator = pyramid_request.user.username member_to_add = factories.User() description = 'Purpose of new group' origins = ['https://example.com'] def call_on_success(request, form, on_success, on_failure): return on_success({ 'organization': default_org.pubid, 'creator': creator, 'description': description, 'group_type': type_, 'name': name, 'origins': origins, 'members': [member_to_add.username] }) handle_form_submission.side_effect = call_on_success ctrl = GroupCreateController(pyramid_request) if type_ == 'open': create_method = group_svc.create_open_group else: create_method = group_svc.create_restricted_group create_method.return_value = factories.RestrictedGroup(pubid='testgroup') ctrl.post() expected_userid = User(username=creator, authority=pyramid_request.default_authority).userid create_method.assert_called_with(name=name, userid=expected_userid, description=description, origins=origins, organization=default_org) group_svc.add_members.assert_called_once_with(create_method.return_value, [member_to_add.userid])
def test_it_handles_form_submission(self, pyramid_request, handle_form_submission, matchers): ctrl = GroupCreateController(pyramid_request) ctrl.post() handle_form_submission.assert_called_once_with(ctrl.request, ctrl.form, matchers.AnyCallable(), ctrl._template_context)
def test_get_lists_all_organizations(self, pyramid_request, factories, default_org, CreateAdminGroupSchema, list_orgs_svc): GroupCreateController(pyramid_request) list_orgs_svc.organizations.assert_called_with() schema = CreateAdminGroupSchema.return_value (_, call_kwargs) = schema.bind.call_args assert call_kwargs['organizations'] == {default_org.pubid: default_org}
def test_post_redirects_to_list_view_on_success(self, pyramid_request, matchers, routes, handle_form_submission, default_org): def call_on_success(request, form, on_success, on_failure): return on_success({ 'name': 'My New Group', 'group_type': 'restricted', 'creator': pyramid_request.user.username, 'description': None, 'members': [], 'organization': default_org.pubid, 'origins': [], }) handle_form_submission.side_effect = call_on_success ctrl = GroupCreateController(pyramid_request) response = ctrl.post() expected_location = pyramid_request.route_url('admin.groups') assert response == matchers.Redirect302To(expected_location)
def test_get_sets_form(self, pyramid_request): ctrl = GroupCreateController(pyramid_request) ctx = ctrl.get() assert 'form' in ctx