diff options
| author | 2024-04-23 00:37:58 -0400 | |
|---|---|---|
| committer | 2024-04-23 00:37:58 -0400 | |
| commit | 9b0e86a8e74768c4fe848fb5ce8d754292db4e3e (patch) | |
| tree | cfd424be8ecb68357e6e572033f08bc534bf724f /tests/integration/test_demo_build.py | |
| parent | 393aa58f2c5afd51f92fd9bd4b6dfd0dc90cea41 (diff) | |
New upstream version 8.3.0.upstream/8.3.0upstream
Diffstat (limited to 'tests/integration/test_demo_build.py')
| -rw-r--r-- | tests/integration/test_demo_build.py | 136 |
1 files changed, 135 insertions, 1 deletions
diff --git a/tests/integration/test_demo_build.py b/tests/integration/test_demo_build.py index 57a1807..3a36d28 100644 --- a/tests/integration/test_demo_build.py +++ b/tests/integration/test_demo_build.py @@ -7,8 +7,14 @@ In this case these are tested against the demo site with default settings. """ +import datetime +import email +import itertools import os +import time +import feedparser +import freezegun import pytest import nikola.plugins.command.init @@ -23,6 +29,133 @@ from .test_empty_build import ( # NOQA 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 + rss_path = os.path.join(output_dir, 'galleries', 'demo', 'rss.xml') + + # Then it exists + assert os.path.isfile(rss_path) + # and it contains text + with open(rss_path) as fp: + content = fp.read() + assert isinstance(content, str) + assert len(content) > 0 + # and the text can be parsed as valid RSS + parsed = feedparser.parse(content) + # and the RSS contains top level attributes: + assert parsed.version == 'rss20' + # and the RSS contains feed attributes, about the gallery: + assert parsed.feed.language == 'en' + assert parsed.feed.link == 'https://example.com/galleries/demo/rss.xml' + # TODO I think the following is a bug: The feed title should be the Gallery name, + # not the name of the gallery's final image. + assert parsed.feed.title == 'Tesla tower1 lg' + # TODO I think the following is a bug: The feed's subtitle (aka description) should + # contain 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( + id='galleries/demo/tesla4_lg.jpg', + link='https://example.com/galleries/demo/tesla4_lg.jpg', + links=[ + Any(), + dict( + href='https://example.com/galleries/demo/tesla4_lg.jpg', + length='30200', + rel='enclosure', + type='image/jpeg', + ), + ], + published='Wed, 01 Jan 2014 00:01:00 GMT', + title='Tesla4 lg', + ), + dict( + id='galleries/demo/tesla_conducts_lg.webp', + link='https://example.com/galleries/demo/tesla_conducts_lg.webp', + links=[ + Any(), + dict( + href='https://example.com/galleries/demo/tesla_conducts_lg.webp', + length='9620', + rel='enclosure', + type='image/webp', + ), + ], + published='Wed, 01 Jan 2014 00:02:00 GMT', + title='Tesla conducts lg', + ), + dict( + id='galleries/demo/tesla_lightning1_lg.jpg', + link='https://example.com/galleries/demo/tesla_lightning1_lg.jpg', + links=[ + Any(), + dict( + href='https://example.com/galleries/demo/tesla_lightning1_lg.jpg', + length='41123', + rel='enclosure', + type='image/jpeg', + ), + ], + published='Wed, 01 Jan 2014 00:03:00 GMT', + title='Tesla lightning1 lg', + ), + dict( + id='galleries/demo/tesla_lightning2_lg.jpg', + link='https://example.com/galleries/demo/tesla_lightning2_lg.jpg', + links=[ + Any(), + dict( + href='https://example.com/galleries/demo/tesla_lightning2_lg.jpg', + length='36994', + rel='enclosure', + type='image/jpeg', + ), + ], + published='Wed, 01 Jan 2014 00:04:00 GMT', + title='Tesla lightning2 lg', + ), + dict( + id='galleries/demo/tesla_tower1_lg.jpg', + link='https://example.com/galleries/demo/tesla_tower1_lg.jpg', + links=[ + Any(), + dict( + href='https://example.com/galleries/demo/tesla_tower1_lg.jpg', + length='18105', + rel='enclosure', + type='image/jpeg', + ) + ], + published='Wed, 01 Jan 2014 00:05:00 GMT', + title='Tesla tower1 lg', + ), + ] + for index, (actual, expected) in enumerate( + itertools.zip_longest(parsed.entries, expected_items) + ): + for key, value in expected.items(): + assert actual[key] == value, f'item [{index}][{key!r}] {actual}' + @pytest.fixture(scope="module") def build(target_dir): @@ -30,7 +163,8 @@ def build(target_dir): prepare_demo_site(target_dir) with cd(target_dir): - __main__.main(["build"]) + with freezegun.freeze_time(BUILDTIME): + __main__.main(["build"]) def prepare_demo_site(target_dir): |
