def prepare_thumbnail(self, post: Post) -> None: """ Prepare the post for the submission with thumbnail. Converted the post to the Rich Text JSON format so that Reddit creates a thumbnail for the post. """ log.debug("scheduled_post_convert") try: post.body_rtjson = self.post_converter.convert_to_rtjson( post.body_md, ) except ImageNotFound: log.warning("scheduled_post_missing_image", post=str(post)) post.submit_with_thumbnail = False click.echo( click.style( "Warning: No image found in the post.\n" + "To submit a post without image set the " + "'submit_with_thumbnail' option to False.", fg="red", )) except (RedditError, PostConversionError) as exception: log.exception("scheduled_post_convert_error") exception.hint = ( "To avoid further issues you can submit a post without " + "image by setting the 'submit_with_thumbnail' option to False." ) raise
def test_submit_post_with_thumbnail( mock_reddit, mock_reddit_helper, mock_sleep, mock_update_post, reddit_cutifier_config, post: Post, ): """ Test submitting a post with thumbnail. Set the :attr:`Post.body_rtjson` (empty by default). Check that :meth:`RedditHelper.submit_post_rtjson()` is called with the correct arguments. Check that :meth:`Reddit.subreddit()` is not called (used only for posts without thumbnail). Check the delay before updating the post. Check that :meth:`RedditCutifier.update_post()` is called. """ post.body_rtjson = [{"c": [{"t": "Slow Start"}]}] reddit_cutifier = RedditCutifier(reddit_cutifier_config) submit_post_rtjson = mock_reddit_helper.return_value.submit_post_rtjson mock_update_post.return_value.permalink = "slow_start_link" assert reddit_cutifier.submit_post(post).permalink == "slow_start_link" assert submit_post_rtjson.call_args == call( subreddit=post.subreddit, title=post.title, body_rtjson=post.body_rtjson, flair_id=post.flair_id, ) assert not mock_reddit.return_value.subreddit.called assert mock_sleep.call_args == call(2000 / 1000) assert mock_update_post.called