From a21ed181fee5b999a2b03ce028440bf568d47fb8 Mon Sep 17 00:00:00 2001 From: Adnan Umer Date: Mon, 17 Apr 2017 15:53:56 +0500 Subject: [PATCH] Unit Tests for CachedLoader --- tenant_schemas/tests/__init__.py | 5 +-- .../tests/template_loader/__init__.py | 1 + .../template_loader/templates/hello.html | 1 + .../test_cached_template_loader.py | 31 +++++++++++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 tenant_schemas/tests/template_loader/__init__.py create mode 100755 tenant_schemas/tests/template_loader/templates/hello.html create mode 100755 tenant_schemas/tests/template_loader/test_cached_template_loader.py diff --git a/tenant_schemas/tests/__init__.py b/tenant_schemas/tests/__init__.py index 09a3f81..2b6c0f2 100644 --- a/tenant_schemas/tests/__init__.py +++ b/tenant_schemas/tests/__init__.py @@ -1,5 +1,6 @@ -from .test_routes import * -from .test_tenants import * +from .template_loader import * from .test_cache import * from .test_log import * +from .test_routes import * +from .test_tenants import * from .test_utils import * diff --git a/tenant_schemas/tests/template_loader/__init__.py b/tenant_schemas/tests/template_loader/__init__.py new file mode 100644 index 0000000..ac17d9d --- /dev/null +++ b/tenant_schemas/tests/template_loader/__init__.py @@ -0,0 +1 @@ +from .test_cached_template_loader import CachedLoaderTests diff --git a/tenant_schemas/tests/template_loader/templates/hello.html b/tenant_schemas/tests/template_loader/templates/hello.html new file mode 100755 index 0000000..7f54a62 --- /dev/null +++ b/tenant_schemas/tests/template_loader/templates/hello.html @@ -0,0 +1 @@ +Hello! (Django templates) diff --git a/tenant_schemas/tests/template_loader/test_cached_template_loader.py b/tenant_schemas/tests/template_loader/test_cached_template_loader.py new file mode 100755 index 0000000..39facfe --- /dev/null +++ b/tenant_schemas/tests/template_loader/test_cached_template_loader.py @@ -0,0 +1,31 @@ +import os + +from django.template.loader import get_template +from django.test import SimpleTestCase, override_settings + + +@override_settings( + TEMPLATES=[ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [ + os.path.join(os.path.dirname(__file__), "templates") + ], + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.request', + ], + 'loaders': [ + ('tenant_schemas.template_loaders.CachedLoader', ( + 'tenant_schemas.template_loaders.FilesystemLoader', + 'django.template.loaders.filesystem.Loader' + )) + ] + }, + } + ] +) +class CachedLoaderTests(SimpleTestCase): + def test_get_template(self): + template = get_template("hello.html") + self.assertEqual(template.render(), "Hello! (Django templates)\n")