# Path: via/exceptions.py
# class BadURL(RequestBasedException):
#     """An invalid URL was discovered."""
# 
#     def __init__(self, message, requests_err=None, url=None):
#         super().__init__(message, requests_err)
#         self.url = url
# 
#     status_int = 400
# 
# Path: via/resources.py
# class PathURLResource(_URLResource):
#     """Resource for routes expecting urls from the path."""
# 
#     def url_from_path(self):
#         """Get the 'url' parameter from the path.
# 
#         :return: The URL as a string
#         :raise HTTPBadRequest: If the URL is missing or empty
#         :raise BadURL: If the URL is malformed
#         """
# 
#         url = self._request.path_qs[1:].strip()
#         if not url:
#             raise HTTPBadRequest("Required path part 'url` is missing")
# 
#         return self._normalise_url(url)
# 
# class QueryURLResource(_URLResource):
#     """Resource for routes expecting urls from the query."""
# 
#     def url_from_query(self):
#         """Get the 'url' parameter from the query.
# 
#         :return: The URL as a string
#         :raise HTTPBadRequest: If the URL is missing or empty
#         :raise BadURL: If the URL is malformed
#         """
#         try:
#             url = self._request.params["url"].strip()
#         except KeyError as err:
#             raise HTTPBadRequest("Required parameter 'url' missing") from err
# 
#         if not url:
#             raise HTTPBadRequest("Required parameter 'url' is blank")
# 
#         return self._normalise_url(url)
# 
# def get_original_url(context):
#     """Get the original URL from a provided context object (if any)."""
# 
#     if isinstance(context, QueryURLResource):
#         getter = context.url_from_query
#     elif isinstance(context, PathURLResource):
#         getter = context.url_from_path
#     else:
#         return None
# 
#     try:
#         return getter()
#     except BadURL as err:
#         return err.url
#     except HTTPBadRequest:
#         return None


from unittest.mock import create_autospec
from pyramid.httpexceptions import HTTPBadRequest
from via.exceptions import BadURL
from via.resources import PathURLResource, QueryURLResource, get_original_url
import pytest
        with pytest.raises(BadURL):
            context.url_from_query()

    @pytest.fixture
    def context(self, pyramid_request):
        return QueryURLResource(pyramid_request)


class TestPathURLResource:
    @pytest.mark.parametrize("url,expected", NORMALISED_URLS)
    def test_url_from_path_returns_url(self, context, pyramid_request, url, expected):
        pyramid_request.path_qs = f"/{url}"

        assert context.url_from_path() == expected

    @pytest.mark.parametrize("bad_path", ("/", "/  "))
    def test_url_from_path_raises_HTTPBadRequest_for_missing_urls(
        self, context, pyramid_request, bad_path
    ):
        pyramid_request.path_qs = bad_path

        with pytest.raises(HTTPBadRequest):
            context.url_from_path()

    @pytest.mark.parametrize("bad_url", BAD_URLS)
    def test_url_from_path_BadURL_for_malformed_urls(
        self, context, pyramid_request, bad_url
    ):
        pyramid_request.path_qs = f"/{bad_url}"


# Path: via/exceptions.py
# class BadURL(RequestBasedException):
#     """An invalid URL was discovered."""
# 
#     def __init__(self, message, requests_err=None, url=None):
#         super().__init__(message, requests_err)
#         self.url = url
# 
#     status_int = 400
# 
# Path: via/resources.py
# class PathURLResource(_URLResource):
#     """Resource for routes expecting urls from the path."""
# 
#     def url_from_path(self):
#         """Get the 'url' parameter from the path.
# 
#         :return: The URL as a string
#         :raise HTTPBadRequest: If the URL is missing or empty
#         :raise BadURL: If the URL is malformed
#         """
# 
#         url = self._request.path_qs[1:].strip()
#         if not url:
#             raise HTTPBadRequest("Required path part 'url` is missing")
# 
#         return self._normalise_url(url)
# 
# class QueryURLResource(_URLResource):
#     """Resource for routes expecting urls from the query."""
# 
#     def url_from_query(self):
#         """Get the 'url' parameter from the query.
# 
#         :return: The URL as a string
#         :raise HTTPBadRequest: If the URL is missing or empty
#         :raise BadURL: If the URL is malformed
#         """
#         try:
#             url = self._request.params["url"].strip()
#         except KeyError as err:
#             raise HTTPBadRequest("Required parameter 'url' missing") from err
# 
#         if not url:
#             raise HTTPBadRequest("Required parameter 'url' is blank")
# 
#         return self._normalise_url(url)
# 
# def get_original_url(context):
#     """Get the original URL from a provided context object (if any)."""
# 
#     if isinstance(context, QueryURLResource):
#         getter = context.url_from_query
#     elif isinstance(context, PathURLResource):
#         getter = context.url_from_path
#     else:
#         return None
# 
#     try:
#         return getter()
#     except BadURL as err:
#         return err.url
#     except HTTPBadRequest:
#         return None


# Path: tests/unit/via/resources_test.py
from unittest.mock import create_autospec
from pyramid.httpexceptions import HTTPBadRequest
from via.exceptions import BadURL
from via.resources import PathURLResource, QueryURLResource, get_original_url
import pytest

        with pytest.raises(BadURL):
            context.url_from_query()

    @pytest.fixture
    def context(self, pyramid_request):
        return QueryURLResource(pyramid_request)


class TestPathURLResource:
    @pytest.mark.parametrize("url,expected", NORMALISED_URLS)
    def test_url_from_path_returns_url(self, context, pyramid_request, url, expected):
        pyramid_request.path_qs = f"/{url}"

        assert context.url_from_path() == expected

    @pytest.mark.parametrize("bad_path", ("/", "/  "))
    def test_url_from_path_raises_HTTPBadRequest_for_missing_urls(
        self, context, pyramid_request, bad_path
    ):
        pyramid_request.path_qs = bad_path

        with pytest.raises(HTTPBadRequest):
            context.url_from_path()

    @pytest.mark.parametrize("bad_url", BAD_URLS)
    def test_url_from_path_BadURL_for_malformed_urls(
        self, context, pyramid_request, bad_url
    ):
        pyramid_request.path_qs = f"/{bad_url}"


        with pytest.raises(BadURL):