Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump openedx-learning to support tagging with multiple taxonomies at once [FC-0036] #34490

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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),
Expand All @@ -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):
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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(
Expand All @@ -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):
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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(
Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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(
Expand All @@ -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

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

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

Expand All @@ -1725,20 +1714,17 @@ 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

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

Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion requirements/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading