# Path: via/tweens.py
# def robots_tween_factory(handler, _registry):
#     def robots_tween(request):
#         response = handler(request)
# 
#         # If the view hasn't set its own X-Robots-Tag header then set one that
#         # tells Google (and most other crawlers) not to index the page and not
#         # to follow links on the page.
#         #
#         # https://developers.google.com/search/reference/robots_meta_tag
#         if "X-Robots-Tag" not in response.headers:
#             response.headers["X-Robots-Tag"] = "noindex, nofollow"
# 
#         return response
# 
#     return robots_tween


from unittest.mock import create_autospec
from via.tweens import robots_tween_factory
import pytest
    @pytest.mark.parametrize(
        "existing_header,expected_header",
        [
            (None, "noindex, nofollow"),
            ("all", "all"),
        ],
    )
    def test_it(
        self, existing_header, expected_header, handler, pyramid_request, tween
    ):
        if existing_header:
            handler.return_value.headers = {"X-Robots-Tag": existing_header}
        else:
            handler.return_value.headers = {}

        response = tween(pyramid_request)

        handler.assert_called_once_with(pyramid_request)
        assert response == handler.return_value
        assert response.headers["X-Robots-Tag"] == expected_header

    @pytest.fixture
    def handler(self):
        def handler_spec(request):
            """Spec for mock handler function."""

        return create_autospec(handler_spec)

    @pytest.fixture
    def tween(self, handler, pyramid_request):

# Path: via/tweens.py
# def robots_tween_factory(handler, _registry):
#     def robots_tween(request):
#         response = handler(request)
# 
#         # If the view hasn't set its own X-Robots-Tag header then set one that
#         # tells Google (and most other crawlers) not to index the page and not
#         # to follow links on the page.
#         #
#         # https://developers.google.com/search/reference/robots_meta_tag
#         if "X-Robots-Tag" not in response.headers:
#             response.headers["X-Robots-Tag"] = "noindex, nofollow"
# 
#         return response
# 
#     return robots_tween


# Path: tests/unit/via/tweens_test.py
from unittest.mock import create_autospec
from via.tweens import robots_tween_factory
import pytest

    @pytest.mark.parametrize(
        "existing_header,expected_header",
        [
            (None, "noindex, nofollow"),
            ("all", "all"),
        ],
    )
    def test_it(
        self, existing_header, expected_header, handler, pyramid_request, tween
    ):
        if existing_header:
            handler.return_value.headers = {"X-Robots-Tag": existing_header}
        else:
            handler.return_value.headers = {}

        response = tween(pyramid_request)

        handler.assert_called_once_with(pyramid_request)
        assert response == handler.return_value
        assert response.headers["X-Robots-Tag"] == expected_header

    @pytest.fixture
    def handler(self):
        def handler_spec(request):
            """Spec for mock handler function."""

        return create_autospec(handler_spec)

    @pytest.fixture
    def tween(self, handler, pyramid_request):

        return robots_tween_factory(handler, pyramid_request.registry)