From 73d085845c60e85bf4d00db7c87c3b5520f8ee14 Mon Sep 17 00:00:00 2001 From: qilinz Date: Thu, 13 Jul 2023 16:32:09 +0200 Subject: [PATCH] add tests. black --- journal/tests.py | 18 ++++++++++++++++++ journal/urls.py | 4 +--- journal/views.py | 4 +++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/journal/tests.py b/journal/tests.py index 46d4f003..64471cee 100644 --- a/journal/tests.py +++ b/journal/tests.py @@ -96,6 +96,24 @@ class ShelfTest(TestCase): self.assertEqual(Mark(user, book1).visibility, 1) self.assertEqual(shelf_manager.get_log_for_item(book1).count(), 5) + # test silence mark mode -> no log + shelf_manager.move_item(book1, ShelfType.WISHLIST, silence=True) + self.assertEqual(log.count(), 5) + shelf_manager.move_item(book1, ShelfType.PROGRESS, silence=True) + self.assertEqual(log.count(), 5) + # test delete one log + first_log = log.first() + Mark(user, book1).delete_log(first_log.id) + self.assertEqual(log.count(), 4) + # test delete mark -> leave one log: 移除标记 + Mark(user, book1).delete() + self.assertEqual(log.count(), 1) + # test delete all logs + shelf_manager.move_item(book1, ShelfType.PROGRESS) + self.assertEqual(log.count(), 2) + Mark(user, book1).delete(silence=True) + self.assertEqual(log.count(), 0) + class TagTest(TestCase): def setUp(self): diff --git a/journal/urls.py b/journal/urls.py index ef4cea11..a4a46daf 100644 --- a/journal/urls.py +++ b/journal/urls.py @@ -23,9 +23,7 @@ urlpatterns = [ path("mark/", mark, name="mark"), path("comment/", comment, name="comment"), path("mark_log//", mark_log, name="mark_log"), - path( - "mark_history/", mark_history, name="mark_history" - ), + path("mark_history/", mark_history, name="mark_history"), path( "add_to_collection/", add_to_collection, name="add_to_collection" ), diff --git a/journal/views.py b/journal/views.py index 6fd661f4..f9248b9b 100644 --- a/journal/views.py +++ b/journal/views.py @@ -161,7 +161,9 @@ def mark(request, item_uuid): if request.POST.get("delete", default=False): silence = request.POST.get("silence", False) mark.delete(silence=silence) - if silence: # this means the mark is deleted from mark_history, thus redirect to item page + if ( + silence + ): # this means the mark is deleted from mark_history, thus redirect to item page return redirect( reverse("catalog:retrieve", args=[item.url_path, item.uuid]) )