From 0829d00e5fdd04f202c7f414b23f7ecb5f550e53 Mon Sep 17 00:00:00 2001 From: wahlm Date: Sun, 3 Jul 2022 05:34:40 +0200 Subject: [PATCH] no duplication of imported tags (#289) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * no duplication of imported tags (#287) * Add importer test * Revert settings test Co-authored-by: Sascha Ißbrücker --- bookmarks/services/importer.py | 1 + bookmarks/tests/test_importer.py | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/bookmarks/services/importer.py b/bookmarks/services/importer.py index 0b83a30..2259ef8 100644 --- a/bookmarks/services/importer.py +++ b/bookmarks/services/importer.py @@ -93,6 +93,7 @@ def _create_missing_tags(netscape_bookmarks: List[NetscapeBookmark], user: User) tag = Tag(name=tag_name, owner=user) tag.date_added = timezone.now() tags_to_create.append(tag) + tag_cache.put(tag) Tag.objects.bulk_create(tags_to_create) diff --git a/bookmarks/tests/test_importer.py b/bookmarks/tests/test_importer.py index ded0ea9..d814d1f 100644 --- a/bookmarks/tests/test_importer.py +++ b/bookmarks/tests/test_importer.py @@ -139,6 +139,17 @@ class ImporterTestCase(TestCase, BookmarkFactoryMixin, ImportTestMixin): self.assertEqual(Tag.objects.count(), 4) + def test_create_missing_tags_does_not_duplicate_tags(self): + html_tags = [ + BookmarkHtmlTag(href='https://example.com', tags='tag1'), + BookmarkHtmlTag(href='https://foo.com', tags='tag1'), + BookmarkHtmlTag(href='https://bar.com', tags='tag1'), + ] + import_html = self.render_html(tags=html_tags) + import_netscape_html(import_html, self.get_or_create_test_user()) + + self.assertEqual(Tag.objects.count(), 1) + def test_should_append_tags_to_bookmark_when_reimporting_with_different_tags(self): html_tags = [ BookmarkHtmlTag(href='https://example.com', tags='tag1'),