Loading src/rpc/methods.py +4 −6 Original line number Diff line number Diff line Loading @@ -9,7 +9,6 @@ import cv2 import numpy import jama.native_libs # noqa: F401 - configures libvips lookup on macOS import pyvips import unidecode from django.contrib.auth.models import User from django.db.models import QuerySet from django.db.utils import IntegrityError Loading Loading @@ -222,10 +221,6 @@ def _collection_path_segments(path: str) -> List[str]: return segments def _ascii_collection_path_segments(path: str) -> List[str]: return [unidecode.unidecode(segment) for segment in _collection_path_segments(path)] def _resources_with_serialization_data( query_set: QuerySet, include_metas: bool ) -> QuerySet: Loading Loading @@ -717,7 +712,10 @@ def add_collection_from_path(user: User, path: str, project_id: int) -> List[Dic hierarchy = [] previous_dir = project.root_collection for dir_name in _ascii_collection_path_segments(path): for dir_name in path.split("/"): dir_name = dir_name.strip() if not dir_name: continue serialized_collection = add_collection(user, dir_name, previous_dir.pk) hierarchy.append(serialized_collection) previous_dir = Collection.objects.get(pk=serialized_collection["id"]) Loading src/rpc/tests.py +27 −0 Original line number Diff line number Diff line Loading @@ -625,6 +625,33 @@ class ServiceTestCase(TestCase): idx = idx + 1 self.assertEqual(models.Collection.objects.filter(title="root").count(), 1) def test_add_collection_from_path_strips_empty_and_non_ascii_items(self): expected_titles = [ "été", "Noël & São Paulo", "Crème brûlée № ①", "東京・北京", ] collections = methods.add_collection_from_path( self.test_user, " / été / //\tNoël & São Paulo \n/ Crème brûlée № ① /// 東京・北京 \t/", self.test_project.pk, ) self.assertEqual( [collection["title"] for collection in collections], expected_titles ) self.assertEqual( [ancestor["title"] for ancestor in collections[-1]["ancestors"]], expected_titles[:-1], ) parent = self.test_project.root_collection for title in expected_titles: parent = models.Collection.objects.get( title=title, parent=parent, project=self.test_project ) def test_find_collection_from_path(self): created_collections = methods.add_collection_from_path( self.test_user, "/some/example/collection/", self.test_project.pk Loading Loading
src/rpc/methods.py +4 −6 Original line number Diff line number Diff line Loading @@ -9,7 +9,6 @@ import cv2 import numpy import jama.native_libs # noqa: F401 - configures libvips lookup on macOS import pyvips import unidecode from django.contrib.auth.models import User from django.db.models import QuerySet from django.db.utils import IntegrityError Loading Loading @@ -222,10 +221,6 @@ def _collection_path_segments(path: str) -> List[str]: return segments def _ascii_collection_path_segments(path: str) -> List[str]: return [unidecode.unidecode(segment) for segment in _collection_path_segments(path)] def _resources_with_serialization_data( query_set: QuerySet, include_metas: bool ) -> QuerySet: Loading Loading @@ -717,7 +712,10 @@ def add_collection_from_path(user: User, path: str, project_id: int) -> List[Dic hierarchy = [] previous_dir = project.root_collection for dir_name in _ascii_collection_path_segments(path): for dir_name in path.split("/"): dir_name = dir_name.strip() if not dir_name: continue serialized_collection = add_collection(user, dir_name, previous_dir.pk) hierarchy.append(serialized_collection) previous_dir = Collection.objects.get(pk=serialized_collection["id"]) Loading
src/rpc/tests.py +27 −0 Original line number Diff line number Diff line Loading @@ -625,6 +625,33 @@ class ServiceTestCase(TestCase): idx = idx + 1 self.assertEqual(models.Collection.objects.filter(title="root").count(), 1) def test_add_collection_from_path_strips_empty_and_non_ascii_items(self): expected_titles = [ "été", "Noël & São Paulo", "Crème brûlée № ①", "東京・北京", ] collections = methods.add_collection_from_path( self.test_user, " / été / //\tNoël & São Paulo \n/ Crème brûlée № ① /// 東京・北京 \t/", self.test_project.pk, ) self.assertEqual( [collection["title"] for collection in collections], expected_titles ) self.assertEqual( [ancestor["title"] for ancestor in collections[-1]["ancestors"]], expected_titles[:-1], ) parent = self.test_project.root_collection for title in expected_titles: parent = models.Collection.objects.get( title=title, parent=parent, project=self.test_project ) def test_find_collection_from_path(self): created_collections = methods.add_collection_from_path( self.test_user, "/some/example/collection/", self.test_project.pk Loading