Skip updating website metadata on edit unless URL has changed (#318)

* Skip updating website metadata on edit unless URL has changed

* Prevent form fetching metadata when editing existing bookmark
This commit is contained in:
Sascha Ißbrücker
2022-08-13 11:21:26 +02:00
committed by GitHub
parent ee7ac775d2
commit 1b67081773
5 changed files with 83 additions and 26 deletions

View File

@@ -7,6 +7,7 @@ from django.utils import timezone
from bookmarks.models import Bookmark, Tag
from bookmarks.services.bookmarks import create_bookmark, update_bookmark, archive_bookmark, archive_bookmarks, \
unarchive_bookmark, unarchive_bookmarks, delete_bookmarks, tag_bookmarks, untag_bookmarks
from bookmarks.services import website_loader
from bookmarks.tests.helpers import BookmarkFactoryMixin
from bookmarks.services import tasks
@@ -60,6 +61,22 @@ class BookmarkServiceTestCase(TestCase, BookmarkFactoryMixin):
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:
bookmark = self.setup_bookmark()
bookmark.url = 'https://example.com/updated'
update_bookmark(bookmark, 'tag1,tag2', self.user)
mock_load_website_metadata.assert_called_once()
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:
bookmark = self.setup_bookmark()
bookmark.title = 'updated title'
update_bookmark(bookmark, 'tag1,tag2', self.user)
mock_load_website_metadata.assert_not_called()
def test_archive_bookmark(self):
bookmark = Bookmark(
url='https://example.com',