# Path: via/checkmate.py
# class ViaCheckmateClient(CheckmateClient):
#     def __init__(self, request):
#         super().__init__(
#             host=request.registry.settings["checkmate_url"],
#             api_key=request.registry.settings["checkmate_api_key"],
#         )
#         self._request = request
# 
#     def raise_if_blocked(self, url):
#         """Raise a redirect to Checkmate if the URL is blocked.
# 
#         This will sensibly apply all ignore reasons and other configuration for
#         Checkmate.
# 
#         :param url: The URL to check
#         :raise HTTPTemporaryRedirect: If the URL is blocked
#         """
#         try:
#             blocked = self.check_url(
#                 url,
#                 allow_all=self._request.registry.settings["checkmate_allow_all"],
#                 blocked_for=self._request.params.get("via.blocked_for"),
#                 ignore_reasons=self._request.registry.settings[
#                     "checkmate_ignore_reasons"
#                 ],
#             )
# 
#         except CheckmateException:
#             blocked = None
# 
#         if blocked:
#             raise HTTPTemporaryRedirect(location=blocked.presentation_url)


from unittest.mock import create_autospec, patch, sentinel
from checkmatelib import CheckmateException
from checkmatelib.client import BlockResponse
from pyramid.httpexceptions import HTTPTemporaryRedirect
from via.checkmate import ViaCheckmateClient
import pytest
        pyramid_request.registry.settings = {
            "checkmate_allow_all": sentinel.checkmate_allow_all,
            "checkmate_ignore_reasons": sentinel.checkmate_ignore_reasons,
        }
        pyramid_request.params["via.blocked_for"] = sentinel.via_blocked_for

        client.raise_if_blocked(sentinel.url)

        check_url.assert_called_once_with(
            sentinel.url,
            allow_all=sentinel.checkmate_allow_all,
            blocked_for=sentinel.via_blocked_for,
            ignore_reasons=sentinel.checkmate_ignore_reasons,
        )

    def test_raise_if_blocked_can_block(self, client, check_url, block_response):
        check_url.return_value = block_response

        with pytest.raises(HTTPTemporaryRedirect) as exc:
            client.raise_if_blocked(sentinel.url)

        assert exc.value.location == block_response.presentation_url

    def test_raise_if_blocked_ignores_CheckmateExceptions(self, client, check_url):
        check_url.side_effect = CheckmateException

        client.raise_if_blocked(sentinel.url)

    @pytest.fixture
    def client(self, pyramid_request):

# Path: via/checkmate.py
# class ViaCheckmateClient(CheckmateClient):
#     def __init__(self, request):
#         super().__init__(
#             host=request.registry.settings["checkmate_url"],
#             api_key=request.registry.settings["checkmate_api_key"],
#         )
#         self._request = request
# 
#     def raise_if_blocked(self, url):
#         """Raise a redirect to Checkmate if the URL is blocked.
# 
#         This will sensibly apply all ignore reasons and other configuration for
#         Checkmate.
# 
#         :param url: The URL to check
#         :raise HTTPTemporaryRedirect: If the URL is blocked
#         """
#         try:
#             blocked = self.check_url(
#                 url,
#                 allow_all=self._request.registry.settings["checkmate_allow_all"],
#                 blocked_for=self._request.params.get("via.blocked_for"),
#                 ignore_reasons=self._request.registry.settings[
#                     "checkmate_ignore_reasons"
#                 ],
#             )
# 
#         except CheckmateException:
#             blocked = None
# 
#         if blocked:
#             raise HTTPTemporaryRedirect(location=blocked.presentation_url)


# Path: tests/unit/via/checkmate_test.py
from unittest.mock import create_autospec, patch, sentinel
from checkmatelib import CheckmateException
from checkmatelib.client import BlockResponse
from pyramid.httpexceptions import HTTPTemporaryRedirect
from via.checkmate import ViaCheckmateClient
import pytest

        pyramid_request.registry.settings = {
            "checkmate_allow_all": sentinel.checkmate_allow_all,
            "checkmate_ignore_reasons": sentinel.checkmate_ignore_reasons,
        }
        pyramid_request.params["via.blocked_for"] = sentinel.via_blocked_for

        client.raise_if_blocked(sentinel.url)

        check_url.assert_called_once_with(
            sentinel.url,
            allow_all=sentinel.checkmate_allow_all,
            blocked_for=sentinel.via_blocked_for,
            ignore_reasons=sentinel.checkmate_ignore_reasons,
        )

    def test_raise_if_blocked_can_block(self, client, check_url, block_response):
        check_url.return_value = block_response

        with pytest.raises(HTTPTemporaryRedirect) as exc:
            client.raise_if_blocked(sentinel.url)

        assert exc.value.location == block_response.presentation_url

    def test_raise_if_blocked_ignores_CheckmateExceptions(self, client, check_url):
        check_url.side_effect = CheckmateException

        client.raise_if_blocked(sentinel.url)

    @pytest.fixture
    def client(self, pyramid_request):

        return ViaCheckmateClient(pyramid_request)