Skip to content

Commit

Permalink
feat: adds endpoint for downloading taxonomy templates (#33464)
Browse files Browse the repository at this point in the history
  • Loading branch information
pomegranited authored Oct 11, 2023
1 parent 43f4607 commit ba5546e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
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))
]

0 comments on commit ba5546e

Please sign in to comment.