From ca86467f46a525bcfb7d57e83462830e362d1ec4 Mon Sep 17 00:00:00 2001 From: Joshua May Date: Sun, 13 Oct 2019 19:08:17 -0700 Subject: [PATCH] We can set the datetime from the outside for default_template --- sirius/coding/templating.py | 4 ++-- sirius/coding/test_image_coding_snapshots.py | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) 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 -- 2.47.3