def test_post_creates_open_group_on_success( self, pyramid_request, group_create_svc, handle_form_submission, default_org, user_svc, base_appstruct, ): def call_on_success(request, form, on_success, on_failure): base_appstruct["group_type"] = "open" return on_success(base_appstruct) handle_form_submission.side_effect = call_on_success view = GroupCreateViews(pyramid_request) view.post() group_create_svc.create_open_group.assert_called_with( name="My New Group", userid=user_svc.fetch.return_value.userid, description=None, origins=["http://example.com"], organization=default_org, enforce_scope=True, )
def test_post_creates_open_group_on_success( self, pyramid_request, group_create_svc, handle_form_submission, default_org, user_svc, base_appstruct, ): def call_on_success(request, form, on_success, on_failure): base_appstruct["group_type"] = "open" return on_success(base_appstruct) handle_form_submission.side_effect = call_on_success view = GroupCreateViews(pyramid_request) view.post() group_create_svc.create_open_group.assert_called_with( name="My New Group", userid=user_svc.fetch.return_value.userid, description=None, scopes=["http://example.com"], organization=default_org, enforce_scope=True, )
def test_post_adds_members_on_success( self, factories, pyramid_request, group_create_svc, group_members_svc, handle_form_submission, user_svc, base_appstruct, ): user = factories.User() user_svc.fetch.return_value = user def call_on_success(request, form, on_success, on_failure): base_appstruct["members"] = ["someusername"] return on_success(base_appstruct) handle_form_submission.side_effect = call_on_success view = GroupCreateViews(pyramid_request) view.post() group_members_svc.add_members.assert_called_once_with( group_create_svc.create_restricted_group.return_value, [user.userid] )
def test_post_adds_members_on_success( self, factories, pyramid_request, group_create_svc, group_members_svc, handle_form_submission, user_svc, base_appstruct, ): user = factories.User() user_svc.fetch.return_value = user def call_on_success(request, form, on_success, on_failure): base_appstruct["members"] = ["someusername"] return on_success(base_appstruct) handle_form_submission.side_effect = call_on_success view = GroupCreateViews(pyramid_request) view.post() group_members_svc.add_members.assert_called_once_with( group_create_svc.create_restricted_group.return_value, [user.userid])
def test_post_creates_restricted_group_on_success( self, pyramid_request, group_create_service, handle_form_submission, organization, user_service, base_appstruct, ): def call_on_success( # pylint:disable=unused-argument request, form, on_success, on_failure): base_appstruct["group_type"] = "restricted" return on_success(base_appstruct) handle_form_submission.side_effect = call_on_success view = GroupCreateViews(pyramid_request) view.post() group_create_service.create_restricted_group.assert_called_with( name="My New Group", userid=user_service.fetch.return_value.userid, description=None, scopes=["http://example.com"], organization=organization, enforce_scope=True, )
def test_post_handles_form_submission(self, pyramid_request, handle_form_submission, matchers): view = GroupCreateViews(pyramid_request) view.post() handle_form_submission.assert_called_once_with(view.request, view.form, matchers.AnyCallable(), view._template_context)
def test_post_handles_form_submission(self, pyramid_request, handle_form_submission): view = GroupCreateViews(pyramid_request) view.post() handle_form_submission.assert_called_once_with(view.request, view.form, Any.function(), view._template_context)
def test_post_handles_form_submission( self, pyramid_request, handle_form_submission, matchers ): view = GroupCreateViews(pyramid_request) view.post() handle_form_submission.assert_called_once_with( view.request, view.form, matchers.AnyCallable(), view._template_context )
def test_post_redirects_to_list_view_on_success( self, pyramid_request, matchers, routes, handle_form_submission, base_appstruct ): def call_on_success(request, form, on_success, on_failure): return on_success(base_appstruct) handle_form_submission.side_effect = call_on_success view = GroupCreateViews(pyramid_request) response = view.post() expected_location = pyramid_request.route_url("admin.groups") assert response == matchers.Redirect302To(expected_location)
def test_init_binds_schema_with_organizations( self, pyramid_request, default_org, AdminGroupSchema, list_orgs_svc ): GroupCreateViews(pyramid_request) schema = AdminGroupSchema.return_value (_, call_kwargs) = schema.bind.call_args assert call_kwargs["organizations"] == {default_org.pubid: default_org}
def test_init_binds_schema_with_organizations(self, pyramid_request, organization, AdminGroupSchema): GroupCreateViews(pyramid_request) schema = AdminGroupSchema.return_value (_, call_kwargs) = schema.bind.call_args assert call_kwargs["organizations"] == { organization.pubid: organization }
def test_get_sets_form(self, pyramid_request): view = GroupCreateViews(pyramid_request) ctx = view.get() assert "form" in ctx
def test_init_fetches_all_organizations(self, pyramid_request, list_orgs_svc): GroupCreateViews(pyramid_request) list_orgs_svc.organizations.assert_called_with()