diff --git a/src/newsreader/news/collection/tests/reddit/builder/mocks.py b/src/newsreader/news/collection/tests/reddit/builder/mocks.py index e163e44..625ced3 100644 --- a/src/newsreader/news/collection/tests/reddit/builder/mocks.py +++ b/src/newsreader/news/collection/tests/reddit/builder/mocks.py @@ -3733,3 +3733,168 @@ external_gifv_mock = { }, "kind": "Listing", } + +unknown_mock = { + "data": { + "after": "t3_hr3mhe", + "before": None, + "children": [ + { + "kind": "t1", + "data": { + "approved_at_utc": None, + "subreddit": "aww", + "selftext": "", + "author_fullname": "t2_ygx0p1u", + "saved": False, + "mod_reason_title": None, + "gilded": 0, + "clicked": False, + "title": "if i fits i sits", + "link_flair_richtext": [], + "subreddit_name_prefixed": "r/aww", + "hidden": False, + "pwls": 6, + "link_flair_css_class": None, + "downs": 0, + "thumbnail_height": 74, + "top_awarded_type": None, + "hide_score": False, + "name": "t3_humdlf", + "quarantine": False, + "link_flair_text_color": "dark", + "upvote_ratio": 0.97, + "author_flair_background_color": "", + "subreddit_type": "public", + "ups": 7512, + "total_awards_received": 1, + "media_embed": {}, + "thumbnail_width": 140, + "author_flair_template_id": None, + "is_original_content": False, + "user_reports": [], + "secure_media": None, + "is_reddit_media_domain": False, + "is_meta": False, + "category": None, + "secure_media_embed": {}, + "link_flair_text": None, + "can_mod_post": False, + "score": 7512, + "approved_by": None, + "author_premium": True, + "thumbnail": "https://b.thumbs.redditmedia.com/QHK44nUFZup-hfFX2Z1dXhk-1lPEmROUCB3bBujvTck.jpg", + "edited": False, + "author_flair_css_class": "k", + "author_flair_richtext": [], + "gildings": {}, + "post_hint": "link", + "content_categories": None, + "is_self": False, + "mod_note": None, + "created": 1595284712, + "link_flair_type": "text", + "wls": 6, + "removed_by_category": None, + "banned_by": None, + "author_flair_type": "text", + "domain": "i.imgur.com", + "allow_live_comments": False, + "selftext_html": None, + "likes": None, + "suggested_sort": "confidence", + "banned_at_utc": None, + "url_overridden_by_dest": "https://i.imgur.com/grVh2AG.gifv", + "view_count": None, + "archived": False, + "no_follow": False, + "is_crosspostable": False, + "pinned": False, + "over_18": False, + "preview": { + "images": [ + { + "source": { + "url": "https://external-preview.redd.it/XDHMFAMlcn3iuSqmWeDIc4yG-q-6xnTIdGivYX-cus4.jpg?auto=webp&s=c4ba246318b3502b080d37fcbdb12e07221401a9", + "width": 638, + "height": 338, + }, + "resolutions": [ + { + "url": "https://external-preview.redd.it/XDHMFAMlcn3iuSqmWeDIc4yG-q-6xnTIdGivYX-cus4.jpg?width=108&crop=smart&auto=webp&s=c9c340a60ba3da1af3f5d5c08f3ed618ebd567d4", + "width": 108, + "height": 57, + }, + { + "url": "https://external-preview.redd.it/XDHMFAMlcn3iuSqmWeDIc4yG-q-6xnTIdGivYX-cus4.jpg?width=216&crop=smart&auto=webp&s=d05c0415e3dc63d097264bfb1b35b09676bd24f6", + "width": 216, + "height": 114, + }, + { + "url": "https://external-preview.redd.it/XDHMFAMlcn3iuSqmWeDIc4yG-q-6xnTIdGivYX-cus4.jpg?width=320&crop=smart&auto=webp&s=5c236179ccfff29e9ba980f31d5a6a9905adbe86", + "width": 320, + "height": 169, + }, + ], + "variants": {}, + "id": "4Z8zF5e4sZJnX4vWH7pZkbqiDPMCuh2J4kNotV9AGSI", + } + ], + "reddit_video_preview": { + "fallback_url": "https://v.redd.it/zzctc8y2dzb51/DASH_240.mp4", + "height": 338, + "width": 638, + "scrubber_media_url": "https://v.redd.it/zzctc8y2dzb51/DASH_96.mp4", + "dash_url": "https://v.redd.it/zzctc8y2dzb51/DASHPlaylist.mpd", + "duration": 44, + "hls_url": "https://v.redd.it/zzctc8y2dzb51/HLSPlaylist.m3u8", + "is_gif": True, + "transcoding_status": "completed", + }, + "enabled": False, + }, + "all_awardings": [], + "awarders": [], + "media_only": False, + "can_gild": False, + "spoiler": False, + "locked": False, + "author_flair_text": None, + "treatment_tags": [], + "visited": False, + "removed_by": None, + "num_reports": None, + "distinguished": None, + "subreddit_id": "t5_2qh1o", + "mod_reason_by": None, + "removal_reason": None, + "link_flair_background_color": "", + "id": "humdlf", + "is_robot_indexable": True, + "report_reasons": None, + "author": "jasontaken", + "discussion_type": None, + "num_comments": 67, + "send_replies": False, + "whitelist_status": "all_ads", + "contest_mode": False, + "mod_reports": [], + "author_patreon_flair": False, + "author_flair_text_color": "dark", + "permalink": "/r/aww/comments/humdlf/if_i_fits_i_sits/", + "parent_whitelist_status": "all_ads", + "stickied": False, + "url": "https://i.imgur.com/grVh2AG.gifv", + "subreddit_subscribers": 25723833, + "created_utc": 1595255912, + "num_crossposts": 1, + "media": None, + "is_video": False, + }, + } + ], + "dist": 25, + "modhash": None, + }, + "kind": "Listing", +} diff --git a/src/newsreader/news/collection/tests/reddit/builder/tests.py b/src/newsreader/news/collection/tests/reddit/builder/tests.py index 58edcd8..0df0d37 100644 --- a/src/newsreader/news/collection/tests/reddit/builder/tests.py +++ b/src/newsreader/news/collection/tests/reddit/builder/tests.py @@ -1,5 +1,4 @@ from datetime import datetime -from unittest import skip from unittest.mock import MagicMock from django.test import TestCase @@ -299,22 +298,113 @@ class RedditBuilderTestCase(TestCase): post.url, ) - @skip("Not implemented") def test_video_post(self): - pass + builder = RedditBuilder + + subreddit = SubredditFactory() + mock_stream = MagicMock(rule=subreddit) + + with builder((video_mock, mock_stream)) as builder: + builder.save() + + posts = {post.remote_identifier: post for post in Post.objects.all()} + + self.assertCountEqual(("hr32jf", "hr1r00", "hqy0ny", "hr0uzh"), posts.keys()) + + post = posts["hr1r00"] + + url = "https://v.redd.it/eyvbxaeqtta51/DASH_480.mp4?source=fallback" + + self.assertEquals( + post.url, + "https://www.reddit.com/r/aww/comments/hr1r00/cool_catt_and_his_clingy_girlfriend/", + ) + self.assertEquals( + f'
', + post.body, + ) - @skip("Not implemented") def test_external_video_post(self): - pass + builder = RedditBuilder + + subreddit = SubredditFactory() + mock_stream = MagicMock(rule=subreddit) + + with builder((external_video_mock, mock_stream)) as builder: + builder.save() + + post = Post.objects.get() + + self.assertEquals(post.remote_identifier, "hulh8k") + + self.assertEquals( + post.url, + "https://www.reddit.com/r/aww/comments/hulh8k/dog_splashing_in_water/", + ) + + title = "Dog splashing in water" + url = "https://gfycat.com/excellentinfantileamericanwigeon" + + self.assertEquals( + f'
Direct url
', + post.body, + ) - @skip("Not implemented") def test_external_gifv_video_post(self): - pass + builder = RedditBuilder + + subreddit = SubredditFactory() + mock_stream = MagicMock(rule=subreddit) + + with builder((external_gifv_mock, mock_stream)) as builder: + builder.save() + + post = Post.objects.get() + + self.assertEquals(post.remote_identifier, "humdlf") + + self.assertEquals( + post.url, "https://www.reddit.com/r/aww/comments/humdlf/if_i_fits_i_sits/" + ) + + url = "https://i.imgur.com/grVh2AG.mp4" + + self.assertEquals( + f'
', + post.body, + ) - @skip("Not implemented") def test_link_only_post(self): - pass + builder = RedditBuilder + + subreddit = SubredditFactory() + mock_stream = MagicMock(rule=subreddit) + + with builder((simple_mock, mock_stream)) as builder: + builder.save() + + post = Post.objects.get(remote_identifier="hngsj8") + + title = "KeePassXC 2.6.0 released" + url = "https://keepassxc.org/blog/2020-07-07-2.6.0-released/" + + self.assertIn( + f'
Direct url
', + post.body, + ) + + self.assertEquals( + post.url, + "https://www.reddit.com/r/linux/comments/hngsj8/keepassxc_260_released/", + ) - @skip("Not implemented") def test_skip_not_known_post_type(self): - pass + builder = RedditBuilder + + subreddit = SubredditFactory() + mock_stream = MagicMock(rule=subreddit) + + with builder((unknown_mock, mock_stream)) as builder: + builder.save() + + self.assertEquals(Post.objects.count(), 0)