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 ebe453f5ca06..f64fba5c3358 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 @@ -44,7 +44,7 @@ TAXONOMY_ORG_LIST_URL = "/api/content_tagging/v1/taxonomies/" TAXONOMY_ORG_DETAIL_URL = "/api/content_tagging/v1/taxonomies/{pk}/" TAXONOMY_ORG_UPDATE_ORG_URL = "/api/content_tagging/v1/taxonomies/{pk}/orgs/" -OBJECT_TAG_UPDATE_URL = "/api/content_tagging/v1/object_tags/{object_id}/?taxonomy={taxonomy_id}" +OBJECT_TAG_UPDATE_URL = "/api/content_tagging/v1/object_tags/{object_id}/" OBJECT_TAGS_EXPORT_URL = "/api/content_tagging/v1/object_tags/{object_id}/export/" OBJECT_TAGS_URL = "/api/content_tagging/v1/object_tags/{object_id}/" TAXONOMY_TEMPLATE_URL = "/api/content_tagging/v1/taxonomies/import/{filename}" @@ -1404,6 +1404,13 @@ class TestObjectTagViewSet(TestObjectTagMixin, APITestCase): Testing various cases for the ObjectTagView. """ + def _call_put_request(self, object_id, taxonomy_id, tags): + url = OBJECT_TAG_UPDATE_URL.format(object_id=object_id) + return self.client.put(url, {"tagsData": [{ + "taxonomy": taxonomy_id, + "tags": tags, + }]}, format="json") + @ddt.data( # staffA and staff are staff in courseA and can tag using enabled taxonomies ("user", "tA1", ["Tag 1"], status.HTTP_403_FORBIDDEN), @@ -1429,9 +1436,7 @@ def test_tag_course(self, user_attr, taxonomy_attr, tag_values, expected_status) taxonomy = getattr(self, taxonomy_attr) - url = OBJECT_TAG_UPDATE_URL.format(object_id=self.courseA, taxonomy_id=taxonomy.pk) - - response = self.client.put(url, {"tags": tag_values}, format="json") + response = self._call_put_request(self.courseA, taxonomy.pk, tag_values) assert response.status_code == expected_status if status.is_success(expected_status): @@ -1445,6 +1450,7 @@ def test_tag_course(self, user_attr, taxonomy_attr, tag_values, expected_status) assert tags_by_taxonomy == [] # No tags are set from any taxonomy # Check that re-fetching the tags returns what we set + url = OBJECT_TAG_UPDATE_URL.format(object_id=self.courseA) new_response = self.client.get(url, format="json") assert status.is_success(new_response.status_code) assert new_response.data == response.data @@ -1463,8 +1469,7 @@ def test_tag_course_disabled_taxonomy(self, user_attr): disabled_taxonomy = self.tA2 assert disabled_taxonomy.enabled is False - url = OBJECT_TAG_UPDATE_URL.format(object_id=self.courseA, taxonomy_id=disabled_taxonomy.pk) - response = self.client.put(url, {"tags": ["Tag 1"]}, format="json") + response = self._call_put_request(self.courseA, disabled_taxonomy.pk, ["Tag 1"]) assert response.status_code == status.HTTP_403_FORBIDDEN @@ -1484,9 +1489,7 @@ def test_tag_course_invalid(self, user_attr, taxonomy_attr): taxonomy = getattr(self, taxonomy_attr) - url = OBJECT_TAG_UPDATE_URL.format(object_id=self.courseA, taxonomy_id=taxonomy.pk) - - response = self.client.put(url, {"tags": ["invalid"]}, format="json") + response = self._call_put_request(self.courseA, taxonomy.pk, ["invalid"]) assert response.status_code == status.HTTP_400_BAD_REQUEST @ddt.data( @@ -1513,9 +1516,7 @@ def test_tag_xblock(self, user_attr, taxonomy_attr, tag_values, expected_status) taxonomy = getattr(self, taxonomy_attr) - url = OBJECT_TAG_UPDATE_URL.format(object_id=self.xblockA, taxonomy_id=taxonomy.pk) - - response = self.client.put(url, {"tags": tag_values}, format="json") + response = self._call_put_request(self.xblockA, taxonomy.pk, tag_values) assert response.status_code == expected_status if status.is_success(expected_status): @@ -1529,6 +1530,7 @@ def test_tag_xblock(self, user_attr, taxonomy_attr, tag_values, expected_status) assert tags_by_taxonomy == [] # No tags are set from any taxonomy # Check that re-fetching the tags returns what we set + url = OBJECT_TAG_UPDATE_URL.format(object_id=self.xblockA) new_response = self.client.get(url, format="json") assert status.is_success(new_response.status_code) assert new_response.data == response.data @@ -1547,8 +1549,7 @@ def test_tag_xblock_disabled_taxonomy(self, user_attr): disabled_taxonomy = self.tA2 assert disabled_taxonomy.enabled is False - url = OBJECT_TAG_UPDATE_URL.format(object_id=self.xblockA, taxonomy_id=disabled_taxonomy.pk) - response = self.client.put(url, {"tags": ["Tag 1"]}, format="json") + response = self._call_put_request(self.xblockA, disabled_taxonomy.pk, ["Tag 1"]) assert response.status_code == status.HTTP_403_FORBIDDEN @@ -1568,9 +1569,7 @@ def test_tag_xblock_invalid(self, user_attr, taxonomy_attr): taxonomy = getattr(self, taxonomy_attr) - url = OBJECT_TAG_UPDATE_URL.format(object_id=self.xblockA, taxonomy_id=taxonomy.pk) - - response = self.client.put(url, {"tags": ["invalid"]}, format="json") + response = self._call_put_request(self.xblockA, taxonomy.pk, ["invalid"]) assert response.status_code == status.HTTP_400_BAD_REQUEST @ddt.data( @@ -1598,9 +1597,7 @@ def test_tag_library(self, user_attr, taxonomy_attr, tag_values, expected_status taxonomy = getattr(self, taxonomy_attr) - url = OBJECT_TAG_UPDATE_URL.format(object_id=self.libraryA, taxonomy_id=taxonomy.pk) - - response = self.client.put(url, {"tags": tag_values}, format="json") + response = self._call_put_request(self.libraryA, taxonomy.pk, tag_values) assert response.status_code == expected_status if status.is_success(expected_status): @@ -1614,6 +1611,7 @@ def test_tag_library(self, user_attr, taxonomy_attr, tag_values, expected_status assert tags_by_taxonomy == [] # No tags are set from any taxonomy # Check that re-fetching the tags returns what we set + url = OBJECT_TAG_UPDATE_URL.format(object_id=self.libraryA) new_response = self.client.get(url, format="json") assert status.is_success(new_response.status_code) assert new_response.data == response.data @@ -1632,8 +1630,7 @@ def test_tag_library_disabled_taxonomy(self, user_attr): disabled_taxonomy = self.tA2 assert disabled_taxonomy.enabled is False - url = OBJECT_TAG_UPDATE_URL.format(object_id=self.libraryA, taxonomy_id=disabled_taxonomy.pk) - response = self.client.put(url, {"tags": ["Tag 1"]}, format="json") + response = self._call_put_request(self.libraryA, disabled_taxonomy.pk, ["Tag 1"]) assert response.status_code == status.HTTP_403_FORBIDDEN @@ -1653,9 +1650,7 @@ def test_tag_library_invalid(self, user_attr, taxonomy_attr): taxonomy = getattr(self, taxonomy_attr) - url = OBJECT_TAG_UPDATE_URL.format(object_id=self.libraryA, taxonomy_id=taxonomy.pk) - - response = self.client.put(url, {"tags": ["invalid"]}, format="json") + response = self._call_put_request(self.libraryA, taxonomy.pk, ["invalid"]) assert response.status_code == status.HTTP_400_BAD_REQUEST @ddt.data( @@ -1672,9 +1667,7 @@ def test_tag_cross_org(self, user_attr, expected_status): user = getattr(self, user_attr) self.client.force_authenticate(user=user) - url = OBJECT_TAG_UPDATE_URL.format(object_id=self.courseB, taxonomy_id=self.tA1.pk) - - response = self.client.put(url, {"tags": ["Tag 1"]}, format="json") + response = self._call_put_request(self.courseB, self.tA1.pk, ["Tag 1"]) assert response.status_code == expected_status @@ -1692,9 +1685,7 @@ def test_tag_no_org(self, user_attr, expected_status): user = getattr(self, user_attr) self.client.force_authenticate(user=user) - url = OBJECT_TAG_UPDATE_URL.format(object_id=self.courseA, taxonomy_id=self.ot1.pk) - - response = self.client.put(url, {"tags": []}, format="json") + response = self._call_put_request(self.courseA, self.ot1.pk, []) assert response.status_code == expected_status @@ -1709,9 +1700,7 @@ def test_tag_no_permission(self, objectid_attr): self.client.force_authenticate(user=self.staffA) object_id = getattr(self, objectid_attr) - url = OBJECT_TAG_UPDATE_URL.format(object_id=object_id, taxonomy_id=self.tA1.pk) - - response = self.client.put(url, {"tags": ["Tag 1"]}, format="json") + response = self._call_put_request(object_id, self.tA1.pk, ["Tag 1"]) assert response.status_code == status.HTTP_403_FORBIDDEN @@ -1725,9 +1714,7 @@ def test_tag_unauthorized(self, objectid_attr): """ object_id = getattr(self, objectid_attr) - url = OBJECT_TAG_UPDATE_URL.format(object_id=object_id, taxonomy_id=self.tA1.pk) - - response = self.client.put(url, {"tags": ["Tag 1"]}, format="json") + response = self._call_put_request(object_id, self.tA1.pk, ["Tag 1"]) assert response.status_code == status.HTTP_401_UNAUTHORIZED @@ -1735,10 +1722,9 @@ def test_tag_invalid_object(self): """ Test that we cannot tag an object that is not a CouseKey, LibraryLocatorV2 or UsageKey """ - url = OBJECT_TAG_UPDATE_URL.format(object_id='invalid_key', taxonomy_id=self.tA1.pk) self.client.force_authenticate(user=self.staff) - response = self.client.put(url, {"tags": ["Tag 1"]}, format="json") + response = self._call_put_request('invalid_key', self.tA1.pk, ["Tag 1"]) assert response.status_code == status.HTTP_403_FORBIDDEN @@ -1749,10 +1735,9 @@ def test_get_tags(self): self.client.force_authenticate(user=self.staffA) taxonomy = self.multiple_taxonomy tag_values = ["Tag 1", "Tag 2"] - put_url = OBJECT_TAG_UPDATE_URL.format(object_id=self.courseA, taxonomy_id=taxonomy.pk) # Tag an object - response1 = self.client.put(put_url, {"tags": tag_values}, format="json") + response1 = self._call_put_request(self.courseA, taxonomy.pk, tag_values) assert status.is_success(response1.status_code) # Fetch this object's tags for a single taxonomy @@ -2077,19 +2062,27 @@ def test_import_no_name(self, file_format) -> None: ) def test_import_no_export_id(self, file_format) -> None: url = TAXONOMY_CREATE_IMPORT_URL - file = SimpleUploadedFile(f"taxonomy.{file_format}", b"invalid file content") + new_tags = [ + {"id": "tag_1", "value": "Tag 1"}, + ] + file = self._get_file(new_tags, file_format) self.client.force_authenticate(user=self.staff) response = self.client.post( url, { - "taxonomt_name": "Imported Taxonomy name", + "taxonomy_name": "Imported Taxonomy", "taxonomy_description": "Imported Taxonomy description", "file": file, }, format="multipart" ) - assert response.status_code == status.HTTP_400_BAD_REQUEST - assert response.data["taxonomy_export_id"][0] == "This field is required." + assert response.status_code == status.HTTP_201_CREATED + + taxonomy = response.data + taxonomy_id = taxonomy["id"] + assert taxonomy["name"] == "Imported Taxonomy" + assert taxonomy["description"] == "Imported Taxonomy description" + assert taxonomy["export_id"] == f"{taxonomy_id}-imported-taxonomy" # Check if the taxonomy was not created assert not Taxonomy.objects.filter(name="Imported Taxonomy name").exists() diff --git a/requirements/constraints.txt b/requirements/constraints.txt index 14ca5717b255..3bd6ac7a1500 100644 --- a/requirements/constraints.txt +++ b/requirements/constraints.txt @@ -108,7 +108,7 @@ libsass==0.10.0 click==8.1.6 # pinning this version to avoid updates while the library is being developed -openedx-learning==0.8.0 +openedx-learning==0.9.2 # Open AI version 1.0.0 dropped support for openai.ChatCompletion which is currently in use in enterprise. openai<=0.28.1 diff --git a/requirements/edx/base.txt b/requirements/edx/base.txt index b23ed570c0e4..6f354ad70601 100644 --- a/requirements/edx/base.txt +++ b/requirements/edx/base.txt @@ -794,7 +794,7 @@ openedx-filters==1.8.1 # -r requirements/edx/kernel.in # lti-consumer-xblock # ora2 -openedx-learning==0.8.0 +openedx-learning==0.9.2 # via # -c requirements/edx/../constraints.txt # -r requirements/edx/kernel.in diff --git a/requirements/edx/development.txt b/requirements/edx/development.txt index 073a52e80adc..dc7f2fdadee9 100644 --- a/requirements/edx/development.txt +++ b/requirements/edx/development.txt @@ -1317,7 +1317,7 @@ openedx-filters==1.8.1 # -r requirements/edx/testing.txt # lti-consumer-xblock # ora2 -openedx-learning==0.8.0 +openedx-learning==0.9.2 # via # -c requirements/edx/../constraints.txt # -r requirements/edx/doc.txt diff --git a/requirements/edx/doc.txt b/requirements/edx/doc.txt index 2246b2a94e4b..671d45be1217 100644 --- a/requirements/edx/doc.txt +++ b/requirements/edx/doc.txt @@ -932,7 +932,7 @@ openedx-filters==1.8.1 # -r requirements/edx/base.txt # lti-consumer-xblock # ora2 -openedx-learning==0.8.0 +openedx-learning==0.9.2 # via # -c requirements/edx/../constraints.txt # -r requirements/edx/base.txt diff --git a/requirements/edx/testing.txt b/requirements/edx/testing.txt index 9e42bf401afc..89dd96851bc2 100644 --- a/requirements/edx/testing.txt +++ b/requirements/edx/testing.txt @@ -987,7 +987,7 @@ openedx-filters==1.8.1 # -r requirements/edx/base.txt # lti-consumer-xblock # ora2 -openedx-learning==0.8.0 +openedx-learning==0.9.2 # via # -c requirements/edx/../constraints.txt # -r requirements/edx/base.txt