Skip to content

Commit

Permalink
Convert integration tests that make no requests to unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LilSpazJoekp committed Dec 8, 2022
1 parent d971048 commit 5826c50
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
16 changes: 0 additions & 16 deletions tests/integration/models/reddit/test_subreddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,14 +474,6 @@ async def test_submit_image__bad_websocket(self, _, reddit, image_path):
with pytest.raises(ClientException):
await subreddit.submit_image("Test Title", image)

async def test_submit_image__bad_filetype(self, reddit):
reddit.read_only = False
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)

@mock.patch(
"aiohttp.client.ClientSession.ws_connect", return_value=WebsocketMock("l6evpd")
) # update with cassette
Expand Down Expand Up @@ -596,14 +588,6 @@ async def test_submit_video(self, _, reddit, image_path):
# for some reason returns false
assert submission.title == f"Test Title {i}"

async def test_submit_video__bad_filetype(self, reddit):
reddit.read_only = False
subreddit = await reddit.subreddit(pytest.placeholders.test_subreddit)
for file_name in ("test.jpg", "test.png", "test.gif"):
video = image_path(file_name)
with pytest.raises(ClientException):
await subreddit.submit_video("Test Title", video)

@pytest.mark.cassette_name("TestSubreddit.test_submit_video")
@mock.patch("aiohttp.client.ClientSession.ws_connect", return_value=WebsocketMock())
async def test_submit_video__bad_websocket(self, _, reddit, image_path):
Expand Down
7 changes: 0 additions & 7 deletions tests/integration/models/reddit/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,13 +714,6 @@ async def test_update(self, reddit):


class TestSubredditWidgets(IntegrationTest):
@pytest.mark.cassette_name("TestSubredditWidgets.fetch_widgets")
async def test_bad_attribute(self, reddit):
subreddit = await reddit.subreddit(pytest.placeholders.test_subreddit)
widgets = subreddit.widgets
with pytest.raises(AttributeError):
widgets.nonexistant_attribute

@pytest.mark.cassette_name("TestSubredditWidgets.fetch_widgets")
async def test_items(self, reddit):
subreddit = await reddit.subreddit(pytest.placeholders.test_subreddit)
Expand Down
16 changes: 15 additions & 1 deletion tests/unit/models/reddit/test_subreddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from unittest import mock
from unittest.mock import AsyncMock, MagicMock

from asyncpraw.exceptions import MediaPostFailed
from asyncpraw.exceptions import ClientException, MediaPostFailed
from asyncpraw.models import InlineGif, InlineImage, InlineVideo, Subreddit, WikiPage
from asyncpraw.models.reddit.subreddit import SubredditFlairTemplates

Expand Down Expand Up @@ -148,6 +148,20 @@ 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):
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):
subreddit = await reddit.subreddit(pytest.placeholders.test_subreddit)
for file_name in ("test.jpg", "test.png", "test.gif"):
video = image_path(file_name)
with pytest.raises(ClientException):
await subreddit.submit_video("Test Title", video)

async def test_upload_banner_additional_image(self, reddit):
subreddit = Subreddit(reddit, display_name="name")
with pytest.raises(ValueError):
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/models/reddit/test_widgets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from json import dumps

import pytest
from pytest import raises

from asyncpraw.models import (
Expand Down Expand Up @@ -38,6 +39,22 @@ def test_good_encode(self, reddit):


class TestSubredditWidgets(UnitTest):
async def test_bad_attribute(self, reddit):
subreddit = await reddit.subreddit(pytest.placeholders.test_subreddit)
widgets = subreddit.widgets
with pytest.raises(AttributeError):
_ = widgets.nonexistant_attribute

def test_repr(self, reddit):
widgets = SubredditWidgets(Subreddit(reddit, "fake_subreddit"))
assert (
"SubredditWidgets(subreddit=Subreddit(display_name='fake_subreddit'))"
== repr(widgets)
)

def test_subreddit_widgets_mod(self, reddit):
widgets = SubredditWidgets(Subreddit(reddit, "fake_subreddit"))
assert isinstance(widgets.mod, SubredditWidgetsModeration)

def test_widget_mod(self, reddit):
w = Widget(reddit, {})
Expand Down

0 comments on commit 5826c50

Please sign in to comment.