Beispiel #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,
            scopes=["http://example.com"],
            organization=default_org,
            enforce_scope=True,
        )
Beispiel #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,
            origins=["http://example.com"],
            organization=default_org,
            enforce_scope=True,
        )
Beispiel #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]
        )
Beispiel #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])
Beispiel #5
0
    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,
        )
Beispiel #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)
Beispiel #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)
Beispiel #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
        )
Beispiel #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)
Beispiel #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)