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) result = view(request, self.local_user.localname, 2020)
self.assertEqual(result.status_code, 404) 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 """ """ create a new goal """
view = views.Goal.as_view() view = views.Goal.as_view()
request = self.factory.post( request = self.factory.post(

View file

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

View file

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

View file

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

View file

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

View file

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