Skip to content

Commit

Permalink
Merge pull request #225 from praw-dev/more_test_cleanup
Browse files Browse the repository at this point in the history
Additional test cleanup
  • Loading branch information
LilSpazJoekp committed Dec 21, 2022
2 parents f2536b2 + 91eb24f commit 7aa91e8
Show file tree
Hide file tree
Showing 8 changed files with 293 additions and 248 deletions.
4 changes: 2 additions & 2 deletions tests/integration/models/reddit/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ async def test_create__invalid_layout(self, reddit):
description = "The description."
layout = "milk before cereal"
reddit.read_only = False
subreddit = await reddit.subreddit(pytest.placeholders.test_subreddit)
with pytest.raises(RedditAPIException):
subreddit = await reddit.subreddit(pytest.placeholders.test_subreddit)
await subreddit.collections.mod.create(
title=title, description=description, display_layout=layout
)
Expand All @@ -275,8 +275,8 @@ async def test_create__lowercase_layout(self, reddit):
description = "The description."
layout = "gallery"
reddit.read_only = False
subreddit = await reddit.subreddit(pytest.placeholders.test_subreddit)
with pytest.raises(RedditAPIException):
subreddit = await reddit.subreddit(pytest.placeholders.test_subreddit)
await subreddit.collections.mod.create(
title=title, description=description, display_layout=layout
)
Expand Down
183 changes: 108 additions & 75 deletions tests/integration/models/reddit/test_subreddit.py

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions tests/integration/models/reddit/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def test_button_widget(self, reddit):

assert subreddit == button_widget.subreddit

async def test_create_and_update_and_delete(self, reddit, image_path):
async def test_create_and_update_and_delete(self, image_path, reddit):
reddit.read_only = False

subreddit = await reddit.subreddit(pytest.placeholders.test_subreddit)
Expand Down Expand Up @@ -290,7 +290,7 @@ async def test_create_and_update_and_delete(self, reddit):


class TestCustomWidget(IntegrationTest):
async def test_create_and_update_and_delete(self, reddit, image_path):
async def test_create_and_update_and_delete(self, image_path, reddit):
reddit.read_only = False

subreddit = await reddit.subreddit(pytest.placeholders.test_subreddit)
Expand Down Expand Up @@ -410,7 +410,7 @@ async def test_update(self, reddit):


class TestImageWidget(IntegrationTest):
async def test_create_and_update_and_delete(self, reddit, image_path):
async def test_create_and_update_and_delete(self, image_path, reddit):
reddit.read_only = False

subreddit = await reddit.subreddit(pytest.placeholders.test_subreddit)
Expand Down Expand Up @@ -817,7 +817,7 @@ async def test_reorder(self, reddit):
order = await self.async_list(widgets.sidebar())
assert order == new_order

async def test_upload_image(self, reddit, image_path):
async def test_upload_image(self, image_path, reddit):
reddit.read_only = False
subreddit = await reddit.subreddit(pytest.placeholders.test_subreddit)
widgets = subreddit.widgets
Expand Down
29 changes: 17 additions & 12 deletions tests/unit/models/reddit/test_subreddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,17 @@ def test_hash(self, reddit):
assert hash(subreddit1) != hash(subreddit3)

@mock.patch(
"asyncpraw.Reddit.post", return_value={"json": {"data": {"websocket_url": ""}}}
"asyncpraw.Reddit.post",
new=AsyncMock(return_value={"json": {"data": {"websocket_url": ""}}}),
)
@mock.patch(
"asyncpraw.models.Subreddit._upload_media",
return_value=("fake_media_url", "fake_websocket_url"),
new=AsyncMock(
return_value=("fake_media_url", "fake_websocket_url"),
),
)
@mock.patch("aiohttp.client.ClientSession.ws_connect")
async def test_invalid_media(self, connection_mock, _, __, reddit):
async def test_invalid_media(self, connection_mock, reddit):
reddit._core._requestor._http = aiohttp.ClientSession()
recv_mock = MagicMock()
recv_mock.receive_json = AsyncMock(
Expand All @@ -83,16 +86,18 @@ async def test_invalid_media(self, connection_mock, _, __, reddit):
)
await reddit._core._requestor._http.close()

@mock.patch("asyncpraw.models.Subreddit._read_and_post_media")
@mock.patch("aiohttp.client.ClientSession.ws_connect", new=AsyncMock())
@mock.patch(
"asyncpraw.Reddit.post",
return_value={
"json": {"data": {"websocket_url": ""}},
"args": {"action": "", "fields": []},
},
new=AsyncMock(
return_value={
"json": {"data": {"websocket_url": ""}},
"args": {"action": "", "fields": []},
},
),
)
@mock.patch("aiohttp.client.ClientSession.ws_connect")
async def test_media_upload_500(self, _, __, mock_method, reddit):
@mock.patch("asyncpraw.models.Subreddit._read_and_post_media")
async def test_media_upload_500(self, mock_method, reddit):
from aiohttp.http_exceptions import HttpProcessingError
from asyncprawcore.exceptions import ServerError

Expand Down Expand Up @@ -146,14 +151,14 @@ async def test_submit__failure(self, reddit):
await subreddit.submit("Cool title", selftext="", url="b")
assert str(excinfo.value) == message

async def test_submit_image__bad_filetype(self, reddit, image_path):
async def test_submit_image__bad_filetype(self, image_path, reddit):
subreddit = await reddit.subreddit(pytest.placeholders.test_subreddit)
for file_name in ("test.mov", "test.mp4"):
image = image_path(file_name)
with pytest.raises(ClientException):
await subreddit.submit_image("Test Title", image)

async def test_submit_video__bad_filetype(self, reddit, image_path):
async def test_submit_video__bad_filetype(self, image_path, reddit):
subreddit = await reddit.subreddit(pytest.placeholders.test_subreddit)
for file_name in ("test.jpg", "test.png", "test.gif"):
video = image_path(file_name)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/models/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async def web_app(self):
) as reddit:
yield reddit

def test_implicit__from_script_app(self, script_app_with_password, script_app):
def test_implicit__from_script_app(self, script_app, script_app_with_password):
with pytest.raises(ClientException):
script_app.auth.implicit(
access_token="dummy token", expires_in=10, scope=""
Expand All @@ -63,7 +63,7 @@ def test_implicit__from_web_app(self, web_app):
with pytest.raises(ClientException):
web_app.auth.implicit(access_token="dummy token", expires_in=10, scope="")

def test_limits(self, web_app, script_app_with_password, script_app, installed_app):
def test_limits(self, installed_app, script_app, script_app_with_password, web_app):
expected = {"remaining": None, "reset_timestamp": None, "used": None}
for app in [
installed_app,
Expand Down
Loading

0 comments on commit 7aa91e8

Please sign in to comment.