From 60b42827f4b9d8da2718a5ec6d82d6b6e1d08976 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Mon, 18 Jan 2021 20:00:04 -0800 Subject: [PATCH] Mock the AP publishing to stop hanging tests --- bookwyrm/tests/actions/test_readthrough.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bookwyrm/tests/actions/test_readthrough.py b/bookwyrm/tests/actions/test_readthrough.py index b92c9b657..bd24cec27 100644 --- a/bookwyrm/tests/actions/test_readthrough.py +++ b/bookwyrm/tests/actions/test_readthrough.py @@ -1,9 +1,11 @@ +from unittest.mock import patch from django.test import TestCase, Client from django.utils import timezone from datetime import datetime from bookwyrm import models +@patch('bookwyrm.broadcast.broadcast_task.delay') class ReadThrough(TestCase): def setUp(self): self.client = Client() @@ -25,7 +27,7 @@ class ReadThrough(TestCase): self.client.force_login(self.user) - def test_create_basic_readthrough(self): + def test_create_basic_readthrough(self, delay_mock): """A basic readthrough doesn't create a progress update""" self.assertEqual(self.edition.readthrough_set.count(), 0) @@ -40,8 +42,9 @@ class ReadThrough(TestCase): datetime(2020, 11, 27, tzinfo=timezone.utc)) self.assertEqual(readthroughs[0].progress, None) self.assertEqual(readthroughs[0].finish_date, None) + self.assertEqual(delay_mock.call_count, 1) - def test_create_progress_readthrough(self): + def test_create_progress_readthrough(self, delay_mock): self.assertEqual(self.edition.readthrough_set.count(), 0) self.client.post('/start-reading/{}'.format(self.edition.id), { @@ -60,6 +63,7 @@ class ReadThrough(TestCase): self.assertEqual(len(progress_updates), 1) self.assertEqual(progress_updates[0].mode, models.ProgressMode.PAGE) self.assertEqual(progress_updates[0].progress, 50) + self.assertEqual(delay_mock.call_count, 1) # Update progress self.client.post('/edit-readthrough', { @@ -72,3 +76,4 @@ class ReadThrough(TestCase): self.assertEqual(len(progress_updates), 2) self.assertEqual(progress_updates[1].mode, models.ProgressMode.PAGE) self.assertEqual(progress_updates[1].progress, 100) + self.assertEqual(delay_mock.call_count, 1) # Edit doesn't publish anything