From f1ba1f99fe22b010cc669dc9cd5c9ed4e96c768b Mon Sep 17 00:00:00 2001 From: sonny Date: Mon, 20 Jul 2020 23:24:31 +0200 Subject: [PATCH] Update existing tests & add reddit image post --- .../collection/tests/reddit/builder/mocks.py | 2 +- .../collection/tests/reddit/builder/tests.py | 48 +++++++++++++++---- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/newsreader/news/collection/tests/reddit/builder/mocks.py b/src/newsreader/news/collection/tests/reddit/builder/mocks.py index b565674..1ca3a50 100644 --- a/src/newsreader/news/collection/tests/reddit/builder/mocks.py +++ b/src/newsreader/news/collection/tests/reddit/builder/mocks.py @@ -741,7 +741,7 @@ unsanitized_mock = { "author_flair_richtext": [], "gildings": {}, "content_categories": None, - "is_self": False, + "is_self": True, "mod_note": None, "crosspost_parent_list": [ { diff --git a/src/newsreader/news/collection/tests/reddit/builder/tests.py b/src/newsreader/news/collection/tests/reddit/builder/tests.py index 528edb3..b9ecb8e 100644 --- a/src/newsreader/news/collection/tests/reddit/builder/tests.py +++ b/src/newsreader/news/collection/tests/reddit/builder/tests.py @@ -87,7 +87,7 @@ class RedditBuilderTestCase(TestCase): def test_update_posts(self): subreddit = SubredditFactory() existing_post = RedditPostFactory( - remote_identifier="hngsj8", + remote_identifier="hm0qct", author="Old author", title="Old title", body="Old body", @@ -109,17 +109,24 @@ class RedditBuilderTestCase(TestCase): existing_post.refresh_from_db() - self.assertEquals(existing_post.remote_identifier, "hngsj8") - self.assertEquals(existing_post.author, "nixcraft") - self.assertEquals(existing_post.title, "KeePassXC 2.6.0 released") - self.assertEquals(existing_post.body, "") + self.assertEquals(existing_post.remote_identifier, "hm0qct") + self.assertEquals(existing_post.author, "AutoModerator") + self.assertEquals( + existing_post.title, + "Linux Experiences/Rants or Education/Certifications thread - July 06, 2020", + ) + self.assertIn( + "This megathread is also to hear opinions from anyone just starting out " + "with Linux or those that have used Linux (GNU or otherwise) for a long time.", + existing_post.body, + ) self.assertEquals( existing_post.publication_date, - pytz.utc.localize(datetime(2020, 7, 8, 15, 11, 6)), + pytz.utc.localize(datetime(2020, 7, 6, 6, 11, 22)), ) self.assertEquals( existing_post.url, - "https://www.reddit.com/r/linux/comments/hngsj8/" "keepassxc_260_released/", + "https://www.reddit.com/r/linux/comments/hm0qct/linux_experiencesrants_or_educationcertifications/", ) def test_html_sanitizing(self): @@ -221,9 +228,32 @@ class RedditBuilderTestCase(TestCase): "Linux Experiences/Rants or Education/Certifications thread - July 06, 2020", ) - @skip("Not implemented") def test_image_post(self): - pass + builder = RedditBuilder + + subreddit = SubredditFactory() + mock_stream = MagicMock(rule=subreddit) + + with builder((image_mock, mock_stream)) as builder: + builder.save() + + posts = {post.remote_identifier: post for post in Post.objects.all()} + + self.assertCountEqual(("hr64xh", "hr4bxo", "hr14y5", "hr2fv0"), posts.keys()) + + post = posts["hr64xh"] + + title = ( + "Ya’ll, I just can’t... this is my " + "son, Judah. My wife and I have no " + "idea how we created such a " + "beautiful child." + ) + url = "https://i.redd.it/cm2qybia1va51.jpg" + + self.assertEquals( + f'
{title}
', post.body + ) @skip("Not implemented") def test_external_image_post(self):