mirror of
https://github.com/sissbruecker/linkding.git
synced 2025-09-22 00:49:34 +02:00
Add black code formatter
This commit is contained in:
@@ -7,9 +7,21 @@ from django.utils import timezone
|
||||
from bookmarks.models import Bookmark, Tag
|
||||
from bookmarks.services import tasks
|
||||
from bookmarks.services import website_loader
|
||||
from bookmarks.services.bookmarks import create_bookmark, update_bookmark, archive_bookmark, archive_bookmarks, \
|
||||
unarchive_bookmark, unarchive_bookmarks, delete_bookmarks, tag_bookmarks, untag_bookmarks, mark_bookmarks_as_read, \
|
||||
mark_bookmarks_as_unread, share_bookmarks, unshare_bookmarks
|
||||
from bookmarks.services.bookmarks import (
|
||||
create_bookmark,
|
||||
update_bookmark,
|
||||
archive_bookmark,
|
||||
archive_bookmarks,
|
||||
unarchive_bookmark,
|
||||
unarchive_bookmarks,
|
||||
delete_bookmarks,
|
||||
tag_bookmarks,
|
||||
untag_bookmarks,
|
||||
mark_bookmarks_as_read,
|
||||
mark_bookmarks_as_unread,
|
||||
share_bookmarks,
|
||||
unshare_bookmarks,
|
||||
)
|
||||
from bookmarks.services.website_loader import WebsiteMetadata
|
||||
from bookmarks.tests.helpers import BookmarkFactoryMixin
|
||||
|
||||
@@ -22,36 +34,48 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
self.get_or_create_test_user()
|
||||
|
||||
def test_create_should_update_website_metadata(self):
|
||||
with patch.object(website_loader, 'load_website_metadata') as mock_load_website_metadata:
|
||||
with patch.object(
|
||||
website_loader, "load_website_metadata"
|
||||
) as mock_load_website_metadata:
|
||||
expected_metadata = WebsiteMetadata(
|
||||
'https://example.com',
|
||||
'Website title',
|
||||
'Website description'
|
||||
"https://example.com", "Website title", "Website description"
|
||||
)
|
||||
mock_load_website_metadata.return_value = expected_metadata
|
||||
|
||||
bookmark_data = Bookmark(url='https://example.com',
|
||||
title='Updated Title',
|
||||
description='Updated description',
|
||||
unread=True,
|
||||
shared=True,
|
||||
is_archived=True)
|
||||
created_bookmark = create_bookmark(bookmark_data, '', self.get_or_create_test_user())
|
||||
bookmark_data = Bookmark(
|
||||
url="https://example.com",
|
||||
title="Updated Title",
|
||||
description="Updated description",
|
||||
unread=True,
|
||||
shared=True,
|
||||
is_archived=True,
|
||||
)
|
||||
created_bookmark = create_bookmark(
|
||||
bookmark_data, "", self.get_or_create_test_user()
|
||||
)
|
||||
|
||||
created_bookmark.refresh_from_db()
|
||||
self.assertEqual(expected_metadata.title, created_bookmark.website_title)
|
||||
self.assertEqual(expected_metadata.description, created_bookmark.website_description)
|
||||
self.assertEqual(
|
||||
expected_metadata.description, created_bookmark.website_description
|
||||
)
|
||||
|
||||
def test_create_should_update_existing_bookmark_with_same_url(self):
|
||||
original_bookmark = self.setup_bookmark(url='https://example.com', unread=False, shared=False)
|
||||
bookmark_data = Bookmark(url='https://example.com',
|
||||
title='Updated Title',
|
||||
description='Updated description',
|
||||
notes='Updated notes',
|
||||
unread=True,
|
||||
shared=True,
|
||||
is_archived=True)
|
||||
updated_bookmark = create_bookmark(bookmark_data, '', self.get_or_create_test_user())
|
||||
original_bookmark = self.setup_bookmark(
|
||||
url="https://example.com", unread=False, shared=False
|
||||
)
|
||||
bookmark_data = Bookmark(
|
||||
url="https://example.com",
|
||||
title="Updated Title",
|
||||
description="Updated description",
|
||||
notes="Updated notes",
|
||||
unread=True,
|
||||
shared=True,
|
||||
is_archived=True,
|
||||
)
|
||||
updated_bookmark = create_bookmark(
|
||||
bookmark_data, "", self.get_or_create_test_user()
|
||||
)
|
||||
|
||||
self.assertEqual(Bookmark.objects.count(), 1)
|
||||
self.assertEqual(updated_bookmark.id, original_bookmark.id)
|
||||
@@ -64,75 +88,91 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
self.assertFalse(updated_bookmark.is_archived)
|
||||
|
||||
def test_create_should_create_web_archive_snapshot(self):
|
||||
with patch.object(tasks, 'create_web_archive_snapshot') as mock_create_web_archive_snapshot:
|
||||
bookmark_data = Bookmark(url='https://example.com')
|
||||
bookmark = create_bookmark(bookmark_data, 'tag1,tag2', self.user)
|
||||
with patch.object(
|
||||
tasks, "create_web_archive_snapshot"
|
||||
) as mock_create_web_archive_snapshot:
|
||||
bookmark_data = Bookmark(url="https://example.com")
|
||||
bookmark = create_bookmark(bookmark_data, "tag1,tag2", self.user)
|
||||
|
||||
mock_create_web_archive_snapshot.assert_called_once_with(self.user, bookmark, False)
|
||||
mock_create_web_archive_snapshot.assert_called_once_with(
|
||||
self.user, bookmark, False
|
||||
)
|
||||
|
||||
def test_create_should_load_favicon(self):
|
||||
with patch.object(tasks, 'load_favicon') as mock_load_favicon:
|
||||
bookmark_data = Bookmark(url='https://example.com')
|
||||
bookmark = create_bookmark(bookmark_data, 'tag1,tag2', self.user)
|
||||
with patch.object(tasks, "load_favicon") as mock_load_favicon:
|
||||
bookmark_data = Bookmark(url="https://example.com")
|
||||
bookmark = create_bookmark(bookmark_data, "tag1,tag2", self.user)
|
||||
|
||||
mock_load_favicon.assert_called_once_with(self.user, bookmark)
|
||||
|
||||
def test_update_should_create_web_archive_snapshot_if_url_did_change(self):
|
||||
with patch.object(tasks, 'create_web_archive_snapshot') as mock_create_web_archive_snapshot:
|
||||
with patch.object(
|
||||
tasks, "create_web_archive_snapshot"
|
||||
) as mock_create_web_archive_snapshot:
|
||||
bookmark = self.setup_bookmark()
|
||||
bookmark.url = 'https://example.com/updated'
|
||||
update_bookmark(bookmark, 'tag1,tag2', self.user)
|
||||
bookmark.url = "https://example.com/updated"
|
||||
update_bookmark(bookmark, "tag1,tag2", self.user)
|
||||
|
||||
mock_create_web_archive_snapshot.assert_called_once_with(self.user, bookmark, True)
|
||||
mock_create_web_archive_snapshot.assert_called_once_with(
|
||||
self.user, bookmark, True
|
||||
)
|
||||
|
||||
def test_update_should_not_create_web_archive_snapshot_if_url_did_not_change(self):
|
||||
with patch.object(tasks, 'create_web_archive_snapshot') as mock_create_web_archive_snapshot:
|
||||
with patch.object(
|
||||
tasks, "create_web_archive_snapshot"
|
||||
) as mock_create_web_archive_snapshot:
|
||||
bookmark = self.setup_bookmark()
|
||||
bookmark.title = 'updated title'
|
||||
update_bookmark(bookmark, 'tag1,tag2', self.user)
|
||||
bookmark.title = "updated title"
|
||||
update_bookmark(bookmark, "tag1,tag2", self.user)
|
||||
|
||||
mock_create_web_archive_snapshot.assert_not_called()
|
||||
|
||||
def test_update_should_update_website_metadata_if_url_did_change(self):
|
||||
with patch.object(website_loader, 'load_website_metadata') as mock_load_website_metadata:
|
||||
with patch.object(
|
||||
website_loader, "load_website_metadata"
|
||||
) as mock_load_website_metadata:
|
||||
expected_metadata = WebsiteMetadata(
|
||||
'https://example.com/updated',
|
||||
'Updated website title',
|
||||
'Updated website description'
|
||||
"https://example.com/updated",
|
||||
"Updated website title",
|
||||
"Updated website description",
|
||||
)
|
||||
mock_load_website_metadata.return_value = expected_metadata
|
||||
|
||||
bookmark = self.setup_bookmark()
|
||||
bookmark.url = 'https://example.com/updated'
|
||||
update_bookmark(bookmark, 'tag1,tag2', self.user)
|
||||
bookmark.url = "https://example.com/updated"
|
||||
update_bookmark(bookmark, "tag1,tag2", self.user)
|
||||
|
||||
bookmark.refresh_from_db()
|
||||
mock_load_website_metadata.assert_called_once()
|
||||
self.assertEqual(expected_metadata.title, bookmark.website_title)
|
||||
self.assertEqual(expected_metadata.description, bookmark.website_description)
|
||||
self.assertEqual(
|
||||
expected_metadata.description, bookmark.website_description
|
||||
)
|
||||
|
||||
def test_update_should_not_update_website_metadata_if_url_did_not_change(self):
|
||||
with patch.object(website_loader, 'load_website_metadata') as mock_load_website_metadata:
|
||||
with patch.object(
|
||||
website_loader, "load_website_metadata"
|
||||
) as mock_load_website_metadata:
|
||||
bookmark = self.setup_bookmark()
|
||||
bookmark.title = 'updated title'
|
||||
update_bookmark(bookmark, 'tag1,tag2', self.user)
|
||||
bookmark.title = "updated title"
|
||||
update_bookmark(bookmark, "tag1,tag2", self.user)
|
||||
|
||||
mock_load_website_metadata.assert_not_called()
|
||||
|
||||
def test_update_should_update_favicon(self):
|
||||
with patch.object(tasks, 'load_favicon') as mock_load_favicon:
|
||||
with patch.object(tasks, "load_favicon") as mock_load_favicon:
|
||||
bookmark = self.setup_bookmark()
|
||||
bookmark.title = 'updated title'
|
||||
update_bookmark(bookmark, 'tag1,tag2', self.user)
|
||||
bookmark.title = "updated title"
|
||||
update_bookmark(bookmark, "tag1,tag2", self.user)
|
||||
|
||||
mock_load_favicon.assert_called_once_with(self.user, bookmark)
|
||||
|
||||
def test_archive_bookmark(self):
|
||||
bookmark = Bookmark(
|
||||
url='https://example.com',
|
||||
url="https://example.com",
|
||||
date_added=timezone.now(),
|
||||
date_modified=timezone.now(),
|
||||
owner=self.user
|
||||
owner=self.user,
|
||||
)
|
||||
bookmark.save()
|
||||
|
||||
@@ -146,7 +186,7 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
|
||||
def test_unarchive_bookmark(self):
|
||||
bookmark = Bookmark(
|
||||
url='https://example.com',
|
||||
url="https://example.com",
|
||||
date_added=timezone.now(),
|
||||
date_modified=timezone.now(),
|
||||
owner=self.user,
|
||||
@@ -165,7 +205,9 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
bookmark2 = self.setup_bookmark()
|
||||
bookmark3 = self.setup_bookmark()
|
||||
|
||||
archive_bookmarks([bookmark1.id, bookmark2.id, bookmark3.id], self.get_or_create_test_user())
|
||||
archive_bookmarks(
|
||||
[bookmark1.id, bookmark2.id, bookmark3.id], self.get_or_create_test_user()
|
||||
)
|
||||
|
||||
self.assertTrue(Bookmark.objects.get(id=bookmark1.id).is_archived)
|
||||
self.assertTrue(Bookmark.objects.get(id=bookmark2.id).is_archived)
|
||||
@@ -183,12 +225,17 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
self.assertTrue(Bookmark.objects.get(id=bookmark3.id).is_archived)
|
||||
|
||||
def test_archive_bookmarks_should_only_archive_user_owned_bookmarks(self):
|
||||
other_user = User.objects.create_user('otheruser', 'otheruser@example.com', 'password123')
|
||||
other_user = User.objects.create_user(
|
||||
"otheruser", "otheruser@example.com", "password123"
|
||||
)
|
||||
bookmark1 = self.setup_bookmark()
|
||||
bookmark2 = self.setup_bookmark()
|
||||
inaccessible_bookmark = self.setup_bookmark(user=other_user)
|
||||
|
||||
archive_bookmarks([bookmark1.id, bookmark2.id, inaccessible_bookmark.id], self.get_or_create_test_user())
|
||||
archive_bookmarks(
|
||||
[bookmark1.id, bookmark2.id, inaccessible_bookmark.id],
|
||||
self.get_or_create_test_user(),
|
||||
)
|
||||
|
||||
self.assertTrue(Bookmark.objects.get(id=bookmark1.id).is_archived)
|
||||
self.assertTrue(Bookmark.objects.get(id=bookmark2.id).is_archived)
|
||||
@@ -199,7 +246,10 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
bookmark2 = self.setup_bookmark()
|
||||
bookmark3 = self.setup_bookmark()
|
||||
|
||||
archive_bookmarks([str(bookmark1.id), bookmark2.id, str(bookmark3.id)], self.get_or_create_test_user())
|
||||
archive_bookmarks(
|
||||
[str(bookmark1.id), bookmark2.id, str(bookmark3.id)],
|
||||
self.get_or_create_test_user(),
|
||||
)
|
||||
|
||||
self.assertTrue(Bookmark.objects.get(id=bookmark1.id).is_archived)
|
||||
self.assertTrue(Bookmark.objects.get(id=bookmark2.id).is_archived)
|
||||
@@ -210,7 +260,9 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
bookmark2 = self.setup_bookmark(is_archived=True)
|
||||
bookmark3 = self.setup_bookmark(is_archived=True)
|
||||
|
||||
unarchive_bookmarks([bookmark1.id, bookmark2.id, bookmark3.id], self.get_or_create_test_user())
|
||||
unarchive_bookmarks(
|
||||
[bookmark1.id, bookmark2.id, bookmark3.id], self.get_or_create_test_user()
|
||||
)
|
||||
|
||||
self.assertFalse(Bookmark.objects.get(id=bookmark1.id).is_archived)
|
||||
self.assertFalse(Bookmark.objects.get(id=bookmark2.id).is_archived)
|
||||
@@ -221,19 +273,26 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
bookmark2 = self.setup_bookmark(is_archived=True)
|
||||
bookmark3 = self.setup_bookmark(is_archived=True)
|
||||
|
||||
unarchive_bookmarks([bookmark1.id, bookmark3.id], self.get_or_create_test_user())
|
||||
unarchive_bookmarks(
|
||||
[bookmark1.id, bookmark3.id], self.get_or_create_test_user()
|
||||
)
|
||||
|
||||
self.assertFalse(Bookmark.objects.get(id=bookmark1.id).is_archived)
|
||||
self.assertTrue(Bookmark.objects.get(id=bookmark2.id).is_archived)
|
||||
self.assertFalse(Bookmark.objects.get(id=bookmark3.id).is_archived)
|
||||
|
||||
def test_unarchive_bookmarks_should_only_unarchive_user_owned_bookmarks(self):
|
||||
other_user = User.objects.create_user('otheruser', 'otheruser@example.com', 'password123')
|
||||
other_user = User.objects.create_user(
|
||||
"otheruser", "otheruser@example.com", "password123"
|
||||
)
|
||||
bookmark1 = self.setup_bookmark(is_archived=True)
|
||||
bookmark2 = self.setup_bookmark(is_archived=True)
|
||||
inaccessible_bookmark = self.setup_bookmark(is_archived=True, user=other_user)
|
||||
|
||||
unarchive_bookmarks([bookmark1.id, bookmark2.id, inaccessible_bookmark.id], self.get_or_create_test_user())
|
||||
unarchive_bookmarks(
|
||||
[bookmark1.id, bookmark2.id, inaccessible_bookmark.id],
|
||||
self.get_or_create_test_user(),
|
||||
)
|
||||
|
||||
self.assertFalse(Bookmark.objects.get(id=bookmark1.id).is_archived)
|
||||
self.assertFalse(Bookmark.objects.get(id=bookmark2.id).is_archived)
|
||||
@@ -244,7 +303,10 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
bookmark2 = self.setup_bookmark(is_archived=True)
|
||||
bookmark3 = self.setup_bookmark(is_archived=True)
|
||||
|
||||
unarchive_bookmarks([str(bookmark1.id), bookmark2.id, str(bookmark3.id)], self.get_or_create_test_user())
|
||||
unarchive_bookmarks(
|
||||
[str(bookmark1.id), bookmark2.id, str(bookmark3.id)],
|
||||
self.get_or_create_test_user(),
|
||||
)
|
||||
|
||||
self.assertFalse(Bookmark.objects.get(id=bookmark1.id).is_archived)
|
||||
self.assertFalse(Bookmark.objects.get(id=bookmark2.id).is_archived)
|
||||
@@ -255,7 +317,9 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
bookmark2 = self.setup_bookmark()
|
||||
bookmark3 = self.setup_bookmark()
|
||||
|
||||
delete_bookmarks([bookmark1.id, bookmark2.id, bookmark3.id], self.get_or_create_test_user())
|
||||
delete_bookmarks(
|
||||
[bookmark1.id, bookmark2.id, bookmark3.id], self.get_or_create_test_user()
|
||||
)
|
||||
|
||||
self.assertIsNone(Bookmark.objects.filter(id=bookmark1.id).first())
|
||||
self.assertIsNone(Bookmark.objects.filter(id=bookmark2.id).first())
|
||||
@@ -273,23 +337,32 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
self.assertIsNone(Bookmark.objects.filter(id=bookmark3.id).first())
|
||||
|
||||
def test_delete_bookmarks_should_only_delete_user_owned_bookmarks(self):
|
||||
other_user = User.objects.create_user('otheruser', 'otheruser@example.com', 'password123')
|
||||
other_user = User.objects.create_user(
|
||||
"otheruser", "otheruser@example.com", "password123"
|
||||
)
|
||||
bookmark1 = self.setup_bookmark()
|
||||
bookmark2 = self.setup_bookmark()
|
||||
inaccessible_bookmark = self.setup_bookmark(user=other_user)
|
||||
|
||||
delete_bookmarks([bookmark1.id, bookmark2.id, inaccessible_bookmark.id], self.get_or_create_test_user())
|
||||
delete_bookmarks(
|
||||
[bookmark1.id, bookmark2.id, inaccessible_bookmark.id],
|
||||
self.get_or_create_test_user(),
|
||||
)
|
||||
|
||||
self.assertIsNone(Bookmark.objects.filter(id=bookmark1.id).first())
|
||||
self.assertIsNone(Bookmark.objects.filter(id=bookmark2.id).first())
|
||||
self.assertIsNotNone(Bookmark.objects.filter(id=inaccessible_bookmark.id).first())
|
||||
self.assertIsNotNone(
|
||||
Bookmark.objects.filter(id=inaccessible_bookmark.id).first()
|
||||
)
|
||||
|
||||
def test_delete_bookmarks_should_accept_mix_of_int_and_string_ids(self):
|
||||
bookmark1 = self.setup_bookmark()
|
||||
bookmark2 = self.setup_bookmark()
|
||||
bookmark3 = self.setup_bookmark()
|
||||
|
||||
delete_bookmarks([bookmark1.id, bookmark2.id, bookmark3.id], self.get_or_create_test_user())
|
||||
delete_bookmarks(
|
||||
[bookmark1.id, bookmark2.id, bookmark3.id], self.get_or_create_test_user()
|
||||
)
|
||||
|
||||
self.assertIsNone(Bookmark.objects.filter(id=bookmark1.id).first())
|
||||
self.assertIsNone(Bookmark.objects.filter(id=bookmark2.id).first())
|
||||
@@ -302,8 +375,11 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
tag1 = self.setup_tag()
|
||||
tag2 = self.setup_tag()
|
||||
|
||||
tag_bookmarks([bookmark1.id, bookmark2.id, bookmark3.id], f'{tag1.name},{tag2.name}',
|
||||
self.get_or_create_test_user())
|
||||
tag_bookmarks(
|
||||
[bookmark1.id, bookmark2.id, bookmark3.id],
|
||||
f"{tag1.name},{tag2.name}",
|
||||
self.get_or_create_test_user(),
|
||||
)
|
||||
|
||||
bookmark1.refresh_from_db()
|
||||
bookmark2.refresh_from_db()
|
||||
@@ -318,7 +394,11 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
bookmark2 = self.setup_bookmark()
|
||||
bookmark3 = self.setup_bookmark()
|
||||
|
||||
tag_bookmarks([bookmark1.id, bookmark2.id, bookmark3.id], 'tag1,tag2', self.get_or_create_test_user())
|
||||
tag_bookmarks(
|
||||
[bookmark1.id, bookmark2.id, bookmark3.id],
|
||||
"tag1,tag2",
|
||||
self.get_or_create_test_user(),
|
||||
)
|
||||
|
||||
bookmark1.refresh_from_db()
|
||||
bookmark2.refresh_from_db()
|
||||
@@ -326,8 +406,8 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
|
||||
self.assertEqual(2, Tag.objects.count())
|
||||
|
||||
tag1 = Tag.objects.filter(name='tag1').first()
|
||||
tag2 = Tag.objects.filter(name='tag2').first()
|
||||
tag1 = Tag.objects.filter(name="tag1").first()
|
||||
tag2 = Tag.objects.filter(name="tag2").first()
|
||||
|
||||
self.assertIsNotNone(tag1)
|
||||
self.assertIsNotNone(tag2)
|
||||
@@ -346,8 +426,11 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
BookmarkToTagRelationShip = Bookmark.tags.through
|
||||
self.assertEqual(3, BookmarkToTagRelationShip.objects.count())
|
||||
|
||||
tag_bookmarks([bookmark1.id, bookmark2.id, bookmark3.id], f'{tag1.name},{tag2.name}',
|
||||
self.get_or_create_test_user())
|
||||
tag_bookmarks(
|
||||
[bookmark1.id, bookmark2.id, bookmark3.id],
|
||||
f"{tag1.name},{tag2.name}",
|
||||
self.get_or_create_test_user(),
|
||||
)
|
||||
|
||||
bookmark1.refresh_from_db()
|
||||
bookmark2.refresh_from_db()
|
||||
@@ -365,7 +448,11 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
tag1 = self.setup_tag()
|
||||
tag2 = self.setup_tag()
|
||||
|
||||
tag_bookmarks([bookmark1.id, bookmark3.id], f'{tag1.name},{tag2.name}', self.get_or_create_test_user())
|
||||
tag_bookmarks(
|
||||
[bookmark1.id, bookmark3.id],
|
||||
f"{tag1.name},{tag2.name}",
|
||||
self.get_or_create_test_user(),
|
||||
)
|
||||
|
||||
bookmark1.refresh_from_db()
|
||||
bookmark2.refresh_from_db()
|
||||
@@ -376,15 +463,20 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
self.assertCountEqual(bookmark3.tags.all(), [tag1, tag2])
|
||||
|
||||
def test_tag_bookmarks_should_only_tag_user_owned_bookmarks(self):
|
||||
other_user = User.objects.create_user('otheruser', 'otheruser@example.com', 'password123')
|
||||
other_user = User.objects.create_user(
|
||||
"otheruser", "otheruser@example.com", "password123"
|
||||
)
|
||||
bookmark1 = self.setup_bookmark()
|
||||
bookmark2 = self.setup_bookmark()
|
||||
inaccessible_bookmark = self.setup_bookmark(user=other_user)
|
||||
tag1 = self.setup_tag()
|
||||
tag2 = self.setup_tag()
|
||||
|
||||
tag_bookmarks([bookmark1.id, bookmark2.id, inaccessible_bookmark.id], f'{tag1.name},{tag2.name}',
|
||||
self.get_or_create_test_user())
|
||||
tag_bookmarks(
|
||||
[bookmark1.id, bookmark2.id, inaccessible_bookmark.id],
|
||||
f"{tag1.name},{tag2.name}",
|
||||
self.get_or_create_test_user(),
|
||||
)
|
||||
|
||||
bookmark1.refresh_from_db()
|
||||
bookmark2.refresh_from_db()
|
||||
@@ -401,8 +493,11 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
tag1 = self.setup_tag()
|
||||
tag2 = self.setup_tag()
|
||||
|
||||
tag_bookmarks([str(bookmark1.id), bookmark2.id, str(bookmark3.id)], f'{tag1.name},{tag2.name}',
|
||||
self.get_or_create_test_user())
|
||||
tag_bookmarks(
|
||||
[str(bookmark1.id), bookmark2.id, str(bookmark3.id)],
|
||||
f"{tag1.name},{tag2.name}",
|
||||
self.get_or_create_test_user(),
|
||||
)
|
||||
|
||||
self.assertCountEqual(bookmark1.tags.all(), [tag1, tag2])
|
||||
self.assertCountEqual(bookmark2.tags.all(), [tag1, tag2])
|
||||
@@ -415,8 +510,11 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
bookmark2 = self.setup_bookmark(tags=[tag1, tag2])
|
||||
bookmark3 = self.setup_bookmark(tags=[tag1, tag2])
|
||||
|
||||
untag_bookmarks([bookmark1.id, bookmark2.id, bookmark3.id], f'{tag1.name},{tag2.name}',
|
||||
self.get_or_create_test_user())
|
||||
untag_bookmarks(
|
||||
[bookmark1.id, bookmark2.id, bookmark3.id],
|
||||
f"{tag1.name},{tag2.name}",
|
||||
self.get_or_create_test_user(),
|
||||
)
|
||||
|
||||
bookmark1.refresh_from_db()
|
||||
bookmark2.refresh_from_db()
|
||||
@@ -433,7 +531,11 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
bookmark2 = self.setup_bookmark(tags=[tag1, tag2])
|
||||
bookmark3 = self.setup_bookmark(tags=[tag1, tag2])
|
||||
|
||||
untag_bookmarks([bookmark1.id, bookmark3.id], f'{tag1.name},{tag2.name}', self.get_or_create_test_user())
|
||||
untag_bookmarks(
|
||||
[bookmark1.id, bookmark3.id],
|
||||
f"{tag1.name},{tag2.name}",
|
||||
self.get_or_create_test_user(),
|
||||
)
|
||||
|
||||
bookmark1.refresh_from_db()
|
||||
bookmark2.refresh_from_db()
|
||||
@@ -444,15 +546,20 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
self.assertCountEqual(bookmark3.tags.all(), [])
|
||||
|
||||
def test_untag_bookmarks_should_only_tag_user_owned_bookmarks(self):
|
||||
other_user = User.objects.create_user('otheruser', 'otheruser@example.com', 'password123')
|
||||
other_user = User.objects.create_user(
|
||||
"otheruser", "otheruser@example.com", "password123"
|
||||
)
|
||||
tag1 = self.setup_tag()
|
||||
tag2 = self.setup_tag()
|
||||
bookmark1 = self.setup_bookmark(tags=[tag1, tag2])
|
||||
bookmark2 = self.setup_bookmark(tags=[tag1, tag2])
|
||||
inaccessible_bookmark = self.setup_bookmark(user=other_user, tags=[tag1, tag2])
|
||||
|
||||
untag_bookmarks([bookmark1.id, bookmark2.id, inaccessible_bookmark.id], f'{tag1.name},{tag2.name}',
|
||||
self.get_or_create_test_user())
|
||||
untag_bookmarks(
|
||||
[bookmark1.id, bookmark2.id, inaccessible_bookmark.id],
|
||||
f"{tag1.name},{tag2.name}",
|
||||
self.get_or_create_test_user(),
|
||||
)
|
||||
|
||||
bookmark1.refresh_from_db()
|
||||
bookmark2.refresh_from_db()
|
||||
@@ -469,8 +576,11 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
bookmark2 = self.setup_bookmark(tags=[tag1, tag2])
|
||||
bookmark3 = self.setup_bookmark(tags=[tag1, tag2])
|
||||
|
||||
untag_bookmarks([str(bookmark1.id), bookmark2.id, str(bookmark3.id)], f'{tag1.name},{tag2.name}',
|
||||
self.get_or_create_test_user())
|
||||
untag_bookmarks(
|
||||
[str(bookmark1.id), bookmark2.id, str(bookmark3.id)],
|
||||
f"{tag1.name},{tag2.name}",
|
||||
self.get_or_create_test_user(),
|
||||
)
|
||||
|
||||
self.assertCountEqual(bookmark1.tags.all(), [])
|
||||
self.assertCountEqual(bookmark2.tags.all(), [])
|
||||
@@ -481,7 +591,9 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
bookmark2 = self.setup_bookmark(unread=True)
|
||||
bookmark3 = self.setup_bookmark(unread=True)
|
||||
|
||||
mark_bookmarks_as_read([bookmark1.id, bookmark2.id, bookmark3.id], self.get_or_create_test_user())
|
||||
mark_bookmarks_as_read(
|
||||
[bookmark1.id, bookmark2.id, bookmark3.id], self.get_or_create_test_user()
|
||||
)
|
||||
|
||||
self.assertFalse(Bookmark.objects.get(id=bookmark1.id).unread)
|
||||
self.assertFalse(Bookmark.objects.get(id=bookmark2.id).unread)
|
||||
@@ -492,19 +604,26 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
bookmark2 = self.setup_bookmark(unread=True)
|
||||
bookmark3 = self.setup_bookmark(unread=True)
|
||||
|
||||
mark_bookmarks_as_read([bookmark1.id, bookmark3.id], self.get_or_create_test_user())
|
||||
mark_bookmarks_as_read(
|
||||
[bookmark1.id, bookmark3.id], self.get_or_create_test_user()
|
||||
)
|
||||
|
||||
self.assertFalse(Bookmark.objects.get(id=bookmark1.id).unread)
|
||||
self.assertTrue(Bookmark.objects.get(id=bookmark2.id).unread)
|
||||
self.assertFalse(Bookmark.objects.get(id=bookmark3.id).unread)
|
||||
|
||||
def test_mark_bookmarks_as_read_should_only_update_user_owned_bookmarks(self):
|
||||
other_user = User.objects.create_user('otheruser', 'otheruser@example.com', 'password123')
|
||||
other_user = User.objects.create_user(
|
||||
"otheruser", "otheruser@example.com", "password123"
|
||||
)
|
||||
bookmark1 = self.setup_bookmark(unread=True)
|
||||
bookmark2 = self.setup_bookmark(unread=True)
|
||||
inaccessible_bookmark = self.setup_bookmark(unread=True, user=other_user)
|
||||
|
||||
mark_bookmarks_as_read([bookmark1.id, bookmark2.id, inaccessible_bookmark.id], self.get_or_create_test_user())
|
||||
mark_bookmarks_as_read(
|
||||
[bookmark1.id, bookmark2.id, inaccessible_bookmark.id],
|
||||
self.get_or_create_test_user(),
|
||||
)
|
||||
|
||||
self.assertFalse(Bookmark.objects.get(id=bookmark1.id).unread)
|
||||
self.assertFalse(Bookmark.objects.get(id=bookmark2.id).unread)
|
||||
@@ -515,7 +634,10 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
bookmark2 = self.setup_bookmark(unread=True)
|
||||
bookmark3 = self.setup_bookmark(unread=True)
|
||||
|
||||
mark_bookmarks_as_read([str(bookmark1.id), bookmark2.id, str(bookmark3.id)], self.get_or_create_test_user())
|
||||
mark_bookmarks_as_read(
|
||||
[str(bookmark1.id), bookmark2.id, str(bookmark3.id)],
|
||||
self.get_or_create_test_user(),
|
||||
)
|
||||
|
||||
self.assertFalse(Bookmark.objects.get(id=bookmark1.id).unread)
|
||||
self.assertFalse(Bookmark.objects.get(id=bookmark2.id).unread)
|
||||
@@ -526,7 +648,9 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
bookmark2 = self.setup_bookmark(unread=False)
|
||||
bookmark3 = self.setup_bookmark(unread=False)
|
||||
|
||||
mark_bookmarks_as_unread([bookmark1.id, bookmark2.id, bookmark3.id], self.get_or_create_test_user())
|
||||
mark_bookmarks_as_unread(
|
||||
[bookmark1.id, bookmark2.id, bookmark3.id], self.get_or_create_test_user()
|
||||
)
|
||||
|
||||
self.assertTrue(Bookmark.objects.get(id=bookmark1.id).unread)
|
||||
self.assertTrue(Bookmark.objects.get(id=bookmark2.id).unread)
|
||||
@@ -537,19 +661,26 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
bookmark2 = self.setup_bookmark(unread=False)
|
||||
bookmark3 = self.setup_bookmark(unread=False)
|
||||
|
||||
mark_bookmarks_as_unread([bookmark1.id, bookmark3.id], self.get_or_create_test_user())
|
||||
mark_bookmarks_as_unread(
|
||||
[bookmark1.id, bookmark3.id], self.get_or_create_test_user()
|
||||
)
|
||||
|
||||
self.assertTrue(Bookmark.objects.get(id=bookmark1.id).unread)
|
||||
self.assertFalse(Bookmark.objects.get(id=bookmark2.id).unread)
|
||||
self.assertTrue(Bookmark.objects.get(id=bookmark3.id).unread)
|
||||
|
||||
def test_mark_bookmarks_as_unread_should_only_update_user_owned_bookmarks(self):
|
||||
other_user = User.objects.create_user('otheruser', 'otheruser@example.com', 'password123')
|
||||
other_user = User.objects.create_user(
|
||||
"otheruser", "otheruser@example.com", "password123"
|
||||
)
|
||||
bookmark1 = self.setup_bookmark(unread=False)
|
||||
bookmark2 = self.setup_bookmark(unread=False)
|
||||
inaccessible_bookmark = self.setup_bookmark(unread=False, user=other_user)
|
||||
|
||||
mark_bookmarks_as_unread([bookmark1.id, bookmark2.id, inaccessible_bookmark.id], self.get_or_create_test_user())
|
||||
mark_bookmarks_as_unread(
|
||||
[bookmark1.id, bookmark2.id, inaccessible_bookmark.id],
|
||||
self.get_or_create_test_user(),
|
||||
)
|
||||
|
||||
self.assertTrue(Bookmark.objects.get(id=bookmark1.id).unread)
|
||||
self.assertTrue(Bookmark.objects.get(id=bookmark2.id).unread)
|
||||
@@ -560,7 +691,10 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
bookmark2 = self.setup_bookmark(unread=False)
|
||||
bookmark3 = self.setup_bookmark(unread=False)
|
||||
|
||||
mark_bookmarks_as_unread([str(bookmark1.id), bookmark2.id, str(bookmark3.id)], self.get_or_create_test_user())
|
||||
mark_bookmarks_as_unread(
|
||||
[str(bookmark1.id), bookmark2.id, str(bookmark3.id)],
|
||||
self.get_or_create_test_user(),
|
||||
)
|
||||
|
||||
self.assertTrue(Bookmark.objects.get(id=bookmark1.id).unread)
|
||||
self.assertTrue(Bookmark.objects.get(id=bookmark2.id).unread)
|
||||
@@ -571,7 +705,9 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
bookmark2 = self.setup_bookmark(shared=False)
|
||||
bookmark3 = self.setup_bookmark(shared=False)
|
||||
|
||||
share_bookmarks([bookmark1.id, bookmark2.id, bookmark3.id], self.get_or_create_test_user())
|
||||
share_bookmarks(
|
||||
[bookmark1.id, bookmark2.id, bookmark3.id], self.get_or_create_test_user()
|
||||
)
|
||||
|
||||
self.assertTrue(Bookmark.objects.get(id=bookmark1.id).shared)
|
||||
self.assertTrue(Bookmark.objects.get(id=bookmark2.id).shared)
|
||||
@@ -589,12 +725,17 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
self.assertTrue(Bookmark.objects.get(id=bookmark3.id).shared)
|
||||
|
||||
def test_share_bookmarks_should_only_update_user_owned_bookmarks(self):
|
||||
other_user = User.objects.create_user('otheruser', 'otheruser@example.com', 'password123')
|
||||
other_user = User.objects.create_user(
|
||||
"otheruser", "otheruser@example.com", "password123"
|
||||
)
|
||||
bookmark1 = self.setup_bookmark(shared=False)
|
||||
bookmark2 = self.setup_bookmark(shared=False)
|
||||
inaccessible_bookmark = self.setup_bookmark(shared=False, user=other_user)
|
||||
|
||||
share_bookmarks([bookmark1.id, bookmark2.id, inaccessible_bookmark.id], self.get_or_create_test_user())
|
||||
share_bookmarks(
|
||||
[bookmark1.id, bookmark2.id, inaccessible_bookmark.id],
|
||||
self.get_or_create_test_user(),
|
||||
)
|
||||
|
||||
self.assertTrue(Bookmark.objects.get(id=bookmark1.id).shared)
|
||||
self.assertTrue(Bookmark.objects.get(id=bookmark2.id).shared)
|
||||
@@ -605,7 +746,10 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
bookmark2 = self.setup_bookmark(shared=False)
|
||||
bookmark3 = self.setup_bookmark(shared=False)
|
||||
|
||||
share_bookmarks([str(bookmark1.id), bookmark2.id, str(bookmark3.id)], self.get_or_create_test_user())
|
||||
share_bookmarks(
|
||||
[str(bookmark1.id), bookmark2.id, str(bookmark3.id)],
|
||||
self.get_or_create_test_user(),
|
||||
)
|
||||
|
||||
self.assertTrue(Bookmark.objects.get(id=bookmark1.id).shared)
|
||||
self.assertTrue(Bookmark.objects.get(id=bookmark2.id).shared)
|
||||
@@ -616,7 +760,9 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
bookmark2 = self.setup_bookmark(shared=True)
|
||||
bookmark3 = self.setup_bookmark(shared=True)
|
||||
|
||||
unshare_bookmarks([bookmark1.id, bookmark2.id, bookmark3.id], self.get_or_create_test_user())
|
||||
unshare_bookmarks(
|
||||
[bookmark1.id, bookmark2.id, bookmark3.id], self.get_or_create_test_user()
|
||||
)
|
||||
|
||||
self.assertFalse(Bookmark.objects.get(id=bookmark1.id).shared)
|
||||
self.assertFalse(Bookmark.objects.get(id=bookmark2.id).shared)
|
||||
@@ -634,12 +780,17 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
self.assertFalse(Bookmark.objects.get(id=bookmark3.id).shared)
|
||||
|
||||
def test_unshare_bookmarks_should_only_update_user_owned_bookmarks(self):
|
||||
other_user = User.objects.create_user('otheruser', 'otheruser@example.com', 'password123')
|
||||
other_user = User.objects.create_user(
|
||||
"otheruser", "otheruser@example.com", "password123"
|
||||
)
|
||||
bookmark1 = self.setup_bookmark(shared=True)
|
||||
bookmark2 = self.setup_bookmark(shared=True)
|
||||
inaccessible_bookmark = self.setup_bookmark(shared=True, user=other_user)
|
||||
|
||||
unshare_bookmarks([bookmark1.id, bookmark2.id, inaccessible_bookmark.id], self.get_or_create_test_user())
|
||||
unshare_bookmarks(
|
||||
[bookmark1.id, bookmark2.id, inaccessible_bookmark.id],
|
||||
self.get_or_create_test_user(),
|
||||
)
|
||||
|
||||
self.assertFalse(Bookmark.objects.get(id=bookmark1.id).shared)
|
||||
self.assertFalse(Bookmark.objects.get(id=bookmark2.id).shared)
|
||||
@@ -650,7 +801,10 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
|
||||
bookmark2 = self.setup_bookmark(shared=True)
|
||||
bookmark3 = self.setup_bookmark(shared=True)
|
||||
|
||||
unshare_bookmarks([str(bookmark1.id), bookmark2.id, str(bookmark3.id)], self.get_or_create_test_user())
|
||||
unshare_bookmarks(
|
||||
[str(bookmark1.id), bookmark2.id, str(bookmark3.id)],
|
||||
self.get_or_create_test_user(),
|
||||
)
|
||||
|
||||
self.assertFalse(Bookmark.objects.get(id=bookmark1.id).shared)
|
||||
self.assertFalse(Bookmark.objects.get(id=bookmark2.id).shared)
|
||||
|
Reference in New Issue
Block a user