From 4c15dd93baddd13a542f8f7aaeda8f833ee3bc5f Mon Sep 17 00:00:00 2001 From: attiyaishaque Date: Wed, 13 Apr 2016 17:58:30 +0500 Subject: [PATCH] Course export page will not be opened for course id that does not belong to any course. --- cms/djangoapps/contentstore/views/import_export.py | 4 +++- .../contentstore/views/tests/test_import_export.py | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cms/djangoapps/contentstore/views/import_export.py b/cms/djangoapps/contentstore/views/import_export.py index 930a16d5a4..610279baff 100644 --- a/cms/djangoapps/contentstore/views/import_export.py +++ b/cms/djangoapps/contentstore/views/import_export.py @@ -16,7 +16,7 @@ from django.contrib.auth.decorators import login_required from django.core.exceptions import SuspiciousOperation, PermissionDenied from django.core.files.temp import NamedTemporaryFile from django.core.servers.basehttp import FileWrapper -from django.http import HttpResponse, HttpResponseNotFound +from django.http import HttpResponse, HttpResponseNotFound, Http404 from django.utils.translation import ugettext as _ from django.views.decorators.csrf import ensure_csrf_cookie from django.views.decorators.http import require_http_methods, require_GET @@ -489,6 +489,8 @@ def export_handler(request, course_key_string): } else: courselike_module = modulestore().get_course(course_key) + if courselike_module is None: + raise Http404 context = { 'context_course': courselike_module, 'courselike_home_url': reverse_course_url("course_handler", course_key), diff --git a/cms/djangoapps/contentstore/views/tests/test_import_export.py b/cms/djangoapps/contentstore/views/tests/test_import_export.py index f934efba62..34d0225bb1 100644 --- a/cms/djangoapps/contentstore/views/tests/test_import_export.py +++ b/cms/djangoapps/contentstore/views/tests/test_import_export.py @@ -510,6 +510,7 @@ class ImportTestCase(CourseTestCase): @override_settings(CONTENTSTORE=TEST_DATA_CONTENTSTORE) +@ddt.ddt class ExportTestCase(CourseTestCase): """ Tests for export_handler. @@ -630,6 +631,17 @@ class ExportTestCase(CourseTestCase): self.test_export_targz_urlparam() + @ddt.data( + '/export/non.1/existence_1/Run_1', # For mongo + '/export/course-v1:non1+existence1+Run1', # For split + ) + def test_export_course_doest_not_exist(self, url): + """ + Export failure if course is not exist + """ + resp = self.client.get_html(url) + self.assertEquals(resp.status_code, 404) + @override_settings(CONTENTSTORE=TEST_DATA_CONTENTSTORE) class TestLibraryImportExport(CourseTestCase):