-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
394 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,12 +39,15 @@ | |
from openedx.core.djangolib.testing.utils import skip_unless_cms | ||
from openedx.core.lib import blockstore_api | ||
|
||
from ....tests.test_api import TaggedCourseMixin | ||
|
||
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_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}" | ||
TAXONOMY_CREATE_IMPORT_URL = "/api/content_tagging/v1/taxonomies/import/" | ||
|
@@ -1624,6 +1627,63 @@ def test_object_tags_query_count(self): | |
assert response.data[object_id]["taxonomies"][0]["tags"] == expected_tags | ||
|
||
|
||
@skip_unless_cms | ||
@ddt.ddt | ||
class TestContentObjectChildrenExportView(TaggedCourseMixin, APITestCase): # type: ignore[misc] | ||
""" | ||
Tests exporting course children with tags | ||
""" | ||
def setUp(self): | ||
super().setUp() | ||
self.user = User.objects.create( | ||
username="user", | ||
email="[email protected]", | ||
) | ||
self.staff = User.objects.create( | ||
username="staff", | ||
email="[email protected]", | ||
is_staff=True, | ||
) | ||
|
||
self.staffA = User.objects.create( | ||
username="staffA", | ||
email="[email protected]", | ||
) | ||
update_org_role(self.staff, OrgStaffRole, self.staffA, [self.orgA.short_name]) | ||
|
||
@ddt.data( | ||
"staff", | ||
"staffA", | ||
) | ||
def test_export_course(self, user_attr) -> None: | ||
url = OBJECT_TAGS_EXPORT_URL.format(object_id=str(self.course.id)) | ||
|
||
user = getattr(self, user_attr) | ||
self.client.force_authenticate(user=user) | ||
response = self.client.get(url) | ||
assert response.status_code == status.HTTP_200_OK | ||
assert response.headers['Content-Type'] == 'text' | ||
assert int(response.headers['Content-Length']) > 0 | ||
assert response.content == self.expected_csv.encode("utf-8") | ||
|
||
def test_export_course_anoymous_unauthorized(self) -> None: | ||
url = OBJECT_TAGS_EXPORT_URL.format(object_id=str(self.course.id)) | ||
response = self.client.get(url) | ||
assert response.status_code == status.HTTP_401_UNAUTHORIZED | ||
|
||
def test_export_course_user_forbidden(self) -> None: | ||
url = OBJECT_TAGS_EXPORT_URL.format(object_id=str(self.course.id)) | ||
self.client.force_authenticate(user=self.user) | ||
response = self.client.get(url) | ||
assert response.status_code == status.HTTP_403_FORBIDDEN | ||
|
||
def test_export_course_invalid_id(self) -> None: | ||
url = OBJECT_TAGS_EXPORT_URL.format(object_id="invalid") | ||
self.client.force_authenticate(user=self.staff) | ||
response = self.client.get(url) | ||
assert response.status_code == status.HTTP_400_BAD_REQUEST | ||
|
||
|
||
@skip_unless_cms | ||
@ddt.ddt | ||
class TestDownloadTemplateView(APITestCase): | ||
|
@@ -1635,20 +1695,20 @@ class TestDownloadTemplateView(APITestCase): | |
("template.json", "application/json"), | ||
) | ||
@ddt.unpack | ||
def test_download(self, filename, content_type): | ||
def test_download(self, filename, content_type) -> None: | ||
url = TAXONOMY_TEMPLATE_URL.format(filename=filename) | ||
response = self.client.get(url) | ||
assert response.status_code == status.HTTP_200_OK | ||
assert response.headers['Content-Type'] == content_type | ||
assert response.headers['Content-Disposition'] == f'attachment; filename="{filename}"' | ||
assert int(response.headers['Content-Length']) > 0 | ||
|
||
def test_download_not_found(self): | ||
def test_download_not_found(self) -> None: | ||
url = TAXONOMY_TEMPLATE_URL.format(filename="template.txt") | ||
response = self.client.get(url) | ||
assert response.status_code == status.HTTP_404_NOT_FOUND | ||
|
||
def test_download_method_not_allowed(self): | ||
def test_download_method_not_allowed(self) -> None: | ||
url = TAXONOMY_TEMPLATE_URL.format(filename="template.txt") | ||
response = self.client.post(url) | ||
assert response.status_code == status.HTTP_405_METHOD_NOT_ALLOWED | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.