From: Joshua May Date: Mon, 14 Oct 2019 02:08:17 +0000 (-0700) Subject: We can set the datetime from the outside for default_template X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=ca86467f46a525bcfb7d57e83462830e362d1ec4;p=sirius.git We can set the datetime from the outside for default_template --- diff --git a/sirius/coding/templating.py b/sirius/coding/templating.py index 188ad4d..ed52023 100644 --- a/sirius/coding/templating.py +++ b/sirius/coding/templating.py @@ -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 ) diff --git a/sirius/coding/test_image_coding_snapshots.py b/sirius/coding/test_image_coding_snapshots.py index 7c0f858..d6e920a 100644 --- a/sirius/coding/test_image_coding_snapshots.py +++ b/sirius/coding/test_image_coding_snapshots.py @@ -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': '

Hello, world!

', } + 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