示例#1
0
    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,
        )
示例#2
0
    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,
        )
示例#3
0
    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]
        )
示例#4
0
    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])
示例#5
0
文件: groups_test.py 项目: kaydoh/h
    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,
        )
示例#6
0
    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)
示例#7
0
    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)
示例#8
0
    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
        )
示例#9
0
    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)
示例#10
0
    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)
示例#11
0
    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}
示例#12
0
文件: groups_test.py 项目: kaydoh/h
    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
        }
示例#13
0
    def test_get_sets_form(self, pyramid_request):
        view = GroupCreateViews(pyramid_request)

        ctx = view.get()

        assert "form" in ctx
示例#14
0
    def test_init_fetches_all_organizations(self, pyramid_request,
                                            list_orgs_svc):
        GroupCreateViews(pyramid_request)

        list_orgs_svc.organizations.assert_called_with()
示例#15
0
    def test_get_sets_form(self, pyramid_request):
        view = GroupCreateViews(pyramid_request)

        ctx = view.get()

        assert "form" in ctx