Improve index mounting value clean up code to remove the spaces at the starts and at the end of directories. Closes again GitLab issue #520 Thanks to TheOneValen @ for the report.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
3.1.6 (2018-10-XX)
|
||||
==================
|
||||
* Improve index mounting value clean up code to remove the spaces at the
|
||||
starts and at the end of directories. Closes again GitLab issue #520
|
||||
Thanks to TheOneValen @ for the report.
|
||||
|
||||
3.1.5 (2018-10-08)
|
||||
==================
|
||||
* Consolidate some document indexing test code into a new mixin.
|
||||
|
||||
@@ -9,7 +9,7 @@ from time import time
|
||||
from fuse import FuseOSError, Operations
|
||||
|
||||
from django.core.exceptions import MultipleObjectsReturned
|
||||
from django.db.models import Count, F, Func, Value
|
||||
from django.db.models import Count, F, Func, Transform, Value
|
||||
|
||||
from document_indexing.models import Index, IndexInstanceNode
|
||||
from documents.models import Document
|
||||
@@ -23,14 +23,22 @@ from .runtime import cache
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Trim(Transform):
|
||||
function = 'TRIM'
|
||||
lookup_name = 'trim'
|
||||
|
||||
|
||||
class IndexFilesystem(Operations):
|
||||
@staticmethod
|
||||
def _clean_queryset(queryset):
|
||||
# Remove newline carriage return to make multiline indexes
|
||||
# Remove newline carriage returns and the first and last space
|
||||
# to make multiline indexes
|
||||
# valid directoy names
|
||||
return queryset.annotate(
|
||||
clean_value=Func(
|
||||
F('value'), Value('\r\n'), Value(' '), function='replace'
|
||||
clean_value=Trim(
|
||||
Func(
|
||||
F('value'), Value('\r\n'), Value(' '), function='replace'
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -3,5 +3,8 @@ from __future__ import absolute_import, unicode_literals
|
||||
TEST_DOCUMENT_PK = 99
|
||||
TEST_NODE_EXPRESSION = 'level_1'
|
||||
TEST_NODE_EXPRESSION_MULTILINE = 'first\r\nsecond\r\nthird'
|
||||
TEST_NODE_EXPRESSION_MULTILINE_EXPECTED = 'first second third'
|
||||
TEST_NODE_EXPRESSION_MULTILINE_2 = '\r\n\r\nfirst\r\nsecond\r\nthird\r\n'
|
||||
TEST_NODE_EXPRESSION_MULTILINE_2_EXPECTED = 'first second third'
|
||||
TEST_NODE_PK = 88
|
||||
TEST_PATH = '/test/path'
|
||||
|
||||
@@ -14,7 +14,9 @@ from document_indexing.tests import DocumentIndexingTestMixin
|
||||
from ..filesystems import IndexFilesystem
|
||||
|
||||
from .literals import (
|
||||
TEST_NODE_EXPRESSION, TEST_NODE_EXPRESSION_MULTILINE
|
||||
TEST_NODE_EXPRESSION, TEST_NODE_EXPRESSION_MULTILINE,
|
||||
TEST_NODE_EXPRESSION_MULTILINE_EXPECTED, TEST_NODE_EXPRESSION_MULTILINE_2,
|
||||
TEST_NODE_EXPRESSION_MULTILINE_2_EXPECTED
|
||||
)
|
||||
|
||||
|
||||
@@ -93,7 +95,24 @@ class IndexFilesystemTestCase(DocumentIndexingTestMixin, DocumentTestMixin, Base
|
||||
|
||||
self.assertEqual(
|
||||
list(index_filesystem.readdir('/', ''))[2:],
|
||||
[TEST_NODE_EXPRESSION_MULTILINE.replace('\r\n', ' ')]
|
||||
[TEST_NODE_EXPRESSION_MULTILINE_EXPECTED]
|
||||
)
|
||||
|
||||
def test_multiline_indexes_first_and_last(self):
|
||||
self._create_index()
|
||||
|
||||
self.index.node_templates.create(
|
||||
parent=self.index.template_root,
|
||||
expression=TEST_NODE_EXPRESSION_MULTILINE_2,
|
||||
link_documents=True
|
||||
)
|
||||
|
||||
self.upload_document()
|
||||
index_filesystem = IndexFilesystem(index_slug=self.index.slug)
|
||||
|
||||
self.assertEqual(
|
||||
list(index_filesystem.readdir('/', ''))[2:],
|
||||
[TEST_NODE_EXPRESSION_MULTILINE_2_EXPECTED]
|
||||
)
|
||||
|
||||
def test_duplicated_indexes(self):
|
||||
|
||||
Reference in New Issue
Block a user