feat: adds endpoint for downloading taxonomy templates (#33464)

This commit is contained in:
Jillian
2023-10-12 04:29:11 +10:30
committed by GitHub
parent 43f46079b3
commit ba5546e29d
2 changed files with 40 additions and 1 deletions

View File

@@ -25,6 +25,7 @@ User = get_user_model()
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(
@@ -844,3 +845,33 @@ class TestObjectTagViewSet(TestTaxonomyObjectsMixin, APITestCase):
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

View File

@@ -6,7 +6,10 @@ from rest_framework.routers import DefaultRouter
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
@@ -15,5 +18,10 @@ router.register("taxonomies", views.TaxonomyOrgView, basename="taxonomy")
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))
]