diff options
-rw-r--r-- | testproject/settings.py | 5 | ||||
-rw-r--r-- | testproject/templates/sample.html | 7 | ||||
-rw-r--r-- | wkhtmltopdf/tests.py | 13 |
3 files changed, 25 insertions, 0 deletions
diff --git a/testproject/settings.py b/testproject/settings.py index f60fecd..0454766 100644 --- a/testproject/settings.py +++ b/testproject/settings.py @@ -1,3 +1,7 @@ +import os + +PROJECT_PATH = os.path.abspath(os.path.dirname(__file__)) + # Django settings for testproject project. DEBUG = True @@ -103,6 +107,7 @@ MIDDLEWARE_CLASSES = ( ROOT_URLCONF = 'testproject.urls' TEMPLATE_DIRS = ( + os.path.join(PROJECT_PATH, 'templates') # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. diff --git a/testproject/templates/sample.html b/testproject/templates/sample.html new file mode 100644 index 0000000..3dfbdbb --- /dev/null +++ b/testproject/templates/sample.html @@ -0,0 +1,7 @@ +<html> + <head> + </head> + <body> + <h1>{{ title }}</h1> + </body> +</html> diff --git a/wkhtmltopdf/tests.py b/wkhtmltopdf/tests.py index e69de29..5eb733f 100644 --- a/wkhtmltopdf/tests.py +++ b/wkhtmltopdf/tests.py @@ -0,0 +1,13 @@ +from django.test import TestCase + +from utils import template_to_temp_file + +class TestUtils(TestCase): + def test_template_to_temp_file(self): + """Should render a template to a temporary file.""" + title = 'A test template.' + temp_file = template_to_temp_file('sample.html', {'title': title}) + with open(temp_file, 'r') as f: + saved_content = f.read() + self.assertTrue(title in saved_content) + |