More mocks for more tests

This commit is contained in:
Mouse Reeve 2021-03-23 09:19:11 -07:00
parent de2cea5ff2
commit 59deb1cd05
3 changed files with 32 additions and 29 deletions

View file

@ -203,7 +203,8 @@ class GoodreadsImport(TestCase):
self.assertEqual(readthrough.finish_date.month, 10)
self.assertEqual(readthrough.finish_date.day, 25)
def test_handle_imported_book_review(self):
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
def test_handle_imported_book_review(self, _):
""" goodreads review import """
import_job = models.ImportJob.objects.create(user=self.user)
datafile = pathlib.Path(__file__).parent.joinpath("data/goodreads.csv")

View file

@ -1,5 +1,4 @@
""" testing import """
from collections import namedtuple
import csv
import pathlib
from unittest.mock import patch
@ -16,8 +15,8 @@ class LibrarythingImport(TestCase):
""" importing from librarything tsv """
def setUp(self):
self.importer = LibrarythingImporter()
""" use a test tsv """
self.importer = LibrarythingImporter()
datafile = pathlib.Path(__file__).parent.joinpath("data/librarything.tsv")
# Librarything generates latin encoded exports...
@ -200,7 +199,8 @@ class LibrarythingImport(TestCase):
self.assertEqual(readthrough.finish_date.month, 5)
self.assertEqual(readthrough.finish_date.day, 8)
def test_handle_imported_book_review(self):
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
def test_handle_imported_book_review(self, _):
""" librarything review import """
import_job = models.ImportJob.objects.create(user=self.user)
datafile = pathlib.Path(__file__).parent.joinpath("data/librarything.tsv")

View file

@ -10,6 +10,7 @@ from bookwyrm import models
from bookwyrm.templatetags import bookwyrm_tags
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
class TemplateTags(TestCase):
""" lotta different things here """
@ -32,34 +33,34 @@ class TemplateTags(TestCase):
)
self.book = models.Edition.objects.create(title="Test Book")
def test_dict_key(self):
def test_dict_key(self, _):
""" just getting a value out of a dict """
test_dict = {"a": 1, "b": 3}
self.assertEqual(bookwyrm_tags.dict_key(test_dict, "a"), 1)
self.assertEqual(bookwyrm_tags.dict_key(test_dict, "c"), 0)
def test_get_user_rating(self):
def test_get_user_rating(self, _):
""" get a user's most recent rating of a book """
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
models.Review.objects.create(user=self.user, book=self.book, rating=3)
self.assertEqual(bookwyrm_tags.get_user_rating(self.book, self.user), 3)
def test_get_user_rating_doesnt_exist(self):
def test_get_user_rating_doesnt_exist(self, _):
""" there is no rating available """
self.assertEqual(bookwyrm_tags.get_user_rating(self.book, self.user), 0)
def test_get_user_identifer_local(self):
def test_get_user_identifer_local(self, _):
""" fall back to the simplest uid available """
self.assertNotEqual(self.user.username, self.user.localname)
self.assertEqual(bookwyrm_tags.get_user_identifier(self.user), "mouse")
def test_get_user_identifer_remote(self):
def test_get_user_identifer_remote(self, _):
""" for a remote user, should be their full username """
self.assertEqual(
bookwyrm_tags.get_user_identifier(self.remote_user), "rat@example.com"
)
def test_get_notification_count(self):
def test_get_notification_count(self, _):
""" just countin' """
self.assertEqual(bookwyrm_tags.get_notification_count(self.user), 0)
@ -72,7 +73,7 @@ class TemplateTags(TestCase):
self.assertEqual(bookwyrm_tags.get_notification_count(self.user), 2)
def test_get_replies(self):
def test_get_replies(self, _):
""" direct replies to a status """
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
parent = models.Review.objects.create(
@ -84,12 +85,13 @@ class TemplateTags(TestCase):
second_child = models.Status.objects.create(
reply_parent=parent, user=self.user, content="hi"
)
third_child = models.Status.objects.create(
reply_parent=parent,
user=self.user,
deleted=True,
deleted_date=timezone.now(),
)
with patch("bookwyrm.activitystreams.ActivityStream.remove_status"):
third_child = models.Status.objects.create(
reply_parent=parent,
user=self.user,
deleted=True,
deleted_date=timezone.now(),
)
replies = bookwyrm_tags.get_replies(parent)
self.assertEqual(len(replies), 2)
@ -97,7 +99,7 @@ class TemplateTags(TestCase):
self.assertTrue(second_child in replies)
self.assertFalse(third_child in replies)
def test_get_parent(self):
def test_get_parent(self, _):
""" get the reply parent of a status """
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
parent = models.Review.objects.create(
@ -111,7 +113,7 @@ class TemplateTags(TestCase):
self.assertEqual(result, parent)
self.assertIsInstance(result, models.Review)
def test_get_user_liked(self):
def test_get_user_liked(self, _):
""" did a user like a status """
status = models.Review.objects.create(user=self.remote_user, book=self.book)
@ -120,7 +122,7 @@ class TemplateTags(TestCase):
models.Favorite.objects.create(user=self.user, status=status)
self.assertTrue(bookwyrm_tags.get_user_liked(self.user, status))
def test_get_user_boosted(self):
def test_get_user_boosted(self, _):
""" did a user boost a status """
status = models.Review.objects.create(user=self.remote_user, book=self.book)
@ -129,7 +131,7 @@ class TemplateTags(TestCase):
models.Boost.objects.create(user=self.user, boosted_status=status)
self.assertTrue(bookwyrm_tags.get_user_boosted(self.user, status))
def test_follow_request_exists(self):
def test_follow_request_exists(self, _):
""" does a user want to follow """
self.assertFalse(
bookwyrm_tags.follow_request_exists(self.user, self.remote_user)
@ -147,7 +149,7 @@ class TemplateTags(TestCase):
bookwyrm_tags.follow_request_exists(self.remote_user, self.user)
)
def test_get_boosted(self):
def test_get_boosted(self, _):
""" load a boosted status """
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
status = models.Review.objects.create(user=self.remote_user, book=self.book)
@ -156,7 +158,7 @@ class TemplateTags(TestCase):
self.assertIsInstance(boosted, models.Review)
self.assertEqual(boosted, status)
def test_get_book_description(self):
def test_get_book_description(self, _):
""" grab it from the edition or the parent """
work = models.Work.objects.create(title="Test Work")
self.book.parent_work = work
@ -172,12 +174,12 @@ class TemplateTags(TestCase):
self.book.save()
self.assertEqual(bookwyrm_tags.get_book_description(self.book), "hello")
def test_get_uuid(self):
def test_get_uuid(self, _):
""" uuid functionality """
uuid = bookwyrm_tags.get_uuid("hi")
self.assertTrue(re.match(r"hi[A-Za-z0-9\-]", uuid))
def test_time_since(self):
def test_time_since(self, _):
""" ultraconcise timestamps """
self.assertEqual(bookwyrm_tags.time_since("bleh"), "")
@ -207,7 +209,7 @@ class TemplateTags(TestCase):
re.match(r"[A-Z][a-z]{2} \d?\d \d{4}", bookwyrm_tags.time_since(years_ago))
)
def test_get_markdown(self):
def test_get_markdown(self, _):
""" mardown format data """
result = bookwyrm_tags.get_markdown("_hi_")
self.assertEqual(result, "<p><em>hi</em></p>")
@ -215,13 +217,13 @@ class TemplateTags(TestCase):
result = bookwyrm_tags.get_markdown("<marquee>_hi_</marquee>")
self.assertEqual(result, "<p><em>hi</em></p>")
def test_get_mentions(self):
def test_get_mentions(self, _):
""" list of people mentioned """
status = models.Status.objects.create(content="hi", user=self.remote_user)
result = bookwyrm_tags.get_mentions(status, self.user)
self.assertEqual(result, "@rat@example.com ")
def test_get_status_preview_name(self):
def test_get_status_preview_name(self, _):
""" status context string """
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
status = models.Status.objects.create(content="hi", user=self.user)
@ -246,7 +248,7 @@ class TemplateTags(TestCase):
result = bookwyrm_tags.get_status_preview_name(status)
self.assertEqual(result, "quotation from <em>Test Book</em>")
def test_related_status(self):
def test_related_status(self, _):
""" gets the subclass model for a notification status """
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
status = models.Status.objects.create(content="hi", user=self.user)