Skip to content

Commit

Permalink
Use common var to show origin of output timestamp
Browse files Browse the repository at this point in the history
Use new variable BUILDTIME to explicitly show that the RSS output
feed.updated field derives its value from the time the `nikola build`
was done.
  • Loading branch information
tartley committed Mar 30, 2023
1 parent a21288c commit 107a057
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions tests/integration/test_demo_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
settings.
"""

import datetime
import email
import itertools
import os
import time

import feedparser
import freezegun
Expand All @@ -26,19 +29,30 @@
test_index_in_sitemap,
)

BUILDTIME = datetime.datetime(2023, 4, 5, 23, 59, 58, tzinfo=datetime.timezone.utc)


class Any:
"""Compare equal with anything. Use for expected values we don't care about."""
def __eq__(self, _):
return True


def rfc822(t):
"""Format a datetime according to RFC822, eg 'Wed, 05 Apr 2023 23:59:58 GMT'"""
return email.utils.formatdate(
time.mktime(BUILDTIME.astimezone().timetuple()),
usegmt=True,
)


def test_gallery_rss(build, output_dir):
# Given a build of the demo samplesite in 'output_dir'
# When we look for the RSS file of the "Demo" gallery
# TODO Can I rely on the name of 'galleries' during tests,
# or should I be using/setting config->GALLERY_FOLDERS?
rss_path = os.path.join(output_dir, 'galleries', 'demo', 'rss.xml')

# Then it exists
assert os.path.isfile(rss_path)
# and it contains text
Expand All @@ -55,9 +69,9 @@ def test_gallery_rss(build, output_dir):
assert parsed.feed.link == 'https://example.com/galleries/demo/rss.xml'
# TODO Should the title be the name of the gallery, not the final image?
assert parsed.feed.title == 'Tesla tower1 lg'
# TODO Should the description be the content of its index.txt, converted to HTML?
assert parsed.feed.subtitle == '' # From the XML field 'description'
assert parsed.feed.updated == 'Wed, 05 Apr 2023 23:59:58 GMT'
# TODO Should the description be the content of the gallery's index.txt?
assert parsed.feed.subtitle == '' # From the XML field 'description'
assert parsed.feed.updated == rfc822(BUILDTIME)
# and the images, as items in the RSS feed, are:
expected_items = [
dict(
Expand Down Expand Up @@ -142,13 +156,14 @@ def test_gallery_rss(build, output_dir):
# Keys/values in 'expected' should be a subset of those in 'actual'.
assert expected.items() <= actual.items(), f'item {index} mismatch'


@pytest.fixture(scope="module")
def build(target_dir):
"""Fill the site with demo content and build it."""
prepare_demo_site(target_dir)

with cd(target_dir):
with freezegun.freeze_time("2023-04-05 23:59:58", tz_offset=0):
with freezegun.freeze_time(BUILDTIME):
__main__.main(["build"])


Expand Down

0 comments on commit 107a057

Please sign in to comment.