-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
232 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "django-render-static" | ||
version = "3.0.1" | ||
version = "3.1.0" | ||
description = "Use Django's template engine to render static files at deployment or package time. Includes transpilers for extending Django's url reversal and enums to JavaScript." | ||
authors = ["Brian Kohan <[email protected]>"] | ||
license = "MIT" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
file.txt: {{ variable }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
file1_1.txt: {{ variable }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
file1_2.txt: {{ variable }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
file2_1.txt: {{ variable }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
file2_2.txt: {{ variable }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
from pathlib import Path | ||
|
||
from django.core.management import call_command | ||
from django.test import override_settings | ||
from .test_core import BaseTestCase, GLOBAL_STATIC_DIR | ||
|
||
BATCH_TEMPLATES = Path(__file__).parent / "batch_templates" | ||
|
||
context = {"variable": "template_rendered!"} | ||
|
||
|
||
@override_settings( | ||
STATIC_TEMPLATES={ | ||
"ENGINES": [ | ||
{ | ||
"BACKEND": "render_static.backends.StaticDjangoTemplates", | ||
"DIRS": [BATCH_TEMPLATES], | ||
"APP_DIRS": False, | ||
"OPTIONS": { | ||
"loaders": ["render_static.loaders.StaticFilesystemBatchLoader"] | ||
}, | ||
} | ||
] | ||
} | ||
) | ||
class TestBatch(BaseTestCase): | ||
def check_file(self, filename, rendered=True, exists=True): | ||
filename = GLOBAL_STATIC_DIR / filename | ||
if exists: | ||
self.assertTrue(filename.is_file()) | ||
if rendered: | ||
self.assertEqual( | ||
filename.read_text().strip(), | ||
f"{filename.name}: {context["variable"]}", | ||
) | ||
else: | ||
self.assertEqual( | ||
filename.read_text().strip(), f"{filename.name}: {{{{ variable }}}}" | ||
) | ||
else: | ||
self.assertFalse(filename.is_file()) | ||
|
||
def test_batch_glob_all_render_all(self): | ||
call_command( | ||
"renderstatic", | ||
"**/*", | ||
destination=GLOBAL_STATIC_DIR, | ||
context="tests.test_batch.context", | ||
) | ||
|
||
self.check_file("file.txt") | ||
self.check_file("folder1/file1_1.txt") | ||
self.check_file("folder1/file1_2.txt") | ||
self.check_file("folder2/file2_1.txt") | ||
self.check_file("folder2/file2_2.txt") | ||
|
||
def test_batch_glob_some_render_all(self): | ||
call_command( | ||
"renderstatic", | ||
"folder1/**", | ||
destination=GLOBAL_STATIC_DIR, | ||
context="tests.test_batch.context", | ||
) | ||
|
||
self.check_file("file.txt", exists=False) | ||
self.check_file("folder1/file1_1.txt") | ||
self.check_file("folder1/file1_2.txt") | ||
self.check_file("folder2/file2_1.txt", exists=False) | ||
self.check_file("folder2/file2_2.txt", exists=False) | ||
|
||
def test_batch_glob_all_exclude_some(self): | ||
call_command( | ||
"renderstatic", | ||
"**/*", | ||
destination=GLOBAL_STATIC_DIR, | ||
context="tests.test_batch.context", | ||
exclude=[BATCH_TEMPLATES / "file.txt", BATCH_TEMPLATES / "folder1"], | ||
) | ||
|
||
self.check_file("file.txt", exists=False) | ||
self.check_file("folder1/file1_1.txt", exists=False) | ||
self.check_file("folder1/file1_2.txt", exists=False) | ||
self.check_file("folder2/file2_1.txt") | ||
self.check_file("folder2/file2_2.txt") | ||
|
||
def test_batch_glob_all_exclude_some_no_render(self): | ||
call_command( | ||
"renderstatic", | ||
"**/*", | ||
destination=GLOBAL_STATIC_DIR, | ||
context="tests.test_batch.context", | ||
exclude=[BATCH_TEMPLATES / "folder2"], | ||
) | ||
call_command( | ||
"renderstatic", | ||
"folder2/*", | ||
destination=GLOBAL_STATIC_DIR, | ||
context="tests.test_batch.context", | ||
no_render_contents=True, | ||
) | ||
|
||
self.check_file("file.txt") | ||
self.check_file("folder1/file1_1.txt") | ||
self.check_file("folder1/file1_2.txt") | ||
self.check_file("folder2/file2_1.txt", rendered=False) | ||
self.check_file("folder2/file2_2.txt", rendered=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import pytest | ||
from django.test import override_settings | ||
|
||
try: | ||
from render_static.backends.jinja2 import StaticJinja2Templates | ||
from render_static.loaders.jinja2 import StaticFileSystemBatchLoader | ||
except ImportError: | ||
pytest.skip(allow_module_level=True, reason="Jinja2 is not installed") | ||
|
||
|
||
from .test_batch import TestBatch, BATCH_TEMPLATES | ||
|
||
|
||
@override_settings( | ||
STATIC_TEMPLATES={ | ||
"ENGINES": [ | ||
{ | ||
"BACKEND": "render_static.backends.jinja2.StaticJinja2Templates", | ||
"OPTIONS": { | ||
"loader": StaticFileSystemBatchLoader(searchpath=BATCH_TEMPLATES) | ||
}, | ||
} | ||
] | ||
} | ||
) | ||
class TestBatchJinja2(TestBatch): | ||
pass |