Python http.HTTPStatus.METHOD_NOT_ALLOWED Examples

The following are 19 code examples of http.HTTPStatus.METHOD_NOT_ALLOWED(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module http.HTTPStatus , or try the search function .
Example #1
Source File: test_api.py    From dicomweb-client with MIT License 6 votes vote down vote up
def test_delete_instance_error(httpserver, client, cache_dir):
    study_instance_uid = '1.2.3'
    series_instance_uid = '1.2.4'
    sop_instance_uid = '1.2.5'
    httpserver.serve_content(
        content='',
        code=HTTPStatus.METHOD_NOT_ALLOWED,
        headers=''
    )
    with pytest.raises(HTTPError):
        client.delete_instance(study_instance_uid=study_instance_uid,
                               series_instance_uid=series_instance_uid,
                               sop_instance_uid=sop_instance_uid)
    assert len(httpserver.requests) == 1
    request = httpserver.requests[0]
    expected_path = (
        '/studies/{study_instance_uid}/series/{series_instance_uid}/instances'
        '/{sop_instance_uid}'.format(
            study_instance_uid=study_instance_uid,
            series_instance_uid=series_instance_uid,
            sop_instance_uid=sop_instance_uid,)
    )
    assert request.path == expected_path
    assert request.method == 'DELETE' 
Example #2
Source File: test_api.py    From dicomweb-client with MIT License 6 votes vote down vote up
def test_delete_series_error(httpserver, client, cache_dir):
    study_instance_uid = '1.2.3'
    series_instance_uid = '1.2.4'
    httpserver.serve_content(
        content='',
        code=HTTPStatus.METHOD_NOT_ALLOWED,
        headers=''
    )
    with pytest.raises(HTTPError):
        client.delete_series(study_instance_uid=study_instance_uid,
                             series_instance_uid=series_instance_uid)
    assert len(httpserver.requests) == 1
    request = httpserver.requests[0]
    expected_path = (
        '/studies/{study_instance_uid}/series/{series_instance_uid}'.format(
            study_instance_uid=study_instance_uid,
            series_instance_uid=series_instance_uid)
    )
    assert request.path == expected_path
    assert request.method == 'DELETE' 
Example #3
Source File: test_api.py    From dicomweb-client with MIT License 6 votes vote down vote up
def test_delete_study_error(httpserver, client, cache_dir):
    study_instance_uid = '1.2.3'
    httpserver.serve_content(
        content='',
        code=HTTPStatus.METHOD_NOT_ALLOWED,
        headers=''
    )
    with pytest.raises(HTTPError):
        client.delete_study(study_instance_uid=study_instance_uid)
    assert len(httpserver.requests) == 1
    request = httpserver.requests[0]
    expected_path = (
        '/studies/{study_instance_uid}'.format(
            study_instance_uid=study_instance_uid)
    )
    assert request.path == expected_path
    assert request.method == 'DELETE' 
Example #4
Source File: test_account.py    From maas with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_method_not_allowed_on_delete(self):
        response = self.client.delete(reverse("csrf"))
        self.assertThat(response, HasStatusCode(HTTPStatus.METHOD_NOT_ALLOWED)) 
Example #5
Source File: base.py    From zimfarm with GNU General Public License v3.0 5 votes vote down vote up
def delete(self, *args, **kwargs):
        return Response(status=HTTPStatus.METHOD_NOT_ALLOWED) 
Example #6
Source File: base.py    From zimfarm with GNU General Public License v3.0 5 votes vote down vote up
def patch(self, *args, **kwargs):
        return Response(status=HTTPStatus.METHOD_NOT_ALLOWED) 
Example #7
Source File: base.py    From zimfarm with GNU General Public License v3.0 5 votes vote down vote up
def put(self, *args, **kwargs):
        return Response(status=HTTPStatus.METHOD_NOT_ALLOWED) 
Example #8
Source File: base.py    From zimfarm with GNU General Public License v3.0 5 votes vote down vote up
def post(self, *args, **kwargs):
        return Response(status=HTTPStatus.METHOD_NOT_ALLOWED) 
Example #9
Source File: base.py    From zimfarm with GNU General Public License v3.0 5 votes vote down vote up
def get(self, *args, **kwargs):
        return Response(status=HTTPStatus.METHOD_NOT_ALLOWED) 
Example #10
Source File: api.py    From dicomweb-client with MIT License 5 votes vote down vote up
def _http_delete(self, url: str):
        '''Performs a HTTP DELETE request to the specified URL.

        Parameters
        ----------
        url: str
            unique resource locator

        Returns
        -------
        requests.models.Response
            HTTP response message
        '''
        @retrying.retry(
            retry_on_result=self._is_retriable_http_error,
            wait_exponential_multiplier=self._wait_exponential_multiplier,
            stop_max_attempt_number=self._max_attempts
        )
        def _invoke_delete_request(url: str) -> requests.models.Response:
            return self._session.delete(url)

        response = _invoke_delete_request(url)
        if response.status_code == HTTPStatus.METHOD_NOT_ALLOWED:
            logger.error(
              'Resource could not be deleted. The origin server may not support'
              'deletion or you may not have the necessary permissions.')
        response.raise_for_status()
        return response 
Example #11
Source File: exceptions.py    From quart with MIT License 5 votes vote down vote up
def __init__(self, allowed_methods: Optional[Iterable[str]] = None) -> None:
        super().__init__(HTTPStatus.METHOD_NOT_ALLOWED)
        self.allowed_methods = allowed_methods 
Example #12
Source File: test_account.py    From maas with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_method_not_allowed_on_put(self):
        response = self.client.put(reverse("csrf"))
        self.assertThat(response, HasStatusCode(HTTPStatus.METHOD_NOT_ALLOWED)) 
Example #13
Source File: test_account.py    From maas with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_method_not_allowed_on_get(self):
        response = self.client.get(reverse("csrf"))
        self.assertThat(response, HasStatusCode(HTTPStatus.METHOD_NOT_ALLOWED)) 
Example #14
Source File: test_account.py    From maas with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_rejects_GET(self):
        response = self.client.get(reverse("authenticate"))
        self.assertThat(response, HasStatusCode(HTTPStatus.METHOD_NOT_ALLOWED))
        self.assertThat(response["Allow"], Equals("POST")) 
Example #15
Source File: test_account.py    From maas with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_logout_GET_returns_405(self):
        password = factory.make_string()
        user = factory.make_User(password=password)
        self.client.handler.enforce_csrf_checks = True
        self.client.login(username=user.username, password=password)
        self.client.handler.enforce_csrf_checks = False
        response = self.client.get(reverse("logout"))
        self.assertThat(
            response, HasStatusCode(http.client.METHOD_NOT_ALLOWED)
        ) 
Example #16
Source File: wsgi.py    From pywebview with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def do_405(environ, start_response):
    """
    Generic app to produce a 405
    """
    urlpath = environ['SCRIPT_NAME'] + environ['PATH_INFO']

    return send_simple_text(
        environ, start_response, HTTPStatus.METHOD_NOT_ALLOWED,
        "Method {} is not allowed on {}".format(
            environ['REQUEST_METHOD'], urlpath,
        ),
    ) 
Example #17
Source File: responses.py    From maubot with GNU Affero General Public License v3.0 5 votes vote down vote up
def method_not_allowed(self) -> web.Response:
        return web.json_response({
            "error": "Method not allowed",
            "errcode": "method_not_allowed",
        }, status=HTTPStatus.METHOD_NOT_ALLOWED) 
Example #18
Source File: router.py    From waspy with Apache License 2.0 5 votes vote down vote up
def _send_405(request):
    raise ResponseError(status=HTTPStatus.METHOD_NOT_ALLOWED) 
Example #19
Source File: jsonapi.py    From safrs with GNU General Public License v3.0 4 votes vote down vote up
def delete(self, **kwargs):
        """
            summary: Delete {class_name} from {collection_name}
            responses :
                202 :
                    description: Accepted
                204 :
                    description: Request fulfilled, nothing follows
                200 :
                    description: Success
                403 :
                    description: Forbidden
                404 :
                    description: Not Found

            ---
            Delete an object by id or by filter

            http://jsonapi.org/format/1.1/#crud-deleting:
            Responses :
                202 : Accepted
                If a deletion request has been accepted for processing,
                but the processing has not been completed by the time the server
                responds, the server MUST return a 202 Accepted status code.

                204 No Content
                A server MUST return a 204 No Content status code if a deletion
                request is successful and no content is returned.

                200 OK
                A server MUST return a 200 OK status code if a deletion request
                is successful and the server responds with only top-level meta data.

                404 NOT FOUND
                A server SHOULD return a 404 Not Found status code
                if a deletion request fails due to the resource not existing.
        """
        id = kwargs.get(self._s_object_id, None)

        if not id:
            # This endpoint shouldn't be exposed so this code is not reachable
            raise ValidationError("", status_code=HTTPStatus.METHOD_NOT_ALLOWED)

        instance = self.SAFRSObject.get_instance(id)
        safrs.DB.session.delete(instance)

        return {}, HTTPStatus.NO_CONTENT