From 002892f77e01429fc2eb98cffa6ea896d0c146e6 Mon Sep 17 00:00:00 2001 From: Richard Tibbles Date: Tue, 11 Apr 2023 10:22:37 -0700 Subject: [PATCH 1/3] Add test for language pagination labels. Fix language label generation. --- contentcuration/kolibri_public/search.py | 15 ++++++++++----- .../kolibri_public/tests/test_content_app.py | 9 +++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/contentcuration/kolibri_public/search.py b/contentcuration/kolibri_public/search.py index ac67edfa79..4b1dbdb7a5 100644 --- a/contentcuration/kolibri_public/search.py +++ b/contentcuration/kolibri_public/search.py @@ -62,11 +62,16 @@ def _get_available_languages(base_queryset): # Updated to use contentcuration Language model from contentcuration.models import Language - langs = Language.objects.filter( - id__in=base_queryset.exclude(lang=None) - .values_list("lang_id", flat=True) - .distinct() - ).values("id", "lang_name") + langs = map( + # Updated to use contentcuration field names + # Convert language objects to dicts mapped to the kolibri field names + lambda x: {"id": x["id"], "lang_name": x["native_name"]}, + Language.objects.filter( + id__in=base_queryset.exclude(lang=None) + .values_list("lang_id", flat=True) + .distinct() + ).values("id", "native_name") + ) return list(langs) diff --git a/contentcuration/kolibri_public/tests/test_content_app.py b/contentcuration/kolibri_public/tests/test_content_app.py index e34c6afa63..c6f4327972 100644 --- a/contentcuration/kolibri_public/tests/test_content_app.py +++ b/contentcuration/kolibri_public/tests/test_content_app.py @@ -15,6 +15,7 @@ from rest_framework.test import APITestCase from contentcuration.models import generate_storage_url +from contentcuration.models import Language kind_activity_map = { @@ -186,6 +187,14 @@ def test_contentnode_list(self): self.assertEqual(len(response.data), expected_output) self._assert_nodes(response.data, nodes) + def test_contentnode_list_labels(self): + nodes = self.root.get_descendants(include_self=True).filter(available=True) + response = self._get(reverse("publiccontentnode-list"), data={"max_results": 1}) + node_languages = Language.objects.filter(contentnode__in=nodes) + self.assertEqual(len(response.data["labels"]["languages"]), node_languages.distinct().count()) + for lang in response.data["labels"]["languages"]: + self.assertTrue(node_languages.filter(native_name=lang["lang_name"]).exists()) + def test_contentnode_list_headers(self): channel = models.ChannelMetadata.objects.get() channel.last_updated = datetime.datetime.now() From 30b7afeb844ee1f250dc91aae3a7fd2a348b8a6a Mon Sep 17 00:00:00 2001 From: Richard Tibbles Date: Wed, 12 Apr 2023 09:33:43 -0700 Subject: [PATCH 2/3] Use F expression to map native_name to lang_name in query. --- contentcuration/kolibri_public/search.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/contentcuration/kolibri_public/search.py b/contentcuration/kolibri_public/search.py index 4b1dbdb7a5..6f1e3648ff 100644 --- a/contentcuration/kolibri_public/search.py +++ b/contentcuration/kolibri_public/search.py @@ -13,6 +13,7 @@ from django.contrib.postgres.aggregates import BitOr from django.core.cache import cache from django.db.models import Case +from django.db.models import F from django.db.models import Max from django.db.models import Value from django.db.models import When @@ -62,16 +63,11 @@ def _get_available_languages(base_queryset): # Updated to use contentcuration Language model from contentcuration.models import Language - langs = map( - # Updated to use contentcuration field names - # Convert language objects to dicts mapped to the kolibri field names - lambda x: {"id": x["id"], "lang_name": x["native_name"]}, - Language.objects.filter( - id__in=base_queryset.exclude(lang=None) - .values_list("lang_id", flat=True) - .distinct() - ).values("id", "native_name") - ) + langs = Language.objects.filter( + id__in=base_queryset.exclude(lang=None).values_list("lang_id", flat=True).distinct() + # Updated to use contentcuration field names + # Convert language objects to dicts mapped to the kolibri field names + ).values("id", lang_name=F("native_name")) return list(langs) From ce97b32d4b45ca45e8aac29d4dc98a3227512a15 Mon Sep 17 00:00:00 2001 From: Richard Tibbles Date: Wed, 12 Apr 2023 10:02:14 -0700 Subject: [PATCH 3/3] Remove deprecated and no longer used codecov library. --- requirements-dev.in | 1 - requirements-dev.txt | 4 ---- 2 files changed, 5 deletions(-) diff --git a/requirements-dev.in b/requirements-dev.in index 5d977035f0..59157d10d7 100644 --- a/requirements-dev.in +++ b/requirements-dev.in @@ -14,7 +14,6 @@ pytest-pythonpath pytest-timeout pytest-watch pre-commit==1.15.1 -codecov coverage pytest-cov nodeenv diff --git a/requirements-dev.txt b/requirements-dev.txt index 1af5a97343..39371567fb 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -35,8 +35,6 @@ click==8.1.3 # -c requirements.txt # flask # pip-tools -codecov==2.1.12 - # via -r requirements-dev.in colorama==0.4.4 # via pytest-watch configargparse==1.5.3 @@ -50,7 +48,6 @@ coreschema==0.0.4 coverage[toml]==6.2 # via # -r requirements-dev.in - # codecov # pytest-cov customizable-django-profiler @ git+https://github.com/someshchaturvedi/customizable-django-profiler.git # via -r requirements-dev.in @@ -220,7 +217,6 @@ pyzmq==23.1.0 requests==2.25.1 # via # -c requirements.txt - # codecov # coreapi # locust roundrobin==0.0.2