Do not associate tags if bookmark was not imported

This commit is contained in:
Sascha Ißbrücker
2022-07-03 14:44:16 +02:00
parent 90a46c1fb9
commit b618a8b10b
2 changed files with 14 additions and 0 deletions

View File

@@ -173,6 +173,7 @@ def _import_batch(netscape_bookmarks: List[NetscapeBookmark], user: User, tag_ca
shortened_bookmark_tag_str = str(netscape_bookmark)[:100] + '...' shortened_bookmark_tag_str = str(netscape_bookmark)[:100] + '...'
logging.warning( logging.warning(
f'Failed to assign tags to the bookmark: {shortened_bookmark_tag_str}. Could not find bookmark by URL.') f'Failed to assign tags to the bookmark: {shortened_bookmark_tag_str}. Could not find bookmark by URL.')
continue
# Get tag models by string, schedule inserts for bookmark -> tag associations # Get tag models by string, schedule inserts for bookmark -> tag associations
tag_names = parse_tag_string(netscape_bookmark.tag_string) tag_names = parse_tag_string(netscape_bookmark.tag_string)

View File

@@ -111,6 +111,19 @@ class ImporterTestCase(TestCase, BookmarkFactoryMixin, ImportTestMixin):
self.assertEqual(len(bookmarks), 1) self.assertEqual(len(bookmarks), 1)
self.assertBookmarksImported(html_tags[1:1]) self.assertBookmarksImported(html_tags[1:1])
def test_import_invalid_bookmark_does_not_associate_tags(self):
html_tags = [
# No URL
BookmarkHtmlTag(tags='tag1, tag2, tag3'),
]
import_html = self.render_html(tags=html_tags)
# Sqlite silently ignores relationships that have a non-persisted bookmark,
# thus testing if the bulk create receives no relationships
BookmarkToTagRelationShip = Bookmark.tags.through
with patch.object(BookmarkToTagRelationShip.objects, 'bulk_create') as mock_bulk_create:
import_netscape_html(import_html, self.get_or_create_test_user())
mock_bulk_create.assert_called_once_with([], ignore_conflicts=True)
def test_import_tags(self): def test_import_tags(self):
html_tags = [ html_tags = [
BookmarkHtmlTag(href='https://example.com', tags='tag1'), BookmarkHtmlTag(href='https://example.com', tags='tag1'),