2022-08-04 17:37:16 +00:00
|
|
|
import urllib.parse
|
|
|
|
|
2021-05-14 00:32:19 +00:00
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from django.test import TestCase
|
|
|
|
from django.urls import reverse
|
|
|
|
|
2024-09-16 10:48:19 +00:00
|
|
|
from bookmarks.models import BookmarkSearch, UserProfile
|
|
|
|
from bookmarks.tests.helpers import (
|
|
|
|
BookmarkFactoryMixin,
|
|
|
|
BookmarkListTestMixin,
|
|
|
|
TagCloudTestMixin,
|
|
|
|
)
|
2021-05-14 00:32:19 +00:00
|
|
|
|
|
|
|
|
2024-09-16 10:48:19 +00:00
|
|
|
class BookmarkIndexViewTestCase(
|
|
|
|
TestCase, BookmarkFactoryMixin, BookmarkListTestMixin, TagCloudTestMixin
|
|
|
|
):
|
2021-05-14 00:32:19 +00:00
|
|
|
def setUp(self) -> None:
|
|
|
|
user = self.get_or_create_test_user()
|
|
|
|
self.client.force_login(user)
|
|
|
|
|
2023-09-01 20:48:21 +00:00
|
|
|
def assertEditLink(self, response, url):
|
|
|
|
html = response.content.decode()
|
2024-01-27 10:29:16 +00:00
|
|
|
self.assertInHTML(
|
|
|
|
f"""
|
2023-09-01 20:48:21 +00:00
|
|
|
<a href="{url}">Edit</a>
|
2024-01-27 10:29:16 +00:00
|
|
|
""",
|
|
|
|
html,
|
|
|
|
)
|
2023-09-01 20:48:21 +00:00
|
|
|
|
|
|
|
def assertBulkActionForm(self, response, url: str):
|
2024-04-11 17:07:20 +00:00
|
|
|
soup = self.make_soup(response.content.decode())
|
|
|
|
form = soup.select_one("form.bookmark-actions")
|
|
|
|
self.assertIsNotNone(form)
|
|
|
|
self.assertEqual(form.attrs["action"], url)
|
2023-09-01 20:48:21 +00:00
|
|
|
|
2021-05-14 00:32:19 +00:00
|
|
|
def test_should_list_unarchived_and_user_owned_bookmarks(self):
|
2024-01-27 10:29:16 +00:00
|
|
|
other_user = User.objects.create_user(
|
|
|
|
"otheruser", "otheruser@example.com", "password123"
|
|
|
|
)
|
2023-10-01 19:22:44 +00:00
|
|
|
visible_bookmarks = self.setup_numbered_bookmarks(3)
|
2021-05-14 00:32:19 +00:00
|
|
|
invisible_bookmarks = [
|
|
|
|
self.setup_bookmark(is_archived=True),
|
|
|
|
self.setup_bookmark(user=other_user),
|
|
|
|
]
|
|
|
|
|
2024-01-27 10:29:16 +00:00
|
|
|
response = self.client.get(reverse("bookmarks:index"))
|
2021-05-14 00:32:19 +00:00
|
|
|
|
|
|
|
self.assertVisibleBookmarks(response, visible_bookmarks)
|
|
|
|
self.assertInvisibleBookmarks(response, invisible_bookmarks)
|
|
|
|
|
|
|
|
def test_should_list_bookmarks_matching_query(self):
|
2024-01-27 10:29:16 +00:00
|
|
|
visible_bookmarks = self.setup_numbered_bookmarks(3, prefix="foo")
|
|
|
|
invisible_bookmarks = self.setup_numbered_bookmarks(3, prefix="bar")
|
2021-05-14 00:32:19 +00:00
|
|
|
|
2024-01-27 10:29:16 +00:00
|
|
|
response = self.client.get(reverse("bookmarks:index") + "?q=foo")
|
2021-05-14 00:32:19 +00:00
|
|
|
|
|
|
|
self.assertVisibleBookmarks(response, visible_bookmarks)
|
|
|
|
self.assertInvisibleBookmarks(response, invisible_bookmarks)
|
|
|
|
|
|
|
|
def test_should_list_tags_for_unarchived_and_user_owned_bookmarks(self):
|
2024-01-27 10:29:16 +00:00
|
|
|
other_user = User.objects.create_user(
|
|
|
|
"otheruser", "otheruser@example.com", "password123"
|
|
|
|
)
|
2023-10-01 19:22:44 +00:00
|
|
|
visible_bookmarks = self.setup_numbered_bookmarks(3, with_tags=True)
|
2024-01-27 10:29:16 +00:00
|
|
|
archived_bookmarks = self.setup_numbered_bookmarks(
|
|
|
|
3, with_tags=True, archived=True, tag_prefix="archived"
|
|
|
|
)
|
|
|
|
other_user_bookmarks = self.setup_numbered_bookmarks(
|
|
|
|
3, with_tags=True, user=other_user, tag_prefix="otheruser"
|
|
|
|
)
|
2021-05-14 00:32:19 +00:00
|
|
|
|
2023-10-01 19:22:44 +00:00
|
|
|
visible_tags = self.get_tags_from_bookmarks(visible_bookmarks)
|
2024-01-27 10:29:16 +00:00
|
|
|
invisible_tags = self.get_tags_from_bookmarks(
|
|
|
|
archived_bookmarks + other_user_bookmarks
|
|
|
|
)
|
2021-05-14 00:32:19 +00:00
|
|
|
|
2024-01-27 10:29:16 +00:00
|
|
|
response = self.client.get(reverse("bookmarks:index"))
|
2021-05-14 00:32:19 +00:00
|
|
|
|
|
|
|
self.assertVisibleTags(response, visible_tags)
|
|
|
|
self.assertInvisibleTags(response, invisible_tags)
|
|
|
|
|
|
|
|
def test_should_list_tags_for_bookmarks_matching_query(self):
|
2024-01-27 10:29:16 +00:00
|
|
|
visible_bookmarks = self.setup_numbered_bookmarks(
|
|
|
|
3, with_tags=True, prefix="foo", tag_prefix="foo"
|
|
|
|
)
|
|
|
|
invisible_bookmarks = self.setup_numbered_bookmarks(
|
|
|
|
3, with_tags=True, prefix="bar", tag_prefix="bar"
|
|
|
|
)
|
2021-05-14 00:32:19 +00:00
|
|
|
|
2023-10-01 19:22:44 +00:00
|
|
|
visible_tags = self.get_tags_from_bookmarks(visible_bookmarks)
|
|
|
|
invisible_tags = self.get_tags_from_bookmarks(invisible_bookmarks)
|
2021-05-14 00:32:19 +00:00
|
|
|
|
2024-01-27 10:29:16 +00:00
|
|
|
response = self.client.get(reverse("bookmarks:index") + "?q=foo")
|
2021-05-14 00:32:19 +00:00
|
|
|
|
|
|
|
self.assertVisibleTags(response, visible_tags)
|
|
|
|
self.assertInvisibleTags(response, invisible_tags)
|
2021-10-03 07:35:59 +00:00
|
|
|
|
2023-10-01 19:22:44 +00:00
|
|
|
def test_should_list_bookmarks_and_tags_for_search_preferences(self):
|
|
|
|
user_profile = self.user.profile
|
|
|
|
user_profile.search_preferences = {
|
2024-01-27 10:29:16 +00:00
|
|
|
"unread": BookmarkSearch.FILTER_UNREAD_YES,
|
2023-10-01 19:22:44 +00:00
|
|
|
}
|
|
|
|
user_profile.save()
|
|
|
|
|
2024-01-27 10:29:16 +00:00
|
|
|
unread_bookmarks = self.setup_numbered_bookmarks(
|
|
|
|
3, unread=True, with_tags=True, prefix="unread", tag_prefix="unread"
|
|
|
|
)
|
|
|
|
read_bookmarks = self.setup_numbered_bookmarks(
|
|
|
|
3, unread=False, with_tags=True, prefix="read", tag_prefix="read"
|
|
|
|
)
|
2023-10-01 19:22:44 +00:00
|
|
|
|
|
|
|
unread_tags = self.get_tags_from_bookmarks(unread_bookmarks)
|
|
|
|
read_tags = self.get_tags_from_bookmarks(read_bookmarks)
|
|
|
|
|
2024-01-27 10:29:16 +00:00
|
|
|
response = self.client.get(reverse("bookmarks:index"))
|
2023-10-01 19:22:44 +00:00
|
|
|
self.assertVisibleBookmarks(response, unread_bookmarks)
|
|
|
|
self.assertInvisibleBookmarks(response, read_bookmarks)
|
|
|
|
self.assertVisibleTags(response, unread_tags)
|
|
|
|
self.assertInvisibleTags(response, read_tags)
|
|
|
|
|
2022-08-04 18:31:24 +00:00
|
|
|
def test_should_display_selected_tags_from_query(self):
|
|
|
|
tags = [
|
|
|
|
self.setup_tag(),
|
|
|
|
self.setup_tag(),
|
|
|
|
self.setup_tag(),
|
|
|
|
self.setup_tag(),
|
|
|
|
self.setup_tag(),
|
|
|
|
]
|
|
|
|
self.setup_bookmark(tags=tags)
|
|
|
|
|
2024-01-27 10:29:16 +00:00
|
|
|
response = self.client.get(
|
|
|
|
reverse("bookmarks:index")
|
|
|
|
+ f"?q=%23{tags[0].name}+%23{tags[1].name.upper()}"
|
|
|
|
)
|
2023-05-18 07:06:22 +00:00
|
|
|
|
|
|
|
self.assertSelectedTags(response, [tags[0], tags[1]])
|
|
|
|
|
2024-01-27 10:29:16 +00:00
|
|
|
def test_should_not_display_search_terms_from_query_as_selected_tags_in_strict_mode(
|
|
|
|
self,
|
|
|
|
):
|
2023-05-18 07:06:22 +00:00
|
|
|
tags = [
|
|
|
|
self.setup_tag(),
|
|
|
|
self.setup_tag(),
|
|
|
|
self.setup_tag(),
|
|
|
|
self.setup_tag(),
|
|
|
|
self.setup_tag(),
|
|
|
|
]
|
|
|
|
self.setup_bookmark(title=tags[0].name, tags=tags)
|
|
|
|
|
2024-01-27 10:29:16 +00:00
|
|
|
response = self.client.get(
|
|
|
|
reverse("bookmarks:index") + f"?q={tags[0].name}+%23{tags[1].name.upper()}"
|
|
|
|
)
|
2023-05-18 07:06:22 +00:00
|
|
|
|
|
|
|
self.assertSelectedTags(response, [tags[1]])
|
|
|
|
|
|
|
|
def test_should_display_search_terms_from_query_as_selected_tags_in_lax_mode(self):
|
|
|
|
self.user.profile.tag_search = UserProfile.TAG_SEARCH_LAX
|
|
|
|
self.user.profile.save()
|
|
|
|
|
|
|
|
tags = [
|
|
|
|
self.setup_tag(),
|
|
|
|
self.setup_tag(),
|
|
|
|
self.setup_tag(),
|
|
|
|
self.setup_tag(),
|
|
|
|
self.setup_tag(),
|
|
|
|
]
|
|
|
|
self.setup_bookmark(tags=tags)
|
|
|
|
|
2024-01-27 10:29:16 +00:00
|
|
|
response = self.client.get(
|
|
|
|
reverse("bookmarks:index") + f"?q={tags[0].name}+%23{tags[1].name.upper()}"
|
|
|
|
)
|
2022-08-04 18:31:24 +00:00
|
|
|
|
|
|
|
self.assertSelectedTags(response, [tags[0], tags[1]])
|
|
|
|
|
2021-10-03 07:35:59 +00:00
|
|
|
def test_should_open_bookmarks_in_new_page_by_default(self):
|
2023-10-01 19:22:44 +00:00
|
|
|
visible_bookmarks = self.setup_numbered_bookmarks(3)
|
2021-10-03 07:35:59 +00:00
|
|
|
|
2024-01-27 10:29:16 +00:00
|
|
|
response = self.client.get(reverse("bookmarks:index"))
|
2021-10-03 07:35:59 +00:00
|
|
|
|
2024-01-27 10:29:16 +00:00
|
|
|
self.assertVisibleBookmarks(response, visible_bookmarks, "_blank")
|
2021-10-03 07:35:59 +00:00
|
|
|
|
|
|
|
def test_should_open_bookmarks_in_same_page_if_specified_in_user_profile(self):
|
|
|
|
user = self.get_or_create_test_user()
|
|
|
|
user.profile.bookmark_link_target = UserProfile.BOOKMARK_LINK_TARGET_SELF
|
|
|
|
user.profile.save()
|
|
|
|
|
2023-10-01 19:22:44 +00:00
|
|
|
visible_bookmarks = self.setup_numbered_bookmarks(3)
|
2021-10-03 07:35:59 +00:00
|
|
|
|
2024-01-27 10:29:16 +00:00
|
|
|
response = self.client.get(reverse("bookmarks:index"))
|
2021-10-03 07:35:59 +00:00
|
|
|
|
2024-01-27 10:29:16 +00:00
|
|
|
self.assertVisibleBookmarks(response, visible_bookmarks, "_self")
|
2022-08-04 17:37:16 +00:00
|
|
|
|
2023-09-01 20:48:21 +00:00
|
|
|
def test_edit_link_return_url_respects_search_options(self):
|
2024-01-27 10:29:16 +00:00
|
|
|
bookmark = self.setup_bookmark(title="foo")
|
|
|
|
edit_url = reverse("bookmarks:edit", args=[bookmark.id])
|
|
|
|
base_url = reverse("bookmarks:index")
|
2022-08-04 17:37:16 +00:00
|
|
|
|
|
|
|
# without query params
|
2023-09-01 20:48:21 +00:00
|
|
|
return_url = urllib.parse.quote(base_url)
|
2024-01-27 10:29:16 +00:00
|
|
|
url = f"{edit_url}?return_url={return_url}"
|
2022-08-04 17:37:16 +00:00
|
|
|
|
2023-09-01 20:48:21 +00:00
|
|
|
response = self.client.get(base_url)
|
|
|
|
self.assertEditLink(response, url)
|
2022-08-04 17:37:16 +00:00
|
|
|
|
2023-09-01 20:48:21 +00:00
|
|
|
# with query
|
2024-01-27 10:29:16 +00:00
|
|
|
url_params = "?q=foo"
|
2023-09-01 20:48:21 +00:00
|
|
|
return_url = urllib.parse.quote(base_url + url_params)
|
2024-01-27 10:29:16 +00:00
|
|
|
url = f"{edit_url}?return_url={return_url}"
|
2022-08-04 17:37:16 +00:00
|
|
|
|
2023-09-01 20:48:21 +00:00
|
|
|
response = self.client.get(base_url + url_params)
|
|
|
|
self.assertEditLink(response, url)
|
|
|
|
|
|
|
|
# with query and sort and page
|
2024-01-27 10:29:16 +00:00
|
|
|
url_params = "?q=foo&sort=title_asc&page=2"
|
2023-09-01 20:48:21 +00:00
|
|
|
return_url = urllib.parse.quote(base_url + url_params)
|
2024-01-27 10:29:16 +00:00
|
|
|
url = f"{edit_url}?return_url={return_url}"
|
2023-09-01 20:48:21 +00:00
|
|
|
|
|
|
|
response = self.client.get(base_url + url_params)
|
|
|
|
self.assertEditLink(response, url)
|
|
|
|
|
|
|
|
def test_bulk_edit_respects_search_options(self):
|
2024-01-27 10:29:16 +00:00
|
|
|
action_url = reverse("bookmarks:index.action")
|
|
|
|
base_url = reverse("bookmarks:index")
|
2023-09-01 20:48:21 +00:00
|
|
|
|
|
|
|
# without params
|
2024-09-16 10:48:19 +00:00
|
|
|
url = f"{action_url}"
|
2023-09-01 20:48:21 +00:00
|
|
|
|
|
|
|
response = self.client.get(base_url)
|
|
|
|
self.assertBulkActionForm(response, url)
|
|
|
|
|
|
|
|
# with query
|
2024-01-27 10:29:16 +00:00
|
|
|
url_params = "?q=foo"
|
2024-09-16 10:48:19 +00:00
|
|
|
url = f"{action_url}?q=foo"
|
2023-09-01 20:48:21 +00:00
|
|
|
|
|
|
|
response = self.client.get(base_url + url_params)
|
|
|
|
self.assertBulkActionForm(response, url)
|
|
|
|
|
|
|
|
# with query and sort
|
2024-01-27 10:29:16 +00:00
|
|
|
url_params = "?q=foo&sort=title_asc"
|
2024-09-16 10:48:19 +00:00
|
|
|
url = f"{action_url}?q=foo&sort=title_asc"
|
2023-09-01 20:48:21 +00:00
|
|
|
|
|
|
|
response = self.client.get(base_url + url_params)
|
|
|
|
self.assertBulkActionForm(response, url)
|
2023-08-25 11:54:23 +00:00
|
|
|
|
|
|
|
def test_allowed_bulk_actions(self):
|
2024-01-27 10:29:16 +00:00
|
|
|
url = reverse("bookmarks:index")
|
2023-08-25 11:54:23 +00:00
|
|
|
response = self.client.get(url)
|
|
|
|
html = response.content.decode()
|
|
|
|
|
2024-01-27 10:29:16 +00:00
|
|
|
self.assertInHTML(
|
|
|
|
f"""
|
2023-08-25 11:54:23 +00:00
|
|
|
<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>
|
|
|
|
</select>
|
2024-01-27 10:29:16 +00:00
|
|
|
""",
|
|
|
|
html,
|
|
|
|
)
|
2023-08-25 11:54:23 +00:00
|
|
|
|
|
|
|
def test_allowed_bulk_actions_with_sharing_enabled(self):
|
|
|
|
user_profile = self.user.profile
|
|
|
|
user_profile.enable_sharing = True
|
|
|
|
user_profile.save()
|
|
|
|
|
2024-01-27 10:29:16 +00:00
|
|
|
url = reverse("bookmarks:index")
|
2023-08-25 11:54:23 +00:00
|
|
|
response = self.client.get(url)
|
|
|
|
html = response.content.decode()
|
|
|
|
|
2024-01-27 10:29:16 +00:00
|
|
|
self.assertInHTML(
|
|
|
|
f"""
|
2023-08-25 11:54:23 +00:00
|
|
|
<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>
|
|
|
|
</select>
|
2024-01-27 10:29:16 +00:00
|
|
|
""",
|
|
|
|
html,
|
|
|
|
)
|
2023-09-26 06:34:43 +00:00
|
|
|
|
2023-10-01 19:22:44 +00:00
|
|
|
def test_apply_search_preferences(self):
|
|
|
|
# no params
|
2024-01-27 10:29:16 +00:00
|
|
|
response = self.client.post(reverse("bookmarks:index"))
|
2023-10-01 19:22:44 +00:00
|
|
|
self.assertEqual(response.status_code, 302)
|
2024-01-27 10:29:16 +00:00
|
|
|
self.assertEqual(response.url, reverse("bookmarks:index"))
|
2023-10-01 19:22:44 +00:00
|
|
|
|
|
|
|
# some params
|
2024-01-27 10:29:16 +00:00
|
|
|
response = self.client.post(
|
|
|
|
reverse("bookmarks:index"),
|
|
|
|
{
|
|
|
|
"q": "foo",
|
|
|
|
"sort": BookmarkSearch.SORT_TITLE_ASC,
|
|
|
|
},
|
|
|
|
)
|
2023-10-01 19:22:44 +00:00
|
|
|
self.assertEqual(response.status_code, 302)
|
2024-01-27 10:29:16 +00:00
|
|
|
self.assertEqual(
|
|
|
|
response.url, reverse("bookmarks:index") + "?q=foo&sort=title_asc"
|
|
|
|
)
|
2023-10-01 19:22:44 +00:00
|
|
|
|
|
|
|
# params with default value are removed
|
2024-01-27 10:29:16 +00:00
|
|
|
response = self.client.post(
|
|
|
|
reverse("bookmarks:index"),
|
|
|
|
{
|
|
|
|
"q": "foo",
|
|
|
|
"user": "",
|
|
|
|
"sort": BookmarkSearch.SORT_ADDED_DESC,
|
|
|
|
"shared": BookmarkSearch.FILTER_SHARED_OFF,
|
|
|
|
"unread": BookmarkSearch.FILTER_UNREAD_YES,
|
|
|
|
},
|
|
|
|
)
|
2023-10-01 19:22:44 +00:00
|
|
|
self.assertEqual(response.status_code, 302)
|
2024-01-27 10:29:16 +00:00
|
|
|
self.assertEqual(response.url, reverse("bookmarks:index") + "?q=foo&unread=yes")
|
2023-10-01 19:22:44 +00:00
|
|
|
|
|
|
|
# page is removed
|
2024-01-27 10:29:16 +00:00
|
|
|
response = self.client.post(
|
|
|
|
reverse("bookmarks:index"),
|
|
|
|
{
|
|
|
|
"q": "foo",
|
|
|
|
"page": "2",
|
|
|
|
"sort": BookmarkSearch.SORT_TITLE_ASC,
|
|
|
|
},
|
|
|
|
)
|
2023-10-01 19:22:44 +00:00
|
|
|
self.assertEqual(response.status_code, 302)
|
2024-01-27 10:29:16 +00:00
|
|
|
self.assertEqual(
|
|
|
|
response.url, reverse("bookmarks:index") + "?q=foo&sort=title_asc"
|
|
|
|
)
|
2023-10-01 19:22:44 +00:00
|
|
|
|
|
|
|
def test_save_search_preferences(self):
|
|
|
|
user_profile = self.user.profile
|
|
|
|
|
|
|
|
# no params
|
2024-01-27 10:29:16 +00:00
|
|
|
self.client.post(
|
|
|
|
reverse("bookmarks:index"),
|
|
|
|
{
|
|
|
|
"save": "",
|
|
|
|
},
|
|
|
|
)
|
2023-10-01 19:22:44 +00:00
|
|
|
user_profile.refresh_from_db()
|
2024-01-27 10:29:16 +00:00
|
|
|
self.assertEqual(
|
|
|
|
user_profile.search_preferences,
|
|
|
|
{
|
|
|
|
"sort": BookmarkSearch.SORT_ADDED_DESC,
|
|
|
|
"shared": BookmarkSearch.FILTER_SHARED_OFF,
|
|
|
|
"unread": BookmarkSearch.FILTER_UNREAD_OFF,
|
|
|
|
},
|
|
|
|
)
|
2023-10-01 19:22:44 +00:00
|
|
|
|
|
|
|
# with param
|
2024-01-27 10:29:16 +00:00
|
|
|
self.client.post(
|
|
|
|
reverse("bookmarks:index"),
|
|
|
|
{
|
|
|
|
"save": "",
|
|
|
|
"sort": BookmarkSearch.SORT_TITLE_ASC,
|
|
|
|
},
|
|
|
|
)
|
2023-10-01 19:22:44 +00:00
|
|
|
user_profile.refresh_from_db()
|
2024-01-27 10:29:16 +00:00
|
|
|
self.assertEqual(
|
|
|
|
user_profile.search_preferences,
|
|
|
|
{
|
|
|
|
"sort": BookmarkSearch.SORT_TITLE_ASC,
|
|
|
|
"shared": BookmarkSearch.FILTER_SHARED_OFF,
|
|
|
|
"unread": BookmarkSearch.FILTER_UNREAD_OFF,
|
|
|
|
},
|
|
|
|
)
|
2023-10-01 19:22:44 +00:00
|
|
|
|
|
|
|
# add a param
|
2024-01-27 10:29:16 +00:00
|
|
|
self.client.post(
|
|
|
|
reverse("bookmarks:index"),
|
|
|
|
{
|
|
|
|
"save": "",
|
|
|
|
"sort": BookmarkSearch.SORT_TITLE_ASC,
|
|
|
|
"unread": BookmarkSearch.FILTER_UNREAD_YES,
|
|
|
|
},
|
|
|
|
)
|
2023-10-01 19:22:44 +00:00
|
|
|
user_profile.refresh_from_db()
|
2024-01-27 10:29:16 +00:00
|
|
|
self.assertEqual(
|
|
|
|
user_profile.search_preferences,
|
|
|
|
{
|
|
|
|
"sort": BookmarkSearch.SORT_TITLE_ASC,
|
|
|
|
"shared": BookmarkSearch.FILTER_SHARED_OFF,
|
|
|
|
"unread": BookmarkSearch.FILTER_UNREAD_YES,
|
|
|
|
},
|
|
|
|
)
|
2023-10-01 19:22:44 +00:00
|
|
|
|
|
|
|
# remove a param
|
2024-01-27 10:29:16 +00:00
|
|
|
self.client.post(
|
|
|
|
reverse("bookmarks:index"),
|
|
|
|
{
|
|
|
|
"save": "",
|
|
|
|
"unread": BookmarkSearch.FILTER_UNREAD_YES,
|
|
|
|
},
|
|
|
|
)
|
2023-10-01 19:22:44 +00:00
|
|
|
user_profile.refresh_from_db()
|
2024-01-27 10:29:16 +00:00
|
|
|
self.assertEqual(
|
|
|
|
user_profile.search_preferences,
|
|
|
|
{
|
|
|
|
"sort": BookmarkSearch.SORT_ADDED_DESC,
|
|
|
|
"shared": BookmarkSearch.FILTER_SHARED_OFF,
|
|
|
|
"unread": BookmarkSearch.FILTER_UNREAD_YES,
|
|
|
|
},
|
|
|
|
)
|
2023-10-01 19:22:44 +00:00
|
|
|
|
|
|
|
# ignores non-preferences
|
2024-01-27 10:29:16 +00:00
|
|
|
self.client.post(
|
|
|
|
reverse("bookmarks:index"),
|
|
|
|
{
|
|
|
|
"save": "",
|
|
|
|
"q": "foo",
|
|
|
|
"user": "john",
|
|
|
|
"page": "3",
|
|
|
|
"sort": BookmarkSearch.SORT_TITLE_ASC,
|
|
|
|
},
|
|
|
|
)
|
2023-10-01 19:22:44 +00:00
|
|
|
user_profile.refresh_from_db()
|
2024-01-27 10:29:16 +00:00
|
|
|
self.assertEqual(
|
|
|
|
user_profile.search_preferences,
|
|
|
|
{
|
|
|
|
"sort": BookmarkSearch.SORT_TITLE_ASC,
|
|
|
|
"shared": BookmarkSearch.FILTER_SHARED_OFF,
|
|
|
|
"unread": BookmarkSearch.FILTER_UNREAD_OFF,
|
|
|
|
},
|
|
|
|
)
|
2023-10-01 19:22:44 +00:00
|
|
|
|
2023-09-26 06:34:43 +00:00
|
|
|
def test_url_encode_bookmark_actions_url(self):
|
2024-01-27 10:29:16 +00:00
|
|
|
url = reverse("bookmarks:index") + "?q=%23foo"
|
2023-09-26 06:34:43 +00:00
|
|
|
response = self.client.get(url)
|
|
|
|
html = response.content.decode()
|
|
|
|
soup = self.make_soup(html)
|
2024-01-27 10:29:16 +00:00
|
|
|
actions_form = soup.select("form.bookmark-actions")[0]
|
2023-09-26 06:34:43 +00:00
|
|
|
|
2024-01-27 10:29:16 +00:00
|
|
|
self.assertEqual(
|
|
|
|
actions_form.attrs["action"],
|
2024-09-16 10:48:19 +00:00
|
|
|
"/bookmarks/action?q=%23foo",
|
2024-01-27 10:29:16 +00:00
|
|
|
)
|
2023-12-08 20:53:54 +00:00
|
|
|
|
|
|
|
def test_encode_search_params(self):
|
2024-01-27 10:29:16 +00:00
|
|
|
bookmark = self.setup_bookmark(description="alert('xss')")
|
2023-12-08 20:53:54 +00:00
|
|
|
|
2024-01-27 10:29:16 +00:00
|
|
|
url = reverse("bookmarks:index") + "?q=alert(%27xss%27)"
|
2023-12-08 20:53:54 +00:00
|
|
|
response = self.client.get(url)
|
2024-01-27 10:29:16 +00:00
|
|
|
self.assertNotContains(response, "alert('xss')")
|
2023-12-08 20:53:54 +00:00
|
|
|
self.assertContains(response, bookmark.url)
|
|
|
|
|
2024-01-27 10:29:16 +00:00
|
|
|
url = reverse("bookmarks:index") + "?sort=alert(%27xss%27)"
|
2023-12-08 20:53:54 +00:00
|
|
|
response = self.client.get(url)
|
2024-01-27 10:29:16 +00:00
|
|
|
self.assertNotContains(response, "alert('xss')")
|
2023-12-08 20:53:54 +00:00
|
|
|
|
2024-01-27 10:29:16 +00:00
|
|
|
url = reverse("bookmarks:index") + "?unread=alert(%27xss%27)"
|
2023-12-08 20:53:54 +00:00
|
|
|
response = self.client.get(url)
|
2024-01-27 10:29:16 +00:00
|
|
|
self.assertNotContains(response, "alert('xss')")
|
2023-12-08 20:53:54 +00:00
|
|
|
|
2024-01-27 10:29:16 +00:00
|
|
|
url = reverse("bookmarks:index") + "?shared=alert(%27xss%27)"
|
2023-12-08 20:53:54 +00:00
|
|
|
response = self.client.get(url)
|
2024-01-27 10:29:16 +00:00
|
|
|
self.assertNotContains(response, "alert('xss')")
|
2023-12-08 20:53:54 +00:00
|
|
|
|
2024-01-27 10:29:16 +00:00
|
|
|
url = reverse("bookmarks:index") + "?user=alert(%27xss%27)"
|
2023-12-08 20:53:54 +00:00
|
|
|
response = self.client.get(url)
|
2024-01-27 10:29:16 +00:00
|
|
|
self.assertNotContains(response, "alert('xss')")
|
2023-12-08 20:53:54 +00:00
|
|
|
|
2024-01-27 10:29:16 +00:00
|
|
|
url = reverse("bookmarks:index") + "?page=alert(%27xss%27)"
|
2023-12-08 20:53:54 +00:00
|
|
|
response = self.client.get(url)
|
2024-01-27 10:29:16 +00:00
|
|
|
self.assertNotContains(response, "alert('xss')")
|
2024-09-16 10:48:19 +00:00
|
|
|
|
|
|
|
def test_turbo_frame_details_modal_renders_details_modal_update(self):
|
|
|
|
bookmark = self.setup_bookmark()
|
|
|
|
url = reverse("bookmarks:index") + f"?bookmark_id={bookmark.id}"
|
|
|
|
response = self.client.get(url, headers={"Turbo-Frame": "details-modal"})
|
|
|
|
|
|
|
|
self.assertEqual(200, response.status_code)
|
|
|
|
|
|
|
|
soup = self.make_soup(response.content.decode())
|
|
|
|
self.assertIsNotNone(soup.select_one("turbo-frame#details-modal"))
|
|
|
|
self.assertIsNone(soup.select_one("#bookmark-list-container"))
|
|
|
|
self.assertIsNone(soup.select_one("#tag-cloud-container"))
|