]> git.aero2k.de Git - sirius.git/commitdiff
We can set the datetime from the outside for default_template
authorJoshua May <notjosh@gmail.com>
Mon, 14 Oct 2019 02:08:17 +0000 (19:08 -0700)
committerJoshua May <notjosh@gmail.com>
Mon, 14 Oct 2019 02:08:17 +0000 (19:08 -0700)
sirius/coding/templating.py
sirius/coding/test_image_coding_snapshots.py

index 188ad4dce387fa4cfb22a5a9480d64f641806599..ed52023183b882bf4e75c6e875d77028dbd017fb 100644 (file)
@@ -8,13 +8,13 @@ ENV = jinja2.Environment()
 # TODO apply scrubber library if wanted.
 # https://pypi.python.org/pypi/scrubber
 
-def default_template(raw_html, from_name):
+def default_template(raw_html, from_name, date=datetime.datetime.now()):
     with open(DEFAULT_TEMPLATE_FILE) as f:
         template = f.read()
 
     t = ENV.from_string(template)
     return t.render(
         raw_html=raw_html,
-        date=datetime.datetime.now(),
+        date=date,
         from_name=from_name
     )
index 7c0f8586a195ede5ae40a27ffe937c97f59100e4..d6e920a638a556559b41d06402868fc4a2eb7e67 100644 (file)
@@ -1,4 +1,5 @@
 import os
+import datetime
 from tempfile import TemporaryDirectory
 from PIL import Image
 
@@ -34,5 +35,14 @@ class ImageCodingSnapshotCase(snapshottest.TestCase):
             'hello_world': '<p>Hello, world!</p>',
         }
 
+        fixture_username = 'somebody'
+        fixture_date = datetime.datetime(2012, 2, 3, 15, 46, 12)
+
         for name, snippet in fixtures.items():
-            self._check_html(name, templating.default_template(snippet, 'anonymous'))
\ No newline at end of file
+            self._check_html(
+                name, templating.default_template(
+                    snippet,
+                    fixture_username,
+                    fixture_date
+                )
+            )
\ No newline at end of file