From b004a2b2246ec924bdf1dccb4ff04bc9a3f471d7 Mon Sep 17 00:00:00 2001 From: ufedaseyeuconsultant Date: Mon, 19 Oct 2026 23:15:52 +0300 Subject: [PATCH 1/4] feat: return taxonomy_type on the object tags endpoint Each taxonomy entry returned by GET /api/content_tagging/v1/object_tags/{object_id}/ now carries taxonomy_type ("competency" or "tags"), computed with the CBE public API is_competency_taxonomy, the same way TaxonomyOrgSerializer does. ObjectTagOrgView joins each taxonomy's competency row so the check adds no per-taxonomy query. Co-Authored-By: Claude Opus 5.5 --- .../rest_api/v1/serializers.py | 23 +++++- .../rest_api/v1/tests/test_views.py | 76 +++++++++++++++++++ .../content_tagging/rest_api/v1/views.py | 11 ++- 3 files changed, 108 insertions(+), 2 deletions(-) diff --git a/openedx/core/djangoapps/content_tagging/rest_api/v1/serializers.py b/openedx/core/djangoapps/content_tagging/rest_api/v1/serializers.py index ac6af0dc365a..a968b4ae8175 100644 --- a/openedx/core/djangoapps/content_tagging/rest_api/v1/serializers.py +++ b/openedx/core/djangoapps/content_tagging/rest_api/v1/serializers.py @@ -8,6 +8,7 @@ from openedx_authz.authz import COURSES_MANAGE_TAGS from openedx_learning.api import is_competency_taxonomy from openedx_tagging.api import TaxonomyType +from openedx_tagging.models import ObjectTag from openedx_tagging.rest_api.v1.serializers import ( ObjectTagMinimalSerializer, ObjectTagsByTaxonomySerializer, @@ -118,7 +119,8 @@ def to_representation(self, instance) -> dict: class ObjectTagOrgByTaxonomySerializer(ObjectTagsByTaxonomySerializer): """ - Extend ObjectTagsByTaxonomySerializer to conditionally use openedx-authz for can_tag_object. + Extend ObjectTagsByTaxonomySerializer to conditionally use openedx-authz for can_tag_object, + and to report each taxonomy's ``taxonomy_type`` ("competency" or "tags"). """ def can_tag_object(self, obj_tag) -> bool | None: @@ -138,6 +140,25 @@ def can_tag_object(self, obj_tag) -> bool | None: # Fall back to parent implementation return super().can_tag_object(obj_tag) + def to_representation(self, instance: list[ObjectTag]) -> dict: + """ + Serialize the object tags grouped by taxonomy, adding ``taxonomy_type`` to each taxonomy entry. + + ``taxonomy_type`` is "competency" when ``is_competency_taxonomy`` (the CBE public API) says the + taxonomy is competency-backed, and "tags" otherwise. That check costs no extra query only if the + taxonomies were loaded with their competency row joined, as ``ObjectTagOrgView`` does. + """ + data = super().to_representation(instance) + taxonomies = {obj_tag.taxonomy_id: obj_tag.taxonomy for obj_tag in instance} + for by_object in data.values(): + for entry in by_object["taxonomies"]: + entry["taxonomy_type"] = ( + TaxonomyType.COMPETENCY.value + if is_competency_taxonomy(taxonomies[entry["taxonomy_id"]]) + else TaxonomyType.TAGS.value + ) + return data + class ObjectTagCopiedMinimalSerializer(ObjectTagMinimalSerializer): """ diff --git a/openedx/core/djangoapps/content_tagging/rest_api/v1/tests/test_views.py b/openedx/core/djangoapps/content_tagging/rest_api/v1/tests/test_views.py index da9234487bfe..233162ea45fe 100644 --- a/openedx/core/djangoapps/content_tagging/rest_api/v1/tests/test_views.py +++ b/openedx/core/djangoapps/content_tagging/rest_api/v1/tests/test_views.py @@ -13,6 +13,8 @@ import ddt from django.contrib.auth import get_user_model from django.core.files.uploadedfile import SimpleUploadedFile +from django.db import connection +from django.test.utils import CaptureQueriesContext from django.urls import reverse from edx_django_utils.cache import RequestCache from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator, LibraryCollectionLocator, LibraryContainerLocator @@ -2000,6 +2002,7 @@ def test_get_tags(self): 'export_id': '13-multiple-taxonomy', 'taxonomy_id': taxonomy.pk, 'can_tag_object': True, + 'taxonomy_type': 'tags', 'tags': [ { 'value': 'Tag 1', @@ -2043,6 +2046,7 @@ def test_get_copied_tags(self): 'taxonomy_id': self.t1.pk, 'can_tag_object': True, 'export_id': self.t1.export_id, + 'taxonomy_type': 'tags', 'tags': [ { 'value': 'android', @@ -2122,6 +2126,78 @@ def test_object_tags_query_count( assert response.data[object_id]["taxonomies"][0]["can_tag_object"] == expected_perm assert response.data[object_id]["taxonomies"][0]["tags"] == expected_tags + def _create_competency_taxonomy(self) -> Taxonomy: + """ + Create a competency taxonomy with one tag, owned by all orgs so the org filter shows it. + """ + taxonomy = create_competency_taxonomy(name="Nursing Competencies", export_id="nursing-competencies") + Tag.objects.create(taxonomy=taxonomy, value="Triage") + TaxonomyOrg.objects.create(taxonomy=taxonomy, org=None, rel_type=TaxonomyOrg.RelType.OWNER) + return taxonomy + + def _get_taxonomy_entries(self, object_id, user=None) -> list[dict]: + """ + GET the object's tags (as staffA unless another user is given) and return the taxonomy entries. + """ + self.client.force_authenticate(user=user or self.staffA) + response = self.client.get(OBJECT_TAGS_URL.format(object_id=object_id)) + assert response.status_code == 200 + return response.data[str(object_id)]["taxonomies"] + + def test_get_tags_taxonomy_type_competency(self): + competency = self._create_competency_taxonomy() + tagging_api.tag_object(object_id=str(self.courseA), taxonomy=competency, tags=["Triage"]) + + entries = self._get_taxonomy_entries(self.courseA) + + assert [e["taxonomy_type"] for e in entries] == ["competency"] + + def test_get_tags_taxonomy_type_ordinary(self): + tagging_api.tag_object(object_id=str(self.courseA), taxonomy=self.t1, tags=["android"]) + + entries = self._get_taxonomy_entries(self.courseA) + + assert [e["taxonomy_type"] for e in entries] == ["tags"] + + def test_get_tags_taxonomy_type_mixed(self): + competency = self._create_competency_taxonomy() + tagging_api.tag_object(object_id=str(self.courseA), taxonomy=competency, tags=["Triage"]) + tagging_api.tag_object(object_id=str(self.courseA), taxonomy=self.t1, tags=["android"]) + + entries = self._get_taxonomy_entries(self.courseA) + + types_by_taxonomy_id = {e["taxonomy_id"]: e["taxonomy_type"] for e in entries} + assert types_by_taxonomy_id == {competency.pk: "competency", self.t1.pk: "tags"} + + def test_get_tags_untagged_object(self): + assert self._get_taxonomy_entries(self.courseA) == [] + + def test_get_tags_query_count_independent_of_taxonomy_type_check(self): + """ + The query count does not grow with the number of taxonomies, competency ones included. + + All taxonomies here are all-org on purpose. For org-owned taxonomies, ``can_tag_object`` makes its own + organization lookups, a separate cost that this test leaves out so it isolates the cost of ``taxonomy_type``. + """ + competency = self._create_competency_taxonomy() + extra = tagging_api.create_taxonomy(name="Extra all-org taxonomy", enabled=True) + Tag.objects.create(taxonomy=extra, value="Extra") + TaxonomyOrg.objects.create(taxonomy=extra, org=None, rel_type=TaxonomyOrg.RelType.OWNER) + tagging_api.tag_object(object_id=str(self.courseB), taxonomy=self.t1, tags=["android"]) + for taxonomy, tag in ((self.t1, "android"), (competency, "Triage"), (extra, "Extra")): + tagging_api.tag_object(object_id=str(self.courseA), taxonomy=taxonomy, tags=[tag]) + + query_counts = [] + for course, expected_taxonomies in ((self.courseB, 1), (self.courseA, 3)): + # Warm up the site and waffle flag caches, as test_object_tags_query_count does. + self._get_taxonomy_entries(course, self.staff) + with CaptureQueriesContext(connection) as queries: + entries = self._get_taxonomy_entries(course, self.staff) + assert len(entries) == expected_taxonomies + query_counts.append(len(queries)) + + assert query_counts[0] == query_counts[1] + @skip_unless_cms @ddt.ddt diff --git a/openedx/core/djangoapps/content_tagging/rest_api/v1/views.py b/openedx/core/djangoapps/content_tagging/rest_api/v1/views.py index ac2ebf92dff1..f718981fb854 100644 --- a/openedx/core/djangoapps/content_tagging/rest_api/v1/views.py +++ b/openedx/core/djangoapps/content_tagging/rest_api/v1/views.py @@ -7,7 +7,7 @@ from typing import TYPE_CHECKING from django.core import exceptions -from django.db.models import Count +from django.db.models import Count, QuerySet from django.http import StreamingHttpResponse from openedx_authz import api as authz_api from openedx_authz.authz import COURSES_VIEW_COURSE @@ -204,6 +204,15 @@ class ObjectTagOrgView(ObjectTagView): filter_backends = [ObjectTagTaxonomyOrgFilterBackend] + def get_queryset(self) -> QuerySet: + """ + Return the object's ObjectTags with each taxonomy's competency row joined in, so the serializer's + ``taxonomy_type`` check adds no per-taxonomy query. + """ + # The path is written directly because the public helper select_competency_taxonomies() + # only accepts a Taxonomy queryset, not an ObjectTag queryset. + return super().get_queryset().select_related("taxonomy__competencytaxonomy") + @functools.cached_property def _authz_check(self) -> tuple[bool, CourseKey | None]: """ From 95104d1abb479974bb39fce885039b39335f0f99 Mon Sep 17 00:00:00 2001 From: ufedaseyeuconsultant Date: Tue, 20 Oct 2026 00:14:46 +0300 Subject: [PATCH 2/4] fix: handle tags without a taxonomy in taxonomy_type ObjectTag.taxonomy is nullable, since deleting a taxonomy leaves its tags with no taxonomy. Report such entries as "tags", which also satisfies mypy. Co-Authored-By: Claude Opus 5.5 --- .../djangoapps/content_tagging/rest_api/v1/serializers.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/openedx/core/djangoapps/content_tagging/rest_api/v1/serializers.py b/openedx/core/djangoapps/content_tagging/rest_api/v1/serializers.py index a968b4ae8175..104104b297a1 100644 --- a/openedx/core/djangoapps/content_tagging/rest_api/v1/serializers.py +++ b/openedx/core/djangoapps/content_tagging/rest_api/v1/serializers.py @@ -152,9 +152,11 @@ def to_representation(self, instance: list[ObjectTag]) -> dict: taxonomies = {obj_tag.taxonomy_id: obj_tag.taxonomy for obj_tag in instance} for by_object in data.values(): for entry in by_object["taxonomies"]: + # A tag whose taxonomy was deleted has no taxonomy, so it can't be a competency. + taxonomy = taxonomies[entry["taxonomy_id"]] entry["taxonomy_type"] = ( TaxonomyType.COMPETENCY.value - if is_competency_taxonomy(taxonomies[entry["taxonomy_id"]]) + if taxonomy is not None and is_competency_taxonomy(taxonomy) else TaxonomyType.TAGS.value ) return data From 3b8b605a1cf6fb41cbe0734ddee5fdbb38309a24 Mon Sep 17 00:00:00 2001 From: ufedaseyeuconsultant Date: Thu, 29 Oct 2026 22:23:22 +0300 Subject: [PATCH 3/4] fix: check competency taxonomies in one query via the CBE API ObjectTagOrgView joined taxonomy__competencytaxonomy into its queryset, reaching a CBE model relation directly, which ADR 0013 rules out. The serializer now loads the object tags' taxonomies once through select_competency_taxonomies() and asks is_competency_taxonomy() which of them are competency taxonomies, so the check is one query per response, and none for an untagged object. The view override is gone. Also document taxonomy_type on ObjectTagOrgView, assert the whole payload for an untagged object, and cover taxonomy_type on PUT. Co-Authored-By: Claude Opus 5.5 --- .../rest_api/v1/serializers.py | 19 +++++---- .../rest_api/v1/tests/test_views.py | 42 ++++++++++++------- .../content_tagging/rest_api/v1/views.py | 14 ++----- 3 files changed, 42 insertions(+), 33 deletions(-) diff --git a/openedx/core/djangoapps/content_tagging/rest_api/v1/serializers.py b/openedx/core/djangoapps/content_tagging/rest_api/v1/serializers.py index 104104b297a1..26e11ae4d6c2 100644 --- a/openedx/core/djangoapps/content_tagging/rest_api/v1/serializers.py +++ b/openedx/core/djangoapps/content_tagging/rest_api/v1/serializers.py @@ -6,9 +6,9 @@ from openedx_authz import api as authz_api from openedx_authz.authz import COURSES_MANAGE_TAGS -from openedx_learning.api import is_competency_taxonomy +from openedx_learning.api import is_competency_taxonomy, select_competency_taxonomies from openedx_tagging.api import TaxonomyType -from openedx_tagging.models import ObjectTag +from openedx_tagging.models import ObjectTag, Taxonomy from openedx_tagging.rest_api.v1.serializers import ( ObjectTagMinimalSerializer, ObjectTagsByTaxonomySerializer, @@ -145,18 +145,21 @@ def to_representation(self, instance: list[ObjectTag]) -> dict: Serialize the object tags grouped by taxonomy, adding ``taxonomy_type`` to each taxonomy entry. ``taxonomy_type`` is "competency" when ``is_competency_taxonomy`` (the CBE public API) says the - taxonomy is competency-backed, and "tags" otherwise. That check costs no extra query only if the - taxonomies were loaded with their competency row joined, as ``ObjectTagOrgView`` does. + taxonomy is competency-backed, and "tags" otherwise. All the taxonomies are checked with one query, + through ``select_competency_taxonomies``, however many there are; no query runs for an untagged object. """ data = super().to_representation(instance) - taxonomies = {obj_tag.taxonomy_id: obj_tag.taxonomy for obj_tag in instance} + taxonomy_ids = {obj_tag.taxonomy_id for obj_tag in instance if obj_tag.taxonomy_id is not None} + competency_taxonomy_ids = { + taxonomy.pk + for taxonomy in select_competency_taxonomies(Taxonomy.objects.filter(pk__in=taxonomy_ids)) + if is_competency_taxonomy(taxonomy) + } for by_object in data.values(): for entry in by_object["taxonomies"]: - # A tag whose taxonomy was deleted has no taxonomy, so it can't be a competency. - taxonomy = taxonomies[entry["taxonomy_id"]] entry["taxonomy_type"] = ( TaxonomyType.COMPETENCY.value - if taxonomy is not None and is_competency_taxonomy(taxonomy) + if entry["taxonomy_id"] in competency_taxonomy_ids else TaxonomyType.TAGS.value ) return data diff --git a/openedx/core/djangoapps/content_tagging/rest_api/v1/tests/test_views.py b/openedx/core/djangoapps/content_tagging/rest_api/v1/tests/test_views.py index 233162ea45fe..dd65dc75243c 100644 --- a/openedx/core/djangoapps/content_tagging/rest_api/v1/tests/test_views.py +++ b/openedx/core/djangoapps/content_tagging/rest_api/v1/tests/test_views.py @@ -2069,19 +2069,19 @@ def test_get_copied_tags(self): assert response.data[str(object_id_2)]["taxonomies"] == expected_tags @ddt.data( - ('staff', 'courseA', 10), - ('staff', 'libraryA', 13), - ('staff', 'collection_key', 13), - ("content_creatorA", 'courseA', 15, False), - ("content_creatorA", 'libraryA', 18, False), - ("content_creatorA", 'collection_key', 18, False), - ("library_staffA", 'libraryA', 18, False), # Library users can only view objecttags, not change them? - ("library_staffA", 'collection_key', 18, False), - ("library_userA", 'libraryA', 18, False), - ("library_userA", 'collection_key', 18, False), - ("instructorA", 'courseA', 15), - ("course_instructorA", 'courseA', 15), - ("course_staffA", 'courseA', 15), + ('staff', 'courseA', 11), + ('staff', 'libraryA', 14), + ('staff', 'collection_key', 14), + ("content_creatorA", 'courseA', 16, False), + ("content_creatorA", 'libraryA', 19, False), + ("content_creatorA", 'collection_key', 19, False), + ("library_staffA", 'libraryA', 19, False), # Library users can only view objecttags, not change them? + ("library_staffA", 'collection_key', 19, False), + ("library_userA", 'libraryA', 19, False), + ("library_userA", 'collection_key', 19, False), + ("instructorA", 'courseA', 16), + ("course_instructorA", 'courseA', 16), + ("course_staffA", 'courseA', 16), ) @ddt.unpack def test_object_tags_query_count( @@ -2170,7 +2170,21 @@ def test_get_tags_taxonomy_type_mixed(self): assert types_by_taxonomy_id == {competency.pk: "competency", self.t1.pk: "tags"} def test_get_tags_untagged_object(self): - assert self._get_taxonomy_entries(self.courseA) == [] + self.client.force_authenticate(user=self.staffA) + response = self.client.get(OBJECT_TAGS_URL.format(object_id=self.courseA)) + + assert response.status_code == 200 + assert response.data == {str(self.courseA): {"taxonomies": []}} + + def test_put_tags_response_includes_taxonomy_type(self): + competency = self._create_competency_taxonomy() + self.client.force_authenticate(user=self.staffA) + + response = self._call_put_request(self.courseA, competency.pk, ["Triage"]) + + assert response.status_code == 200 + entries = response.data[str(self.courseA)]["taxonomies"] + assert [e["taxonomy_type"] for e in entries] == ["competency"] def test_get_tags_query_count_independent_of_taxonomy_type_check(self): """ diff --git a/openedx/core/djangoapps/content_tagging/rest_api/v1/views.py b/openedx/core/djangoapps/content_tagging/rest_api/v1/views.py index f718981fb854..81687bf2c2f2 100644 --- a/openedx/core/djangoapps/content_tagging/rest_api/v1/views.py +++ b/openedx/core/djangoapps/content_tagging/rest_api/v1/views.py @@ -7,7 +7,7 @@ from typing import TYPE_CHECKING from django.core import exceptions -from django.db.models import Count, QuerySet +from django.db.models import Count from django.http import StreamingHttpResponse from openedx_authz import api as authz_api from openedx_authz.authz import COURSES_VIEW_COURSE @@ -196,7 +196,8 @@ class ObjectTagOrgView(ObjectTagView): This view extends the ObjectTagView to add Organization filters for the results, and fires events when the tags are updated. - Refer to ObjectTagView docstring for usage details. + Refer to ObjectTagView docstring for usage details. In addition, each taxonomy entry carries + ``taxonomy_type``: "competency" for a competency taxonomy, and "tags" for any other taxonomy. """ # Serializer overrides minimal_serializer_class = ObjectTagCopiedMinimalSerializer @@ -204,15 +205,6 @@ class ObjectTagOrgView(ObjectTagView): filter_backends = [ObjectTagTaxonomyOrgFilterBackend] - def get_queryset(self) -> QuerySet: - """ - Return the object's ObjectTags with each taxonomy's competency row joined in, so the serializer's - ``taxonomy_type`` check adds no per-taxonomy query. - """ - # The path is written directly because the public helper select_competency_taxonomies() - # only accepts a Taxonomy queryset, not an ObjectTag queryset. - return super().get_queryset().select_related("taxonomy__competencytaxonomy") - @functools.cached_property def _authz_check(self) -> tuple[bool, CourseKey | None]: """ From 87ade87d110c3fc79be8069dd6ba6c7645ecf606 Mon Sep 17 00:00:00 2001 From: ufedaseyeuconsultant Date: Mon, 16 Nov 2026 19:16:54 +0300 Subject: [PATCH 4/4] refactor: simplify the taxonomy_type check and its query-count test The query-count test now requests the same object before and after adding a competency taxonomy and an all-org taxonomy to it, and asserts the query count is unchanged. The earlier version compared two different objects, so differences between the objects could hide a per-taxonomy query. The serializer no longer skips tags without a taxonomy. The object tags endpoint never returns them, because the object-tag lookup excludes tags whose taxonomy was deleted and this view does not ask for them. The to_representation docstring now gives the reason for the batch: is_competency_taxonomy costs one query per taxonomy unless the taxonomies are loaded through select_competency_taxonomies. Co-authored-by: Mary Gwozdz Co-Authored-By: Claude Fable 5 --- .../rest_api/v1/serializers.py | 8 +++-- .../rest_api/v1/tests/test_views.py | 36 ++++++++++--------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/openedx/core/djangoapps/content_tagging/rest_api/v1/serializers.py b/openedx/core/djangoapps/content_tagging/rest_api/v1/serializers.py index 26e11ae4d6c2..4204aec3b4a9 100644 --- a/openedx/core/djangoapps/content_tagging/rest_api/v1/serializers.py +++ b/openedx/core/djangoapps/content_tagging/rest_api/v1/serializers.py @@ -145,11 +145,13 @@ def to_representation(self, instance: list[ObjectTag]) -> dict: Serialize the object tags grouped by taxonomy, adding ``taxonomy_type`` to each taxonomy entry. ``taxonomy_type`` is "competency" when ``is_competency_taxonomy`` (the CBE public API) says the - taxonomy is competency-backed, and "tags" otherwise. All the taxonomies are checked with one query, - through ``select_competency_taxonomies``, however many there are; no query runs for an untagged object. + taxonomy is competency-backed, and "tags" otherwise. + + ``is_competency_taxonomy`` costs one query per taxonomy unless the taxonomies are loaded through + ``select_competency_taxonomies``, so the check is batched this way to keep the query count flat. """ data = super().to_representation(instance) - taxonomy_ids = {obj_tag.taxonomy_id for obj_tag in instance if obj_tag.taxonomy_id is not None} + taxonomy_ids = {obj_tag.taxonomy_id for obj_tag in instance} competency_taxonomy_ids = { taxonomy.pk for taxonomy in select_competency_taxonomies(Taxonomy.objects.filter(pk__in=taxonomy_ids)) diff --git a/openedx/core/djangoapps/content_tagging/rest_api/v1/tests/test_views.py b/openedx/core/djangoapps/content_tagging/rest_api/v1/tests/test_views.py index dd65dc75243c..6cf73732a30a 100644 --- a/openedx/core/djangoapps/content_tagging/rest_api/v1/tests/test_views.py +++ b/openedx/core/djangoapps/content_tagging/rest_api/v1/tests/test_views.py @@ -2135,11 +2135,11 @@ def _create_competency_taxonomy(self) -> Taxonomy: TaxonomyOrg.objects.create(taxonomy=taxonomy, org=None, rel_type=TaxonomyOrg.RelType.OWNER) return taxonomy - def _get_taxonomy_entries(self, object_id, user=None) -> list[dict]: + def _get_taxonomy_entries(self, object_id) -> list[dict]: """ - GET the object's tags (as staffA unless another user is given) and return the taxonomy entries. + GET the object's tags as staffA and return the taxonomy entries. """ - self.client.force_authenticate(user=user or self.staffA) + self.client.force_authenticate(user=self.staffA) response = self.client.get(OBJECT_TAGS_URL.format(object_id=object_id)) assert response.status_code == 200 return response.data[str(object_id)]["taxonomies"] @@ -2193,24 +2193,26 @@ def test_get_tags_query_count_independent_of_taxonomy_type_check(self): All taxonomies here are all-org on purpose. For org-owned taxonomies, ``can_tag_object`` makes its own organization lookups, a separate cost that this test leaves out so it isolates the cost of ``taxonomy_type``. """ + object_id = str(self.courseA) + url = OBJECT_TAGS_URL.format(object_id=object_id) + self.client.force_authenticate(user=self.staff) + tagging_api.tag_object(object_id=object_id, taxonomy=self.t1, tags=["android"]) + self.client.get(url) # Warm up the site and waffle flag caches, as test_object_tags_query_count does. + with CaptureQueriesContext(connection) as queries_with_one_taxonomy: + self.client.get(url) + competency = self._create_competency_taxonomy() extra = tagging_api.create_taxonomy(name="Extra all-org taxonomy", enabled=True) Tag.objects.create(taxonomy=extra, value="Extra") TaxonomyOrg.objects.create(taxonomy=extra, org=None, rel_type=TaxonomyOrg.RelType.OWNER) - tagging_api.tag_object(object_id=str(self.courseB), taxonomy=self.t1, tags=["android"]) - for taxonomy, tag in ((self.t1, "android"), (competency, "Triage"), (extra, "Extra")): - tagging_api.tag_object(object_id=str(self.courseA), taxonomy=taxonomy, tags=[tag]) - - query_counts = [] - for course, expected_taxonomies in ((self.courseB, 1), (self.courseA, 3)): - # Warm up the site and waffle flag caches, as test_object_tags_query_count does. - self._get_taxonomy_entries(course, self.staff) - with CaptureQueriesContext(connection) as queries: - entries = self._get_taxonomy_entries(course, self.staff) - assert len(entries) == expected_taxonomies - query_counts.append(len(queries)) - - assert query_counts[0] == query_counts[1] + tagging_api.tag_object(object_id=object_id, taxonomy=competency, tags=["Triage"]) + tagging_api.tag_object(object_id=object_id, taxonomy=extra, tags=["Extra"]) + + with CaptureQueriesContext(connection) as queries_with_three_taxonomies: + response = self.client.get(url) + + assert len(response.data[object_id]["taxonomies"]) == 3 + assert len(queries_with_three_taxonomies) == len(queries_with_one_taxonomy) @skip_unless_cms