From 9e48328e9e3285d5dc3dfe80a04c20ec063b9e60 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 27 Nov 2020 14:18:45 -0800 Subject: [PATCH] Mocks broadcast task for outgoing shelve tests --- bookwyrm/tests/outgoing/test_shelving.py | 78 +++++++++++++----------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/bookwyrm/tests/outgoing/test_shelving.py b/bookwyrm/tests/outgoing/test_shelving.py index c26bec84f..5567784e5 100644 --- a/bookwyrm/tests/outgoing/test_shelving.py +++ b/bookwyrm/tests/outgoing/test_shelving.py @@ -1,3 +1,4 @@ +from unittest.mock import patch from django.test import TestCase from bookwyrm import models, outgoing @@ -25,39 +26,44 @@ class Shelving(TestCase): ) -# def test_handle_shelve(self): -# outgoing.handle_shelve(self.user, self.book, self.shelf) -# # make sure the book is on the shelf -# self.assertEqual(self.shelf.books.get(), self.book) -# -# -# def test_handle_shelve_to_read(self): -# shelf = models.Shelf.objects.get(identifier='to-read') -# -# outgoing.handle_shelve(self.user, self.book, shelf) -# # make sure the book is on the shelf -# self.assertEqual(shelf.books.get(), self.book) -# -# -# def test_handle_shelve_reading(self): -# shelf = models.Shelf.objects.get(identifier='reading') -# -# outgoing.handle_shelve(self.user, self.book, shelf) -# # make sure the book is on the shelf -# self.assertEqual(shelf.books.get(), self.book) -# -# -# def test_handle_shelve_read(self): -# shelf = models.Shelf.objects.get(identifier='read') -# -# outgoing.handle_shelve(self.user, self.book, shelf) -# # make sure the book is on the shelf -# self.assertEqual(shelf.books.get(), self.book) -# -# -# def test_handle_unshelve(self): -# self.shelf.books.add(self.book) -# self.shelf.save() -# self.assertEqual(self.shelf.books.count(), 1) -# outgoing.handle_unshelve(self.user, self.book, self.shelf) -# self.assertEqual(self.shelf.books.count(), 0) + def test_handle_shelve(self): + with patch('bookwyrm.broadcast.broadcast_task.delay') as _: + outgoing.handle_shelve(self.user, self.book, self.shelf) + # make sure the book is on the shelf + self.assertEqual(self.shelf.books.get(), self.book) + + + def test_handle_shelve_to_read(self): + shelf = models.Shelf.objects.get(identifier='to-read') + + with patch('bookwyrm.broadcast.broadcast_task.delay') as _: + outgoing.handle_shelve(self.user, self.book, shelf) + # make sure the book is on the shelf + self.assertEqual(shelf.books.get(), self.book) + + + def test_handle_shelve_reading(self): + shelf = models.Shelf.objects.get(identifier='reading') + + with patch('bookwyrm.broadcast.broadcast_task.delay') as _: + outgoing.handle_shelve(self.user, self.book, shelf) + # make sure the book is on the shelf + self.assertEqual(shelf.books.get(), self.book) + + + def test_handle_shelve_read(self): + shelf = models.Shelf.objects.get(identifier='read') + + with patch('bookwyrm.broadcast.broadcast_task.delay') as _: + outgoing.handle_shelve(self.user, self.book, shelf) + # make sure the book is on the shelf + self.assertEqual(shelf.books.get(), self.book) + + + def test_handle_unshelve(self): + self.shelf.books.add(self.book) + self.shelf.save() + self.assertEqual(self.shelf.books.count(), 1) + with patch('bookwyrm.broadcast.broadcast_task.delay') as _: + outgoing.handle_unshelve(self.user, self.book, self.shelf) + self.assertEqual(self.shelf.books.count(), 0)