from tests.BaseTestWithDB import BaseTestWithDB
from django.test import tag
from django.http import QueryDict
from django.urls import reverse
from resources.views.views import resource_pdf_cache
from tests.resources.ResourcesTestDataGenerator import ResourcesTestDataGenerator
from utils.get_resource_generator import get_resource_generator


@tag("resource")
class CacheRedirectTest(BaseTestWithDB):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.test_data = ResourcesTestDataGenerator()

    def test_resources_cache_valid_resource(self):
        resource = self.test_data.create_resource(
            "grid",
            "Grid",
            "resources/grid.html",
            "GridResourceGenerator",
        )
        query = QueryDict("paper_size=a4")
        generator = get_resource_generator(resource.generator_module, query)
        response = resource_pdf_cache(resource.name, generator)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(
            response.url,
            "/staticfiles/resources/Resource%20Grid%20(a4).pdf"
        )

Add test for resource cache function
Add test for resource cache function
