mirror of
https://github.com/sissbruecker/linkding.git
synced 2025-11-19 12:34:16 +01:00
Fix missing tags causing errors in import with Postgres (#1203)
* Handle missing tags in importer * Make all tests run with Postgres again
This commit is contained in:
@@ -45,8 +45,9 @@ class TagCache:
|
|||||||
result = []
|
result = []
|
||||||
for tag_name in tag_names:
|
for tag_name in tag_names:
|
||||||
tag = self.get(tag_name)
|
tag = self.get(tag_name)
|
||||||
|
# Tag may not have been created if tag name exceeded maximum length
|
||||||
# Prevent returning duplicates
|
# Prevent returning duplicates
|
||||||
if not (tag in result):
|
if tag and not (tag in result):
|
||||||
result.append(tag)
|
result.append(tag)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import email
|
import email
|
||||||
|
import unittest
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from bookmarks.tests.helpers import BookmarkFactoryMixin
|
|
||||||
from bookmarks.models import FeedToken, User
|
|
||||||
from bookmarks.feeds import sanitize
|
from bookmarks.feeds import sanitize
|
||||||
|
from bookmarks.models import FeedToken, User
|
||||||
|
from bookmarks.tests.helpers import BookmarkFactoryMixin
|
||||||
|
|
||||||
|
|
||||||
def rfc2822_date(date):
|
def rfc2822_date(date):
|
||||||
@@ -343,6 +345,10 @@ class FeedsTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertContains(response, "<item>", count=5)
|
self.assertContains(response, "<item>", count=5)
|
||||||
|
|
||||||
|
@unittest.skipIf(
|
||||||
|
settings.LD_DB_ENGINE == "postgres",
|
||||||
|
"Postgres does not allow NUL in text columns",
|
||||||
|
)
|
||||||
def test_strip_control_characters(self):
|
def test_strip_control_characters(self):
|
||||||
self.setup_bookmark(
|
self.setup_bookmark(
|
||||||
title="test\n\r\t\0\x08title", description="test\n\r\t\0\x08description"
|
title="test\n\r\t\0\x08title", description="test\n\r\t\0\x08description"
|
||||||
|
|||||||
@@ -1199,7 +1199,11 @@ class QueriesBasicTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
sorted_bookmarks = sorted(bookmarks, key=lambda b: b.resolved_title.lower())
|
sorted_bookmarks = sorted(bookmarks, key=lambda b: b.resolved_title.lower())
|
||||||
|
|
||||||
query = queries.query_bookmarks(self.user, self.profile, search)
|
query = queries.query_bookmarks(self.user, self.profile, search)
|
||||||
self.assertEqual(list(query), sorted_bookmarks)
|
|
||||||
|
# Use resolved title for comparison as Postgres returns bookmarks with same resolved title in random order
|
||||||
|
expected_effective_titles = [b.resolved_title for b in sorted_bookmarks]
|
||||||
|
actual_effective_titles = [b.resolved_title for b in query]
|
||||||
|
self.assertEqual(expected_effective_titles, actual_effective_titles)
|
||||||
|
|
||||||
def test_sort_by_title_desc(self):
|
def test_sort_by_title_desc(self):
|
||||||
search = BookmarkSearch(sort=BookmarkSearch.SORT_TITLE_DESC)
|
search = BookmarkSearch(sort=BookmarkSearch.SORT_TITLE_DESC)
|
||||||
@@ -1210,7 +1214,11 @@ class QueriesBasicTestCase(TestCase, BookmarkFactoryMixin):
|
|||||||
)
|
)
|
||||||
|
|
||||||
query = queries.query_bookmarks(self.user, self.profile, search)
|
query = queries.query_bookmarks(self.user, self.profile, search)
|
||||||
self.assertEqual(list(query), sorted_bookmarks)
|
|
||||||
|
# Use resolved title for comparison as Postgres returns bookmarks with same resolved title in random order
|
||||||
|
expected_effective_titles = [b.resolved_title for b in sorted_bookmarks]
|
||||||
|
actual_effective_titles = [b.resolved_title for b in query]
|
||||||
|
self.assertEqual(expected_effective_titles, actual_effective_titles)
|
||||||
|
|
||||||
def test_query_bookmarks_filter_modified_since(self):
|
def test_query_bookmarks_filter_modified_since(self):
|
||||||
# Create bookmarks with different modification dates
|
# Create bookmarks with different modification dates
|
||||||
|
|||||||
Reference in New Issue
Block a user