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

feat: adds endpoint for downloading the taxonomy templates [FC-0036] #33464

Merged
merged 1 commit into from
Oct 11, 2023
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 @@ -25,6 +25,7 @@
TAXONOMY_ORG_LIST_URL = "/api/content_tagging/v1/taxonomies/"
TAXONOMY_ORG_DETAIL_URL = "/api/content_tagging/v1/taxonomies/{pk}/"
OBJECT_TAG_UPDATE_URL = "/api/content_tagging/v1/object_tags/{object_id}/?taxonomy={taxonomy_id}"
TAXONOMY_TEMPLATE_URL = "/api/content_tagging/v1/taxonomies/import/{filename}"


def check_taxonomy(
Expand Down Expand Up @@ -844,3 +845,33 @@ def test_tag_unauthorized(self, objectid_attr):
response = self.client.put(url, {"tags": ["Tag 1"]}, format="json")

assert response.status_code == status.HTTP_403_FORBIDDEN


@skip_unless_cms
@ddt.ddt
class TestDownloadTemplateView(APITestCase):
"""
Tests the taxonomy template downloads.
"""
@ddt.data(
("template.csv", "text/csv"),
("template.json", "application/json"),
)
@ddt.unpack
def test_download(self, filename, content_type):
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):
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):
url = TAXONOMY_TEMPLATE_URL.format(filename="template.txt")
response = self.client.post(url)
assert response.status_code == status.HTTP_405_METHOD_NOT_ALLOWED
10 changes: 9 additions & 1 deletion openedx/core/djangoapps/content_tagging/rest_api/v1/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

from django.urls.conf import path, include

from openedx_tagging.core.tagging.rest_api.v1 import views as oel_tagging_views
from openedx_tagging.core.tagging.rest_api.v1 import (
views as oel_tagging_views,
views_import as oel_tagging_views_import,
)

from . import views

Expand All @@ -15,5 +18,10 @@
router.register("object_tags", oel_tagging_views.ObjectTagView, basename="object_tag")

urlpatterns = [
path(
"taxonomies/import/template.<str:file_ext>",
oel_tagging_views_import.TemplateView.as_view(),
name="taxonomy-import-template",
),
path('', include(router.urls))
]
Loading