forked from mirrors/bookwyrm
Adds tests
This commit is contained in:
parent
8746409e6d
commit
4f4d2dc53e
2 changed files with 70 additions and 7 deletions
|
@ -60,13 +60,6 @@ class BookWyrmTags(TestCase):
|
|||
self.book.save()
|
||||
self.assertEqual(bookwyrm_tags.get_book_description(self.book), "hello")
|
||||
|
||||
def test_get_next_shelf(self, *_):
|
||||
"""self progress helper"""
|
||||
self.assertEqual(bookwyrm_tags.get_next_shelf("to-read"), "reading")
|
||||
self.assertEqual(bookwyrm_tags.get_next_shelf("reading"), "read")
|
||||
self.assertEqual(bookwyrm_tags.get_next_shelf("read"), "complete")
|
||||
self.assertEqual(bookwyrm_tags.get_next_shelf("blooooga"), "to-read")
|
||||
|
||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
||||
def test_load_subclass(self, *_):
|
||||
"""get a status' real type"""
|
||||
|
|
70
bookwyrm/tests/templatetags/test_shelf_tags.py
Normal file
70
bookwyrm/tests/templatetags/test_shelf_tags.py
Normal file
|
@ -0,0 +1,70 @@
|
|||
""" style fixes and lookups for templates """
|
||||
from unittest.mock import patch
|
||||
|
||||
from django.test import TestCase
|
||||
from django.test.client import RequestFactory
|
||||
|
||||
from bookwyrm import models
|
||||
from bookwyrm.templatetags import shelf_tags
|
||||
|
||||
|
||||
@patch("bookwyrm.activitystreams.add_status_task.delay")
|
||||
@patch("bookwyrm.activitystreams.remove_status_task.delay")
|
||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
||||
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
|
||||
class BookWyrmTags(TestCase):
|
||||
"""lotta different things here"""
|
||||
|
||||
def setUp(self):
|
||||
"""create some filler objects"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.mouse",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.rat",
|
||||
"ratword",
|
||||
remote_id="http://example.com/rat",
|
||||
local=False,
|
||||
)
|
||||
self.book = models.Edition.objects.create(
|
||||
title="Test Book",
|
||||
parent_work=models.Work.objects.create(title="Test work"),
|
||||
)
|
||||
|
||||
def test_get_is_book_on_shelf(self, *_):
|
||||
"""check if a book is on a shelf"""
|
||||
shelf = self.local_user.shelf_set.first()
|
||||
self.assertFalse(shelf_tags.get_is_book_on_shelf(self.book, shelf))
|
||||
models.ShelfBook.objects.create(
|
||||
shelf=shelf, book=self.book, user=self.local_user
|
||||
)
|
||||
self.assertTrue(shelf_tags.get_is_book_on_shelf(self.book, shelf))
|
||||
|
||||
def test_get_next_shelf(self, *_):
|
||||
"""self progress helper"""
|
||||
self.assertEqual(shelf_tags.get_next_shelf("to-read"), "reading")
|
||||
self.assertEqual(shelf_tags.get_next_shelf("reading"), "read")
|
||||
self.assertEqual(shelf_tags.get_next_shelf("read"), "complete")
|
||||
self.assertEqual(shelf_tags.get_next_shelf("blooooga"), "to-read")
|
||||
|
||||
def test_active_shelf(self, *_):
|
||||
"""get the shelf a book is on"""
|
||||
shelf = self.local_user.shelf_set.first()
|
||||
request = self.factory.get("")
|
||||
request.user = self.local_user
|
||||
context = {"request": request}
|
||||
self.assertIsInstance(shelf_tags.active_shelf(context, self.book), dict)
|
||||
models.ShelfBook.objects.create(
|
||||
shelf=shelf, book=self.book, user=self.local_user
|
||||
)
|
||||
self.assertEqual(shelf_tags.active_shelf(context, self.book).shelf, shelf)
|
Loading…
Reference in a new issue