# Path: tests/project/drf/request.py
# class FakeRequest:
#     def __init__(self, headers: Optional[Mapping[str, str]] = None) -> None:
#         self.headers = headers or {}
# 
#     @classmethod
#     def fake(cls, *args: Any, **kwargs: Any) -> Request:
#         return cast(Request, cls(*args, **kwargs))


import datetime
import operator
from unittest import TestCase
from django.core.exceptions import ImproperlyConfigured
from django.test.utils import isolate_apps, override_settings
from django.utils.http import http_date
from drf_yasg import openapi
from rest_framework.exceptions import ErrorDetail
from bananas.drf.errors import BadRequest
from bananas.drf.fencing import (
    Fence,
    allow_if_unmodified_since,
    as_set,
    header_date_parser,
    header_etag_parser,
    parse_date_modified,
)
from bananas.models import TimeStampedModel
from tests.project.drf.request import FakeRequest




class TestFence(TestCase):
    openapi_parameter = openapi.Parameter(
        in_=openapi.IN_HEADER,
        name="foo",
        type=openapi.TYPE_STRING,
    )

    def test_check_propagates_error_from_get_token(self):
        error = RuntimeError()

        def get_token(_request):
            raise error

        def get_version(_instance):
            return "a"

        fence = Fence(
            get_token=get_token,
            compare=operator.eq,
            get_version=get_version,
            openapi_parameter=self.openapi_parameter,
        )

        with self.assertRaises(RuntimeError) as exc_info:

# Path: tests/project/drf/request.py
# class FakeRequest:
#     def __init__(self, headers: Optional[Mapping[str, str]] = None) -> None:
#         self.headers = headers or {}
# 
#     @classmethod
#     def fake(cls, *args: Any, **kwargs: Any) -> Request:
#         return cast(Request, cls(*args, **kwargs))


# Path: tests/tests/drf/test_fencing.py
import datetime
import operator
from unittest import TestCase
from django.core.exceptions import ImproperlyConfigured
from django.test.utils import isolate_apps, override_settings
from django.utils.http import http_date
from drf_yasg import openapi
from rest_framework.exceptions import ErrorDetail
from bananas.drf.errors import BadRequest
from bananas.drf.fencing import (
    Fence,
    allow_if_unmodified_since,
    as_set,
    header_date_parser,
    header_etag_parser,
    parse_date_modified,
)
from bananas.models import TimeStampedModel
from tests.project.drf.request import FakeRequest





class TestFence(TestCase):
    openapi_parameter = openapi.Parameter(
        in_=openapi.IN_HEADER,
        name="foo",
        type=openapi.TYPE_STRING,
    )

    def test_check_propagates_error_from_get_token(self):
        error = RuntimeError()

        def get_token(_request):
            raise error

        def get_version(_instance):
            return "a"

        fence = Fence(
            get_token=get_token,
            compare=operator.eq,
            get_version=get_version,
            openapi_parameter=self.openapi_parameter,
        )

        with self.assertRaises(RuntimeError) as exc_info:

            fence.check(FakeRequest.fake(), "a")