mirror of
https://github.com/sissbruecker/linkding.git
synced 2025-08-07 10:58:25 +02:00
Do not associate tags if bookmark was not imported
This commit is contained in:
@@ -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)
|
||||||
|
@@ -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'),
|
||||||
|
Reference in New Issue
Block a user