Fixes views tests

This commit is contained in:
Mouse Reeve 2021-03-23 11:27:00 -07:00
parent 7f271dbde7
commit 28651bd804
6 changed files with 36 additions and 27 deletions

View file

@ -102,7 +102,8 @@ class GoalViews(TestCase):
result = view(request, self.local_user.localname, 2020)
self.assertEqual(result.status_code, 404)
def test_create_goal(self):
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
def test_create_goal(self, _):
""" create a new goal """
view = views.Goal.as_view()
request = self.factory.post(

View file

@ -5,6 +5,7 @@ from django.test.client import RequestFactory
from bookwyrm import models, views
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
class InteractionViews(TestCase):
""" viewing and creating statuses """
@ -146,8 +147,11 @@ class InteractionViews(TestCase):
self.assertEqual(models.Boost.objects.count(), 1)
self.assertEqual(models.Notification.objects.count(), 1)
broadcast_mock.call_count = 0
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
with patch(
"bookwyrm.activitystreams.ActivityStream.remove_status"
) as redis_mock:
view(request, status.id)
self.assertEqual(broadcast_mock.call_count, 1)
self.assertTrue(redis_mock.called)
self.assertEqual(models.Boost.objects.count(), 0)
self.assertEqual(models.Notification.objects.count(), 0)

View file

@ -1,4 +1,5 @@
""" test for app action functionality """
from unittest.mock import patch
from django.contrib.auth.models import AnonymousUser
from django.template.response import TemplateResponse
from django.test import TestCase
@ -30,7 +31,8 @@ class LandingViews(TestCase):
view = views.Home.as_view()
request = self.factory.get("")
request.user = self.local_user
result = view(request)
with patch("bookwyrm.activitystreams.ActivityStream.get_activity_stream"):
result = view(request)
self.assertEqual(result.status_code, 200)
result.render()

View file

@ -8,6 +8,7 @@ from django.utils import timezone
from bookwyrm import models, views
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
class ReadingViews(TestCase):
""" viewing and creating statuses """
@ -39,7 +40,7 @@ class ReadingViews(TestCase):
outbox="https://example.com/users/rat/outbox",
)
def test_start_reading(self):
def test_start_reading(self, _):
""" begin a book """
shelf = self.local_user.shelf_set.get(identifier="reading")
self.assertFalse(shelf.books.exists())
@ -70,7 +71,7 @@ class ReadingViews(TestCase):
self.assertEqual(readthrough.user, self.local_user)
self.assertEqual(readthrough.book, self.book)
def test_start_reading_reshelf(self):
def test_start_reading_reshelf(self, _):
""" begin a book """
to_read_shelf = self.local_user.shelf_set.get(identifier="to-read")
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
@ -90,7 +91,7 @@ class ReadingViews(TestCase):
self.assertFalse(to_read_shelf.books.exists())
self.assertEqual(shelf.books.get(), self.book)
def test_finish_reading(self):
def test_finish_reading(self, _):
""" begin a book """
shelf = self.local_user.shelf_set.get(identifier="read")
self.assertFalse(shelf.books.exists())
@ -126,7 +127,7 @@ class ReadingViews(TestCase):
self.assertEqual(readthrough.user, self.local_user)
self.assertEqual(readthrough.book, self.book)
def test_edit_readthrough(self):
def test_edit_readthrough(self, _):
""" adding dates to an ongoing readthrough """
start = timezone.make_aware(dateutil.parser.parse("2021-01-03"))
readthrough = models.ReadThrough.objects.create(
@ -153,7 +154,7 @@ class ReadingViews(TestCase):
self.assertEqual(readthrough.finish_date.day, 7)
self.assertEqual(readthrough.book, self.book)
def test_delete_readthrough(self):
def test_delete_readthrough(self, _):
""" remove a readthrough """
readthrough = models.ReadThrough.objects.create(
book=self.book, user=self.local_user
@ -170,7 +171,7 @@ class ReadingViews(TestCase):
views.delete_readthrough(request)
self.assertFalse(models.ReadThrough.objects.filter(id=readthrough.id).exists())
def test_create_readthrough(self):
def test_create_readthrough(self, _):
""" adding new read dates """
request = self.factory.post(
"",

View file

@ -26,28 +26,30 @@ class RssFeedView(TestCase):
)
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
self.review = models.Review.objects.create(
name="Review name",
content="test content",
rating=3,
user=self.user,
book=self.book,
)
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
self.review = models.Review.objects.create(
name="Review name",
content="test content",
rating=3,
user=self.user,
book=self.book,
)
self.quote = models.Quotation.objects.create(
quote="a sickening sense",
content="test content",
user=self.user,
book=self.book,
)
self.quote = models.Quotation.objects.create(
quote="a sickening sense",
content="test content",
user=self.user,
book=self.book,
)
self.generatednote = models.GeneratedNote.objects.create(
content="test content", user=self.user
)
self.generatednote = models.GeneratedNote.objects.create(
content="test content", user=self.user
)
self.factory = RequestFactory()
def test_rss_feed(self):
@patch("bookwyrm.activitystreams.ActivityStream.get_activity_stream")
def test_rss_feed(self, _):
""" load an rss feed """
view = rss_feed.RssFeed()
request = self.factory.get("/user/rss_user/rss")

View file

@ -159,7 +159,6 @@ class StatusViews(TestCase):
view(request, "reply")
self.assertTrue(redis_mock.called)
reply = models.Status.replies(status).first()
self.assertEqual(reply.content, "<p>right</p>")
self.assertEqual(reply.user, user)