feat: bump openedx-learning to support tagging with multiple taxonomies at once (#34490)

This commit is contained in:
Chris Chávez
2024-04-25 12:44:47 -05:00
committed by GitHub
parent df7fb35867
commit a33165aaa6
6 changed files with 43 additions and 50 deletions

View File

@@ -44,7 +44,7 @@ User = get_user_model()
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 @@ class TestObjectTagViewSet(TestObjectTagMixin, APITestCase):
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 @@ class TestObjectTagViewSet(TestObjectTagMixin, APITestCase):
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 @@ class TestObjectTagViewSet(TestObjectTagMixin, APITestCase):
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 @@ class TestObjectTagViewSet(TestObjectTagMixin, APITestCase):
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 @@ class TestObjectTagViewSet(TestObjectTagMixin, APITestCase):
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 @@ class TestObjectTagViewSet(TestObjectTagMixin, APITestCase):
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 @@ class TestObjectTagViewSet(TestObjectTagMixin, APITestCase):
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 @@ class TestObjectTagViewSet(TestObjectTagMixin, APITestCase):
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 @@ class TestObjectTagViewSet(TestObjectTagMixin, APITestCase):
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 @@ class TestObjectTagViewSet(TestObjectTagMixin, APITestCase):
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 @@ class TestObjectTagViewSet(TestObjectTagMixin, APITestCase):
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 @@ class TestObjectTagViewSet(TestObjectTagMixin, APITestCase):
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 @@ class TestObjectTagViewSet(TestObjectTagMixin, APITestCase):
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 @@ class TestObjectTagViewSet(TestObjectTagMixin, APITestCase):
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 @@ class TestObjectTagViewSet(TestObjectTagMixin, APITestCase):
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 @@ class TestObjectTagViewSet(TestObjectTagMixin, APITestCase):
"""
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 @@ class TestObjectTagViewSet(TestObjectTagMixin, APITestCase):
"""
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 @@ class TestObjectTagViewSet(TestObjectTagMixin, APITestCase):
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 @@ class TestCreateImportView(ImportTaxonomyMixin, APITestCase):
)
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()

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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