Exemplo n.º 1
0
    def test_delete_removes_authclient(self, authclient, matchers, pyramid_request):
        pyramid_request.db.delete = create_autospec(
            pyramid_request.db.delete, return_value=None
        )
        ctrl = AuthClientEditController(authclient, pyramid_request)

        ctrl.delete()

        pyramid_request.db.delete.assert_called_with(authclient)
Exemplo n.º 2
0
    def test_delete_redirects_to_index(self, authclient, matchers, pyramid_request):
        pyramid_request.db.delete = create_autospec(
            pyramid_request.db.delete, return_value=None
        )
        ctrl = AuthClientEditController(authclient, pyramid_request)

        response = ctrl.delete()

        expected_location = pyramid_request.route_url("admin.oauthclients")
        assert response == matchers.Redirect302To(expected_location)
Exemplo n.º 3
0
    def test_update_updates_authclient(self, authclient, form_post, pyramid_request):
        form_post["client_id"] = authclient.id
        form_post["client_secret"] = authclient.secret
        pyramid_request.POST = form_post
        ctrl = AuthClientEditController(authclient, pyramid_request)

        ctx = ctrl.update()

        assert authclient.name == "new-name"
        assert ctx["form"] == self._expected_form(authclient)
Exemplo n.º 4
0
    def test_update_sets_response_type(
        self, authclient, form_post, pyramid_request, grant_type, expected_response_type
    ):
        pyramid_request.POST = form_post
        pyramid_request.POST["grant_type"] = grant_type
        ctrl = AuthClientEditController(authclient, pyramid_request)

        ctrl.update()

        assert authclient.response_type == expected_response_type
Exemplo n.º 5
0
    def test_update_updates_authclient(self, authclient, form_post,
                                       pyramid_request):
        form_post["client_id"] = authclient.id
        form_post["client_secret"] = authclient.secret
        pyramid_request.POST = form_post
        ctrl = AuthClientEditController(authclient, pyramid_request)

        ctx = ctrl.update()

        assert authclient.name == "new-name"
        assert ctx["form"] == self._expected_form(authclient)
Exemplo n.º 6
0
    def test_update_sets_response_type(self, auth_client, form_post,
                                       pyramid_request, grant_type,
                                       expected_type):
        pyramid_request.POST = form_post
        pyramid_request.POST["grant_type"] = grant_type
        controller = AuthClientEditController(sentinel.context,
                                              pyramid_request)

        controller.update()

        assert auth_client.response_type == expected_type
Exemplo n.º 7
0
    def test_update_updates_auth_client(self, auth_client, form_post,
                                        pyramid_request):
        form_post["client_id"] = auth_client.id
        form_post["client_secret"] = auth_client.secret
        pyramid_request.POST = form_post
        controller = AuthClientEditController(sentinel.context,
                                              pyramid_request)

        response = controller.update()

        assert auth_client.name == "new-name"
        assert response["form"] == self._expected_form(auth_client)
Exemplo n.º 8
0
    def test_update_does_not_update_read_only_fields(self, authclient, form_post, pyramid_request):
        # Attempt to modify read-only ID and secret fields.
        old_id = authclient.id
        old_secret = authclient.secret
        form_post['client_id'] = 'new-id'
        form_post['client_secret'] = 'new-secret'
        pyramid_request.POST = form_post
        ctrl = AuthClientEditController(authclient, pyramid_request)

        ctx = ctrl.update()

        assert authclient.id == old_id
        assert authclient.secret == old_secret
        assert ctx['form'] == self._expected_form(authclient)
Exemplo n.º 9
0
    def test_update_does_not_update_read_only_fields(
        self, authclient, form_post, pyramid_request
    ):
        # Attempt to modify read-only ID and secret fields.
        old_id = authclient.id
        old_secret = authclient.secret
        form_post["client_id"] = "new-id"
        form_post["client_secret"] = "new-secret"
        pyramid_request.POST = form_post
        ctrl = AuthClientEditController(authclient, pyramid_request)

        ctx = ctrl.update()

        assert authclient.id == old_id
        assert authclient.secret == old_secret
        assert ctx["form"] == self._expected_form(authclient)
Exemplo n.º 10
0
    def test_update_does_not_update_read_only_fields(self, auth_client,
                                                     form_post,
                                                     pyramid_request):
        # Attempt to modify read-only ID and secret fields.
        old_id = auth_client.id
        old_secret = auth_client.secret
        form_post["client_id"] = "new-id"
        form_post["client_secret"] = "new-secret"
        pyramid_request.POST = form_post
        controller = AuthClientEditController(sentinel.context,
                                              pyramid_request)

        response = controller.update()

        assert auth_client.id == old_id
        assert auth_client.secret == old_secret
        assert response["form"] == self._expected_form(auth_client)
Exemplo n.º 11
0
    def test_read_renders_form(self, authclient, pyramid_request):
        ctrl = AuthClientEditController(authclient, pyramid_request)

        ctx = ctrl.read()

        assert ctx['form'] == self._expected_form(authclient)
Exemplo n.º 12
0
    def test_read_renders_form(self, authclient, pyramid_request):
        ctrl = AuthClientEditController(authclient, pyramid_request)

        ctx = ctrl.read()

        assert ctx["form"] == self._expected_form(authclient)
Exemplo n.º 13
0
    def test_it_returns_HTTPNotFound_if_the_client_id_is_invalid(
            self, pyramid_request):
        pyramid_request.matchdict["id"] = "scrambled_id"

        with pytest.raises(HTTPNotFound):
            AuthClientEditController(sentinel.context, pyramid_request)
Exemplo n.º 14
0
    def test_it_returns_HTTPNotFound_if_the_client_is_missing(
            self, pyramid_request, db_session, auth_client):
        db_session.delete(auth_client)

        with pytest.raises(HTTPNotFound):
            AuthClientEditController(sentinel.context, pyramid_request)
Exemplo n.º 15
0
    def test_it_gets_the_client_from_the_id(self, pyramid_request,
                                            auth_client):
        controller = AuthClientEditController(sentinel.context,
                                              pyramid_request)

        assert controller.client == auth_client