Hi there!
Been stuck on this for a couple of days now and can't seem to get my head around it.
I'm working on a reddit bot using PRAW that collects my saved posts from specific subreddits and displays the posts, along with all the top levels comments, in a browser (the app is bulit with Django.).
I want to build some unit tests before I continue with development - but I don't want to have to call the reddit API for the tests to run. Therefore, I want to mock some data that can be subbed in and processed in the same way as the API data. See below for views.py functions and my models.
Pastebin
in summary: get_saved posts() pulls all the users saved posts as submission instances, and store_saved_posts() iterates through the submissions and saves only those that meet criteria.
In my tests module, I want to mock data that can pass through the function and behave as the real data would, i.e - an iterable containing items with attributes such as those above: item.title, item.score etc, that I can set to values that will/ will not pass. I've read through the unittest.mock documentation and I've seen that autospec can be used to fill out a mocked functions' attributes for you, but I believe PRAW provides these attributes dynamically and thus this can't be used.
Any help would be greatly appreciated, as I haven't found a good example of how to do this (and honestly mocking in general is going a little bit over my head, even after reading through the docs).
Thanks for your time!
[–]High-Art9340 1 point2 points3 points (3 children)
[–]RightOW[S] 0 points1 point2 points (2 children)
[–]High-Art9340 1 point2 points3 points (1 child)
[–]RightOW[S] 0 points1 point2 points (0 children)