diff --git a/contentcuration/kolibri_public/search.py b/contentcuration/kolibri_public/search.py index ac67edfa79..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 @@ -63,10 +64,10 @@ def _get_available_languages(base_queryset): 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") + 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) 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() 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