mirror of
https://github.com/sissbruecker/linkding.git
synced 2025-08-14 14:09:26 +02:00
Bulk create HTML snapshots (#1132)
* Add option to create HTML snapshot for bulk edit * Add the prerequisite for displaying the "Create HTML Snapshot" bulk action option * Add test case This test case covers the scenario where the bulk actions panel displays the corresponding options when the HTML snapshot feature is enabled. * Use the existing `tasks.create_html_snapshots()` instead of the for loop * Fix the exposure of `settings.LD_ENABLE_SNAPSHOTS` within `BookmarkListContext` * add service tests * cleanup context --------- Co-authored-by: Sascha Ißbrücker <sascha.issbruecker@gmail.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import urllib.parse
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import TestCase
|
||||
from django.test import TestCase, override_settings
|
||||
from django.urls import reverse
|
||||
|
||||
from bookmarks.models import BookmarkSearch, UserProfile
|
||||
@@ -319,6 +319,28 @@ class BookmarkArchivedViewTestCase(
|
||||
html,
|
||||
)
|
||||
|
||||
@override_settings(LD_ENABLE_SNAPSHOTS=True)
|
||||
def test_allowed_bulk_actions_with_html_snapshot_enabled(self):
|
||||
url = reverse("linkding:bookmarks.archived")
|
||||
response = self.client.get(url)
|
||||
html = response.content.decode()
|
||||
|
||||
self.assertInHTML(
|
||||
f"""
|
||||
<select name="bulk_action" class="form-select select-sm">
|
||||
<option value="bulk_unarchive">Unarchive</option>
|
||||
<option value="bulk_delete">Delete</option>
|
||||
<option value="bulk_tag">Add tags</option>
|
||||
<option value="bulk_untag">Remove tags</option>
|
||||
<option value="bulk_read">Mark as read</option>
|
||||
<option value="bulk_unread">Mark as unread</option>
|
||||
<option value="bulk_refresh">Refresh from website</option>
|
||||
<option value="bulk_snapshot">Create HTML snapshot</option>
|
||||
</select>
|
||||
""",
|
||||
html,
|
||||
)
|
||||
|
||||
def test_allowed_bulk_actions_with_sharing_enabled(self):
|
||||
user_profile = self.user.profile
|
||||
user_profile.enable_sharing = True
|
||||
@@ -345,6 +367,34 @@ class BookmarkArchivedViewTestCase(
|
||||
html,
|
||||
)
|
||||
|
||||
@override_settings(LD_ENABLE_SNAPSHOTS=True)
|
||||
def test_allowed_bulk_actions_with_sharing_and_html_snapshot_enabled(self):
|
||||
user_profile = self.user.profile
|
||||
user_profile.enable_sharing = True
|
||||
user_profile.save()
|
||||
|
||||
url = reverse("linkding:bookmarks.archived")
|
||||
response = self.client.get(url)
|
||||
html = response.content.decode()
|
||||
|
||||
self.assertInHTML(
|
||||
f"""
|
||||
<select name="bulk_action" class="form-select select-sm">
|
||||
<option value="bulk_unarchive">Unarchive</option>
|
||||
<option value="bulk_delete">Delete</option>
|
||||
<option value="bulk_tag">Add tags</option>
|
||||
<option value="bulk_untag">Remove tags</option>
|
||||
<option value="bulk_read">Mark as read</option>
|
||||
<option value="bulk_unread">Mark as unread</option>
|
||||
<option value="bulk_share">Share</option>
|
||||
<option value="bulk_unshare">Unshare</option>
|
||||
<option value="bulk_refresh">Refresh from website</option>
|
||||
<option value="bulk_snapshot">Create HTML snapshot</option>
|
||||
</select>
|
||||
""",
|
||||
html,
|
||||
)
|
||||
|
||||
def test_apply_search_preferences(self):
|
||||
# no params
|
||||
response = self.client.post(reverse("linkding:bookmarks.archived"))
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import urllib.parse
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import TestCase
|
||||
from django.test import TestCase, override_settings
|
||||
from django.urls import reverse
|
||||
|
||||
from bookmarks.models import BookmarkSearch, UserProfile
|
||||
@@ -313,6 +313,28 @@ class BookmarkIndexViewTestCase(
|
||||
html,
|
||||
)
|
||||
|
||||
@override_settings(LD_ENABLE_SNAPSHOTS=True)
|
||||
def test_allowed_bulk_actions_with_html_snapshot_enabled(self):
|
||||
url = reverse("linkding:bookmarks.index")
|
||||
response = self.client.get(url)
|
||||
html = response.content.decode()
|
||||
|
||||
self.assertInHTML(
|
||||
f"""
|
||||
<select name="bulk_action" class="form-select select-sm">
|
||||
<option value="bulk_archive">Archive</option>
|
||||
<option value="bulk_delete">Delete</option>
|
||||
<option value="bulk_tag">Add tags</option>
|
||||
<option value="bulk_untag">Remove tags</option>
|
||||
<option value="bulk_read">Mark as read</option>
|
||||
<option value="bulk_unread">Mark as unread</option>
|
||||
<option value="bulk_refresh">Refresh from website</option>
|
||||
<option value="bulk_snapshot">Create HTML snapshot</option>
|
||||
</select>
|
||||
""",
|
||||
html,
|
||||
)
|
||||
|
||||
def test_allowed_bulk_actions_with_sharing_enabled(self):
|
||||
user_profile = self.user.profile
|
||||
user_profile.enable_sharing = True
|
||||
@@ -339,6 +361,34 @@ class BookmarkIndexViewTestCase(
|
||||
html,
|
||||
)
|
||||
|
||||
@override_settings(LD_ENABLE_SNAPSHOTS=True)
|
||||
def test_allowed_bulk_actions_with_sharing_and_html_snapshot_enabled(self):
|
||||
user_profile = self.user.profile
|
||||
user_profile.enable_sharing = True
|
||||
user_profile.save()
|
||||
|
||||
url = reverse("linkding:bookmarks.index")
|
||||
response = self.client.get(url)
|
||||
html = response.content.decode()
|
||||
|
||||
self.assertInHTML(
|
||||
f"""
|
||||
<select name="bulk_action" class="form-select select-sm">
|
||||
<option value="bulk_archive">Archive</option>
|
||||
<option value="bulk_delete">Delete</option>
|
||||
<option value="bulk_tag">Add tags</option>
|
||||
<option value="bulk_untag">Remove tags</option>
|
||||
<option value="bulk_read">Mark as read</option>
|
||||
<option value="bulk_unread">Mark as unread</option>
|
||||
<option value="bulk_share">Share</option>
|
||||
<option value="bulk_unshare">Unshare</option>
|
||||
<option value="bulk_refresh">Refresh from website</option>
|
||||
<option value="bulk_snapshot">Create HTML snapshot</option>
|
||||
</select>
|
||||
""",
|
||||
html,
|
||||
)
|
||||
|
||||
def test_apply_search_preferences(self):
|
||||
# no params
|
||||
response = self.client.post(reverse("linkding:bookmarks.index"))
|
||||
|
@@ -22,6 +22,7 @@ from bookmarks.services.bookmarks import (
|
||||
unshare_bookmarks,
|
||||
enhance_with_website_metadata,
|
||||
refresh_bookmarks_metadata,
|
||||
create_html_snapshots,
|
||||
)
|
||||
from bookmarks.tests.helpers import BookmarkFactoryMixin
|
||||
|
||||
@@ -974,3 +975,73 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
|
||||
self.assertEqual(self.mock_schedule_refresh_metadata.call_count, 3)
|
||||
self.assertEqual(self.mock_load_preview_image.call_count, 3)
|
||||
|
||||
def test_create_html_snapshots(self):
|
||||
with patch.object(tasks, "create_html_snapshots") as mock_create_html_snapshots:
|
||||
bookmark1 = self.setup_bookmark()
|
||||
bookmark2 = self.setup_bookmark()
|
||||
bookmark3 = self.setup_bookmark()
|
||||
|
||||
create_html_snapshots(
|
||||
[bookmark1.id, bookmark2.id, bookmark3.id],
|
||||
self.get_or_create_test_user(),
|
||||
)
|
||||
|
||||
mock_create_html_snapshots.assert_called_once()
|
||||
call_args = mock_create_html_snapshots.call_args[0][0]
|
||||
bookmark_ids = list(call_args.values_list("id", flat=True))
|
||||
self.assertCountEqual(
|
||||
bookmark_ids, [bookmark1.id, bookmark2.id, bookmark3.id]
|
||||
)
|
||||
|
||||
def test_create_html_snapshots_should_only_create_for_specified_bookmarks(self):
|
||||
with patch.object(tasks, "create_html_snapshots") as mock_create_html_snapshots:
|
||||
bookmark1 = self.setup_bookmark()
|
||||
bookmark2 = self.setup_bookmark()
|
||||
bookmark3 = self.setup_bookmark()
|
||||
|
||||
create_html_snapshots(
|
||||
[bookmark1.id, bookmark3.id], self.get_or_create_test_user()
|
||||
)
|
||||
|
||||
mock_create_html_snapshots.assert_called_once()
|
||||
call_args = mock_create_html_snapshots.call_args[0][0]
|
||||
bookmark_ids = list(call_args.values_list("id", flat=True))
|
||||
self.assertCountEqual(bookmark_ids, [bookmark1.id, bookmark3.id])
|
||||
self.assertNotIn(bookmark2.id, bookmark_ids)
|
||||
|
||||
def test_create_html_snapshots_should_only_create_for_user_owned_bookmarks(self):
|
||||
with patch.object(tasks, "create_html_snapshots") as mock_create_html_snapshots:
|
||||
other_user = self.setup_user()
|
||||
bookmark1 = self.setup_bookmark()
|
||||
bookmark2 = self.setup_bookmark()
|
||||
inaccessible_bookmark = self.setup_bookmark(user=other_user)
|
||||
|
||||
create_html_snapshots(
|
||||
[bookmark1.id, bookmark2.id, inaccessible_bookmark.id],
|
||||
self.get_or_create_test_user(),
|
||||
)
|
||||
|
||||
mock_create_html_snapshots.assert_called_once()
|
||||
call_args = mock_create_html_snapshots.call_args[0][0]
|
||||
bookmark_ids = list(call_args.values_list("id", flat=True))
|
||||
self.assertCountEqual(bookmark_ids, [bookmark1.id, bookmark2.id])
|
||||
self.assertNotIn(inaccessible_bookmark.id, bookmark_ids)
|
||||
|
||||
def test_create_html_snapshots_should_accept_mix_of_int_and_string_ids(self):
|
||||
with patch.object(tasks, "create_html_snapshots") as mock_create_html_snapshots:
|
||||
bookmark1 = self.setup_bookmark()
|
||||
bookmark2 = self.setup_bookmark()
|
||||
bookmark3 = self.setup_bookmark()
|
||||
|
||||
create_html_snapshots(
|
||||
[str(bookmark1.id), bookmark2.id, str(bookmark3.id)],
|
||||
self.get_or_create_test_user(),
|
||||
)
|
||||
|
||||
mock_create_html_snapshots.assert_called_once()
|
||||
call_args = mock_create_html_snapshots.call_args[0][0]
|
||||
bookmark_ids = list(call_args.values_list("id", flat=True))
|
||||
self.assertCountEqual(
|
||||
bookmark_ids, [bookmark1.id, bookmark2.id, bookmark3.id]
|
||||
)
|
||||
|
Reference in New Issue
Block a user