From 7b3c4945cf2e203c50b9a69afc15aa2e284b108c Mon Sep 17 00:00:00 2001 From: Julian Arni Date: Tue, 1 Oct 2013 10:51:25 -0400 Subject: [PATCH] Review fixes Studio: revises import help/status copy to better reflect/generalize what is done with imported content Add test cases for import status --- .../contentstore/tests/test_import_export.py | 32 +++++++++++++++++++ .../contentstore/views/import_export.py | 16 +++++----- cms/templates/import.html | 13 +++----- 3 files changed, 44 insertions(+), 17 deletions(-) diff --git a/cms/djangoapps/contentstore/tests/test_import_export.py b/cms/djangoapps/contentstore/tests/test_import_export.py index 267bdb15b1..4b8ba64533 100644 --- a/cms/djangoapps/contentstore/tests/test_import_export.py +++ b/cms/djangoapps/contentstore/tests/test_import_export.py @@ -6,11 +6,17 @@ import shutil import tarfile import tempfile import copy +<<<<<<< HEAD from path import path +======= +import json +import logging +>>>>>>> Review fixes from uuid import uuid4 from pymongo import MongoClient from .utils import CourseTestCase +from django.contrib.auth.models import User from django.core.urlresolvers import reverse from django.test.utils import override_settings from django.conf import settings @@ -20,6 +26,10 @@ from xmodule.contentstore.django import _CONTENTSTORE TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE) TEST_DATA_CONTENTSTORE['OPTIONS']['db'] = 'test_xcontent_%s' % uuid4().hex +<<<<<<< HEAD +======= +log = logging.getLogger(__name__) +>>>>>>> Review fixes @override_settings(CONTENTSTORE=TEST_DATA_CONTENTSTORE) class ImportTestCase(CourseTestCase): @@ -84,6 +94,17 @@ class ImportTestCase(CourseTestCase): "course-data": [btar] }) self.assertEquals(resp.status_code, 415) + # Check that `import_status` returns the appropriate stage (i.e., the + # stage at which import failed). + status_url = reverse("import_status", kwargs={ + 'org': self.course.location.org, + 'course': self.course.location.course, + 'name': os.path.split(self.bad_tar)[1], + }) + resp_status = self.client.get(status_url) + log.debug(str(self.client.session["import_status"])) + self.assertEquals(json.loads(resp_status.content)["ImportStatus"], 2) + def test_with_coursexml(self): """ @@ -183,3 +204,14 @@ class ImportTestCase(CourseTestCase): try_tar(self._symlink_tar()) try_tar(self._outside_tar()) try_tar(self._outside_tar2()) + # Check that `import_status` returns the appropriate stage (i.e., + # either 3, indicating all previous steps are completed, or 0, + # indicating no upload in progress) + status_url = reverse("import_status", kwargs={ + 'org': self.course.location.org, + 'course': self.course.location.course, + 'name': os.path.split(self.good_tar)[1], + }) + resp_status = self.client.get(status_url) + import_status = json.loads(resp_status.content)["ImportStatus"] + self.assertTrue(import_status == 3 or import_status == 0) diff --git a/cms/djangoapps/contentstore/views/import_export.py b/cms/djangoapps/contentstore/views/import_export.py index ce14942273..e69ba02ac5 100644 --- a/cms/djangoapps/contentstore/views/import_export.py +++ b/cms/djangoapps/contentstore/views/import_export.py @@ -9,7 +9,6 @@ import shutil import re from tempfile import mkdtemp from path import path -from contextlib import contextmanager from django.conf import settings from django.http import HttpResponse @@ -20,6 +19,7 @@ from django.core.servers.basehttp import FileWrapper from django.core.files.temp import NamedTemporaryFile from django.core.exceptions import SuspiciousOperation from django.views.decorators.http import require_http_methods, require_GET +from django.utils.translation import ugettext as _ from mitxmako.shortcuts import render_to_response from auth.authz import create_all_course_groups @@ -65,7 +65,7 @@ def import_course(request, org, course, name): if not filename.endswith('.tar.gz'): return JsonResponse( { - 'ErrMsg': 'We only support uploading a .tar.gz file.', + 'ErrMsg': _('We only support uploading a .tar.gz file.'), 'Stage': 1 }, status=415 @@ -102,7 +102,7 @@ def import_course(request, org, course, name): ) return JsonResponse( { - 'ErrMsg': 'File upload corrupted. Please try again', + 'ErrMsg': _('File upload corrupted. Please try again'), 'Stage': 1 }, status=409 @@ -163,8 +163,6 @@ def import_course(request, org, course, name): request.session.modified = True # find the 'course.xml' file - dirpath = None - def get_all_files(directory): """ For each file in the directory, yield a 2-tuple of (file-name, @@ -192,7 +190,7 @@ def import_course(request, org, course, name): if not dirpath: return JsonResponse( { - 'ErrMsg': 'Could not find the course.xml file in the package.', + 'ErrMsg': _('Could not find the course.xml file in the package.'), 'Stage': 2 }, status=415 @@ -223,7 +221,7 @@ def import_course(request, org, course, name): logging.debug('created all course groups at {0}'.format(course_items[0].location)) # Send errors to client with stage at which error occured. - except Exception as exception: #pylint: disable=W0703 + except Exception as exception: # pylint: disable=W0703 return JsonResponse( { 'ErrMsg': str(exception), @@ -248,6 +246,7 @@ def import_course(request, org, course, name): }) }) + @require_GET @ensure_csrf_cookie @login_required @@ -268,7 +267,7 @@ def import_status(request, org, course, name): except KeyError: status = 0 - return JsonResponse({"ImportStatus": status }) + return JsonResponse({"ImportStatus": status}) @ensure_csrf_cookie @@ -349,6 +348,7 @@ def generate_export_course(request, org, course, name): response['Content-Length'] = os.path.getsize(export_file.name) return response + @ensure_csrf_cookie @login_required def export_course(request, org, course, name): diff --git a/cms/templates/import.html b/cms/templates/import.html index 3714dbc2bd..c9d613fb2a 100644 --- a/cms/templates/import.html +++ b/cms/templates/import.html @@ -24,8 +24,8 @@

${_("You may import existing course structure and content into Studio.")}

-

${_("Importing is not something to take lightly as the course content you successfully upload will replace your current content and cannot be reversed. Please be certain you want to replace your course's content.")}

-

${_("During the import process, please do not navigate away from this page.")}

+

${_("Importing is not something to take lightly as the course content you successfully upload will be integrated into your course content and cannot be reversed.")}

+

${_("During the initial stages of the import process, please do not navigate away from this page.")}

${_("Updating Course")}

-

${_("Replacing previous course content with imported content. This may take a while with larger courses.")}

+

${_("Integrating your imported content into this course. This may take a while with larger courses.")}

  • @@ -109,7 +109,7 @@

    ${_("Success")}

    -

    ${_("Your imported content has now replaced all other course content")}

    +

    ${_("Your imported content has now been integrated into this course")}

      @@ -124,11 +124,6 @@