Commit 54d9bbd8 by Jeremy Bowman Committed by GitHub

Merge pull request #14635 from edx/jmbowman/async_course_export_2

PLAT-1121 Export courses asynchronously
parents d40e8c05 8d36c382
......@@ -17,7 +17,7 @@ class ImportExportS3Storage(S3BotoStorage): # pylint: disable=abstract-method
def __init__(self):
bucket = setting('COURSE_IMPORT_EXPORT_BUCKET', settings.AWS_STORAGE_BUCKET_NAME)
super(ImportExportS3Storage, self).__init__(bucket=bucket, querystring_auth=True)
super(ImportExportS3Storage, self).__init__(bucket=bucket, custom_domain=None, querystring_auth=True)
# pylint: disable=invalid-name
course_import_export_storage = get_storage_class(settings.COURSE_IMPORT_EXPORT_STORAGE)()
......@@ -5,11 +5,11 @@ from __future__ import absolute_import
import base64
import json
import logging
import os
import shutil
import tarfile
from datetime import datetime
from tempfile import NamedTemporaryFile, mkdtemp
from celery.task import task
from celery.utils.log import get_task_logger
......@@ -20,17 +20,19 @@ from six import iteritems, text_type
from django.conf import settings
from django.contrib.auth.models import User
from django.core.exceptions import SuspiciousOperation
from django.core.files import File
from django.test import RequestFactory
from django.utils.text import get_valid_filename
from django.utils.translation import ugettext as _
from djcelery.common import respect_language
from user_tasks.models import UserTaskArtifact, UserTaskStatus
from user_tasks.tasks import UserTask
import dogstats_wrapper as dog_stats_api
from contentstore.courseware_index import CoursewareSearchIndexer, LibrarySearchIndexer, SearchIndexingError
from contentstore.storage import course_import_export_storage
from contentstore.utils import initialize_permissions
from contentstore.utils import initialize_permissions, reverse_usage_url
from course_action_state.models import CourseRerunState
from models.settings.course_metadata import CourseMetadata
from opaque_keys.edx.keys import CourseKey
......@@ -39,9 +41,11 @@ from openedx.core.lib.extract_tar import safetar_extractall
from student.auth import has_course_author_access
from xmodule.contentstore.django import contentstore
from xmodule.course_module import CourseFields
from xmodule.exceptions import SerializationError
from xmodule.modulestore import COURSE_ROOT, LIBRARY_ROOT
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.exceptions import DuplicateCourseError, ItemNotFoundError
from xmodule.modulestore.xml_exporter import export_course_to_xml, export_library_to_xml
from xmodule.modulestore.xml_importer import import_course_from_xml, import_library_from_xml
......@@ -155,6 +159,136 @@ def push_course_update_task(course_key_string, course_subscription_id, course_di
send_push_course_update(course_key_string, course_subscription_id, course_display_name)
class CourseExportTask(UserTask): # pylint: disable=abstract-method
"""
Base class for course and library export tasks.
"""
@staticmethod
def calculate_total_steps(arguments_dict):
"""
Get the number of in-progress steps in the export process, as shown in the UI.
For reference, these are:
1. Exporting
2. Compressing
"""
return 2
@classmethod
def generate_name(cls, arguments_dict):
"""
Create a name for this particular import task instance.
Arguments:
arguments_dict (dict): The arguments given to the task function
Returns:
text_type: The generated name
"""
key = arguments_dict[u'course_key_string']
return u'Export of {}'.format(key)
@task(base=CourseExportTask, bind=True)
def export_olx(self, user_id, course_key_string, language):
"""
Export a course or library to an OLX .tar.gz archive and prepare it for download.
"""
courselike_key = CourseKey.from_string(course_key_string)
try:
user = User.objects.get(pk=user_id)
except User.DoesNotExist:
with respect_language(language):
self.status.fail(_(u'Unknown User ID: {0}').format(user_id))
return
if not has_course_author_access(user, courselike_key):
with respect_language(language):
self.status.fail(_(u'Permission denied'))
return
if isinstance(courselike_key, LibraryLocator):
courselike_module = modulestore().get_library(courselike_key)
else:
courselike_module = modulestore().get_course(courselike_key)
try:
self.status.set_state(u'Exporting')
tarball = create_export_tarball(courselike_module, courselike_key, {}, self.status)
artifact = UserTaskArtifact(status=self.status, name=u'Output')
artifact.file.save(name=tarball.name, content=File(tarball)) # pylint: disable=no-member
artifact.save()
# catch all exceptions so we can record useful error messages
except Exception as exception: # pylint: disable=broad-except
LOGGER.exception(u'Error exporting course %s', courselike_key)
if self.status.state != UserTaskStatus.FAILED:
self.status.fail({'raw_error_msg': text_type(exception)})
return
def create_export_tarball(course_module, course_key, context, status=None):
"""
Generates the export tarball, or returns None if there was an error.
Updates the context with any error information if applicable.
"""
name = course_module.url_name
export_file = NamedTemporaryFile(prefix=name + '.', suffix=".tar.gz")
root_dir = path(mkdtemp())
try:
if isinstance(course_key, LibraryLocator):
export_library_to_xml(modulestore(), contentstore(), course_key, root_dir, name)
else:
export_course_to_xml(modulestore(), contentstore(), course_module.id, root_dir, name)
if status:
status.set_state(u'Compressing')
status.increment_completed_steps()
LOGGER.debug(u'tar file being generated at %s', export_file.name)
with tarfile.open(name=export_file.name, mode='w:gz') as tar_file:
tar_file.add(root_dir / name, arcname=name)
except SerializationError as exc:
LOGGER.exception(u'There was an error exporting %s', course_key)
parent = None
try:
failed_item = modulestore().get_item(exc.location)
parent_loc = modulestore().get_parent_location(failed_item.location)
if parent_loc is not None:
parent = modulestore().get_item(parent_loc)
except: # pylint: disable=bare-except
# if we have a nested exception, then we'll show the more generic error message
pass
context.update({
'in_err': True,
'raw_err_msg': str(exc),
'edit_unit_url': reverse_usage_url("container_handler", parent.location) if parent else "",
})
if status:
status.fail(json.dumps({'raw_error_msg': context['raw_err_msg'],
'edit_unit_url': context['edit_unit_url']}))
raise
except Exception as exc:
LOGGER.exception('There was an error exporting %s', course_key)
context.update({
'in_err': True,
'edit_unit_url': None,
'raw_err_msg': str(exc)})
if status:
status.fail(json.dumps({'raw_error_msg': context['raw_err_msg']}))
raise
finally:
if os.path.exists(root_dir / name):
shutil.rmtree(root_dir / name)
return export_file
class CourseImportTask(UserTask): # pylint: disable=abstract-method
"""
Base class for course and library import tasks.
......
"""
Unit tests for course import and export Celery tasks
"""
from __future__ import absolute_import, division, print_function
import copy
import json
import mock
from uuid import uuid4
from django.conf import settings
from django.contrib.auth.models import User
from django.test.utils import override_settings
from user_tasks.models import UserTaskArtifact, UserTaskStatus
from contentstore.tasks import export_olx
from contentstore.tests.test_libraries import LibraryTestCase
from contentstore.tests.utils import CourseTestCase
TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE)
TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex
def side_effect_exception(*args, **kwargs): # pylint: disable=unused-argument
"""
Side effect for mocking which raises an exception
"""
raise Exception('Boom!')
@override_settings(CONTENTSTORE=TEST_DATA_CONTENTSTORE)
class ExportCourseTestCase(CourseTestCase):
"""
Tests of the export_olx task applied to courses
"""
def test_success(self):
"""
Verify that a routine course export task succeeds
"""
key = str(self.course.location.course_key)
result = export_olx.delay(self.user.id, key, u'en')
status = UserTaskStatus.objects.get(task_id=result.id)
self.assertEqual(status.state, UserTaskStatus.SUCCEEDED)
artifacts = UserTaskArtifact.objects.filter(status=status)
self.assertEqual(len(artifacts), 1)
output = artifacts[0]
self.assertEqual(output.name, 'Output')
@mock.patch('contentstore.tasks.export_course_to_xml', side_effect=side_effect_exception)
def test_exception(self, mock_export): # pylint: disable=unused-argument
"""
The export task should fail gracefully if an exception is thrown
"""
key = str(self.course.location.course_key)
result = export_olx.delay(self.user.id, key, u'en')
self._assert_failed(result, json.dumps({u'raw_error_msg': u'Boom!'}))
def test_invalid_user_id(self):
"""
Verify that attempts to export a course as an invalid user fail
"""
user_id = User.objects.order_by(u'-id').first().pk + 100
key = str(self.course.location.course_key)
result = export_olx.delay(user_id, key, u'en')
self._assert_failed(result, u'Unknown User ID: {}'.format(user_id))
def test_non_course_author(self):
"""
Verify that users who aren't authors of the course are unable to export it
"""
_, nonstaff_user = self.create_non_staff_authed_user_client()
key = str(self.course.location.course_key)
result = export_olx.delay(nonstaff_user.id, key, u'en')
self._assert_failed(result, u'Permission denied')
def _assert_failed(self, task_result, error_message):
"""
Verify that a task failed with the specified error message
"""
status = UserTaskStatus.objects.get(task_id=task_result.id)
self.assertEqual(status.state, UserTaskStatus.FAILED)
artifacts = UserTaskArtifact.objects.filter(status=status)
self.assertEqual(len(artifacts), 1)
error = artifacts[0]
self.assertEqual(error.name, u'Error')
self.assertEqual(error.text, error_message)
@override_settings(CONTENTSTORE=TEST_DATA_CONTENTSTORE)
class ExportLibraryTestCase(LibraryTestCase):
"""
Tests of the export_olx task applied to libraries
"""
def test_success(self):
"""
Verify that a routine library export task succeeds
"""
key = str(self.lib_key)
result = export_olx.delay(self.user.id, key, u'en') # pylint: disable=no-member
status = UserTaskStatus.objects.get(task_id=result.id)
self.assertEqual(status.state, UserTaskStatus.SUCCEEDED)
artifacts = UserTaskArtifact.objects.filter(status=status)
self.assertEqual(len(artifacts), 1)
output = artifacts[0]
self.assertEqual(output.name, 'Output')
......@@ -531,6 +531,7 @@ class ExportTestCase(CourseTestCase):
"""
super(ExportTestCase, self).setUp()
self.url = reverse_course_url('export_handler', self.course.id)
self.status_url = reverse_course_url('export_status_handler', self.course.id)
def test_export_html(self):
"""
......@@ -547,6 +548,21 @@ class ExportTestCase(CourseTestCase):
resp = self.client.get(self.url, HTTP_ACCEPT='application/json')
self.assertEquals(resp.status_code, 406)
def test_export_async(self):
"""
Get tar.gz file, using asynchronous background task
"""
resp = self.client.post(self.url)
self.assertEquals(resp.status_code, 200)
resp = self.client.get(self.status_url)
result = json.loads(resp.content)
status = result['ExportStatus']
self.assertEquals(status, 3)
self.assertIn('ExportOutput', result)
output_url = result['ExportOutput']
resp = self.client.get(output_url)
self._verify_export_succeeded(resp)
def test_export_targz(self):
"""
Get tar.gz file, using HTTP_ACCEPT.
......@@ -588,11 +604,16 @@ class ExportTestCase(CourseTestCase):
def _verify_export_failure(self, expected_text):
""" Export failure helper method. """
resp = self.client.get(self.url, HTTP_ACCEPT='application/x-tgz')
resp = self.client.post(self.url)
self.assertEquals(resp.status_code, 200)
resp = self.client.get(self.status_url)
self.assertEquals(resp.status_code, 200)
self.assertIsNone(resp.get('Content-Disposition'))
self.assertContains(resp, 'Unable to create xml for module')
self.assertContains(resp, expected_text)
result = json.loads(resp.content)
self.assertNotIn('ExportOutput', result)
self.assertIn('ExportError', result)
error = result['ExportError']
self.assertIn('Unable to create xml for module', error['raw_error_msg'])
self.assertIn(expected_text, error['edit_unit_url'])
def test_library_export(self):
"""
......@@ -639,19 +660,53 @@ class ExportTestCase(CourseTestCase):
data=xml_string
)
self.test_export_targz_urlparam()
self.test_export_async()
@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):
def test_export_course_does_not_exist(self, url):
"""
Export failure if course is not exist
Export failure if course does not exist
"""
resp = self.client.get_html(url)
self.assertEquals(resp.status_code, 404)
def test_non_course_author(self):
"""
Verify that users who aren't authors of the course are unable to export it
"""
client, _ = self.create_non_staff_authed_user_client()
resp = client.get(self.url)
self.assertEqual(resp.status_code, 403)
def test_status_non_course_author(self):
"""
Verify that users who aren't authors of the course are unable to see the status of export tasks
"""
client, _ = self.create_non_staff_authed_user_client()
resp = client.get(self.status_url)
self.assertEqual(resp.status_code, 403)
def test_status_missing_record(self):
"""
Attempting to get the status of an export task which isn't currently
represented in the database should yield a useful result
"""
resp = self.client.get(self.status_url)
self.assertEqual(resp.status_code, 200)
result = json.loads(resp.content)
self.assertEqual(result['ExportStatus'], 0)
def test_output_non_course_author(self):
"""
Verify that users who aren't authors of the course are unable to see the output of export tasks
"""
client, _ = self.create_non_staff_authed_user_client()
resp = client.get(reverse_course_url('export_output_handler', self.course.id))
self.assertEqual(resp.status_code, 403)
@override_settings(CONTENTSTORE=TEST_DATA_CONTENTSTORE)
class TestLibraryImportExport(CourseTestCase):
......
define(['gettext', 'common/js/components/views/feedback_prompt'], function(gettext, PromptView) {
define([
'domReady', 'js/views/export', 'jquery', 'gettext'
], function(domReady, Export, $, gettext) {
'use strict';
return function(hasUnit, editUnitUrl, courselikeHomeUrl, library, errMsg) {
var dialog;
if (hasUnit) {
dialog = new PromptView({
title: gettext('There has been an error while exporting.'),
message: gettext('There has been a failure to export to XML at least one component. It is recommended that you go to the edit page and repair the error before attempting another export. Please check that all components on the page are valid and do not display any error messages.'),
intent: 'error',
actions: {
primary: {
text: gettext('Correct failed component'),
click: function(view) {
view.hide();
document.location = editUnitUrl;
}
},
secondary: {
text: gettext('Return to Export'),
click: function(view) {
view.hide();
return function(courselikeHomeUrl, library, statusUrl) {
var $submitBtn = $('.action-export'),
unloading = false,
previousExport = Export.storedExport(courselikeHomeUrl);
var onComplete = function() {
$submitBtn.show();
};
var startExport = function(e) {
e.preventDefault();
$submitBtn.hide();
Export.reset(library);
Export.start(statusUrl).then(onComplete);
$.ajax({
type: 'POST',
url: window.location.pathname,
data: {},
success: function(result, textStatus, xhr) {
if (xhr.status === 200) {
setTimeout(function() { Export.pollStatus(result); }, 1000);
} else {
// It could be that the user is simply refreshing the page
// so we need to be sure this is an actual error from the server
if (!unloading) {
$(window).off('beforeunload.import');
Export.reset(library);
onComplete();
Export.showError(gettext('Your export has failed.'));
}
}
}
});
} else {
var msg = '<p>';
var action;
if (library) {
msg += gettext('Your library could not be exported to XML. There is not enough information to identify the failed component. Inspect your library to identify any problematic components and try again.');
action = gettext('Take me to the main library page');
} else {
msg += gettext('Your course could not be exported to XML. There is not enough information to identify the failed component. Inspect your course to identify any problematic components and try again.');
action = gettext('Take me to the main course page');
};
$(window).on('beforeunload', function() { unloading = true; });
// Display the status of last file upload on page load
if (previousExport) {
if (previousExport.completed !== true) {
$submitBtn.hide();
}
msg += '</p><p>' + gettext('The raw error message is:') + '</p>' + errMsg;
dialog = new PromptView({
title: gettext('There has been an error with your export.'),
message: msg,
intent: 'error',
actions: {
primary: {
text: action,
click: function(view) {
view.hide();
document.location = courselikeHomeUrl;
}
},
secondary: {
text: gettext('Cancel'),
click: function(view) {
view.hide();
}
}
}
});
Export.resume(library).then(onComplete);
}
// The CSS animation for the dialog relies on the 'js' class
// being on the body. This happens after this JavaScript is executed,
// causing a 'bouncing' of the dialog after it is initially shown.
// As a workaround, add this class first.
$('body').addClass('js');
dialog.show();
domReady(function() {
// export form setup
$submitBtn.bind('click', startExport);
});
};
});
......@@ -29,7 +29,7 @@ define([
var onComplete = function() {
bar.hide();
chooseBtn
.find('.copy').html(gettext('Choose new file')).end()
.find('.copy').text(gettext('Choose new file')).end()
.show();
};
......@@ -38,7 +38,9 @@ define([
// Display the status of last file upload on page load
if (previousImport) {
$('.file-name-block')
.find('.file-name').html(previousImport.file.name).end()
.find('.file-name')
.text(previousImport.file.name)
.end()
.show();
if (previousImport.completed !== true) {
......@@ -123,7 +125,7 @@ define([
setTimeout(function() { Import.pollStatus(); }, 3000);
} else {
bar.show();
fill.width(percentVal).html(percentVal);
fill.width(percentVal).text(percentVal);
}
},
sequentialUploads: true,
......@@ -136,7 +138,7 @@ define([
if (filepath.substr(filepath.length - 6, 6) === 'tar.gz') {
$('.error-block').hide();
$('.file-name').html($(this).val().replace('C:\\fakepath\\', ''));
$('.file-name').text($(this).val().replace('C:\\fakepath\\', ''));
$('.file-name-block').show();
chooseBtn.hide();
submitBtn.show();
......@@ -145,7 +147,7 @@ define([
var msg = gettext('File format not supported. Please upload a file with a {file_extension} extension.')
.replace('{file_extension}', '<code>tar.gz</code>');
$('.error-block').html(msg).show();
$('.error-block').text(msg).show();
}
};
......
......@@ -2,8 +2,8 @@
* Course import-related js.
*/
define(
['jquery', 'underscore', 'gettext', 'moment', 'jquery.cookie'],
function($, _, gettext, moment) {
['jquery', 'underscore', 'gettext', 'moment', 'edx-ui-toolkit/js/utils/html-utils', 'jquery.cookie'],
function($, _, gettext, moment, HtmlUtils) {
'use strict';
/** ******** Private properties ****************************************/
......@@ -127,10 +127,10 @@ define(
*/
var updateFeedbackList = function(currStageMsg) {
var $checkmark, $curr, $prev, $next;
var date, successUnix, time;
var date, stageMsg, successUnix, time;
$checkmark = $dom.successStage.find('.icon');
currStageMsg = currStageMsg || '';
stageMsg = currStageMsg || '';
function completeStage(stage) {
$(stage)
......@@ -140,12 +140,17 @@ define(
function errorStage(stage) {
if (!$(stage).hasClass('has-error')) {
stageMsg = HtmlUtils.joinHtml(
HtmlUtils.HTML('<p class="copy error">'),
stageMsg,
HtmlUtils.HTML('</p>')
);
$(stage)
.removeClass('is-started')
.addClass('has-error')
.find('p.copy')
.hide()
.after("<p class='copy error'>" + currStageMsg + '</p>');
.after(HtmlUtils.ensureHtml(stageMsg).toString());
}
}
......@@ -181,7 +186,7 @@ define(
$dom.successStage
.find('.item-progresspoint-success-date')
.html('(' + date + ' at ' + time + ' UTC)');
.text('(' + date + ' at ' + time + ' UTC)');
break;
......
......@@ -86,98 +86,183 @@
}
}
// OLD
.description {
@extend %t-copy-sub1;
float: left;
width: 62%;
margin-right: 3%;
h2 {
@extend %t-title5;
@extend %t-strong;
margin-bottom: $baseline;
}
// ====================
strong {
@extend %t-strong;
// UI: upload progress
.wrapper-status {
@include transition(opacity $tmg-f2 ease-in-out 0);
opacity: 1.0;
// STATE: hidden
&.is-hidden {
opacity: 0.0;
display: none;
}
p + p {
margin-top: $baseline;
> .title {
@extend %t-title4;
margin-bottom: $baseline;
border-bottom: 1px solid $gray-l3;
padding-bottom: ($baseline/2);
}
// elem - progress list
.list-progress {
width: flex-grid(9, 9);
.status-visual {
position: relative;
float: left;
width: flex-grid(1,9);
.icon {
@include transition(opacity $tmg-f1 ease-in-out 0);
@extend %t-icon4;
position: absolute;
top: ($baseline/2);
left: $baseline;
}
}
.status-detail {
float: left;
width: flex-grid(8,9);
margin-left: ($baseline*3);
ul {
margin: 20px 0;
list-style: disc inside;
.title {
@extend %t-title5;
@extend %t-strong;
}
li {
margin: 0 0 5px 0;
.copy {
@extend %t-copy-base;
color: $gray-l2;
}
}
}
}
.export-form-wrapper {
.item-progresspoint {
@include clearfix();
@include transition(opacity $tmg-f1 ease-in-out 0);
margin-bottom: $baseline;
border-bottom: 1px solid $gray-l4;
padding-bottom: $baseline;
.export-form {
float: left;
width: 35%;
padding: 25px 30px 35px;
@include box-sizing(border-box);
border: 1px solid $mediumGrey;
border-radius: 3px;
background: $lightGrey;
text-align: center;
h2 {
@extend %t-title4;
@extend %t-light;
margin-bottom: ($baseline*1.5);
}
&:last-child {
margin-bottom: 0;
border-bottom: none;
padding-bottom: 0;
}
.error-block {
@extend %t-copy-sub1;
display: none;
margin-bottom: ($baseline*0.75);
}
// CASE: has actions
&.has-actions {
.error-block {
color: $error-red;
}
.list-actions {
display: none;
.button-export {
@include green-button();
@extend %t-action1;
padding: 10px 50px 11px;
}
.action-primary {
@extend %btn-primary-blue;
}
}
}
.message-status {
@extend %t-copy-sub2;
margin-top: ($baseline/2);
}
// TYPE: success
&.item-progresspoint-success {
.progress-bar {
display: none;
width: 350px;
height: 30px;
margin: 30px auto 10px;
border: 1px solid $blue;
.item-progresspoint-success-date {
@include margin-left($baseline/4);
display: none;
}
&.loaded {
border-color: #66b93d;
&.is-complete {
.progress-fill {
background: #66b93d;
.item-progresspoint-success-date {
display: inline;
}
}
}
}
.progress-fill {
width: 0%;
height: 30px;
background: $blue;
color: $white;
line-height: 48px;
// STATE: not started
&.is-not-started {
opacity: 0.5;
.fa-warning {
visibility: hidden;
opacity: 0.0;
}
.fa-cog {
visibility: visible;
opacity: 1.0;
}
.fa-check {
opacity: 0.3;
}
}
// STATE: started
&.is-started {
.fa-warning {
visibility: hidden;
opacity: 0.0;
}
.fa-cog {
@include animation(fa-spin 2s infinite linear);
visibility: visible;
opacity: 1.0;
}
}
// STATE: completed
&.is-complete {
.fa-cog {
visibility: visible;
opacity: 1.0;
}
.fa-warning {
visibility: hidden;
opacity: 0.0;
}
.icon {
color: $green;
}
.status-detail .title {
color: $green;
}
.list-actions {
display: block;
}
}
// STATE: error
&.has-error {
.fa-cog {
visibility: hidden;
opacity: 0.0;
}
.fa-warning {
visibility: visible;
opacity: 1.0;
}
.icon {
color: $red;
}
.status-detail .title, .status-detail .copy {
color: $red;
}
}
}
}
}
......
......@@ -27,17 +27,13 @@ else:
<%block name="bodyclass">is-signedin course tools view-export</%block>
<%block name="requirejs">
% if in_err:
var hasUnit = ${bool(unit) | n, dump_js_escaped_json},
editUnitUrl = "${edit_unit_url | n, js_escaped_string}",
courselikeHomeUrl = "${courselike_home_url | n, js_escaped_string}",
is_library = ${library | n, dump_js_escaped_json}
errMsg = "${raw_err_msg | n, js_escaped_string}";
var courselikeHomeUrl = "${courselike_home_url | n, js_escaped_string}",
is_library = ${library | n, dump_js_escaped_json},
statusUrl = "${status_url | n, js_escaped_string}";
require(["js/factories/export"], function(ExportFactory) {
ExportFactory(hasUnit, editUnitUrl, courselikeHomeUrl, is_library, errMsg);
ExportFactory(courselikeHomeUrl, is_library, statusUrl);
});
%endif
</%block>
<%block name="content">
......@@ -93,7 +89,7 @@ else:
<ul class="list-actions">
<li class="item-action">
<a class="action action-export action-primary" href="${export_url}">
<a class="action action-export action-primary" href="#">
<span class="icon fa fa-arrow-circle-o-down" aria-hidden="true"></span>
<span class="copy">
%if library:
......@@ -105,6 +101,90 @@ else:
</li>
</ul>
</div>
<div class="wrapper wrapper-status is-hidden">
<h3 class="title">
%if library:
${_("Library Export Status")}
%else:
${_("Course Export Status")}
%endif
</h3>
<ol class="status-progress list-progress">
<li class="item-progresspoint item-progresspoint-prepare is-complete">
<span class="deco status-visual">
<span class="icon fa fa-cog" aria-hidden="true"></span>
<span class="icon fa fa-warning" aria-hidden="true"></span>
</span>
<div class="status-detail">
<h3 class="title">${_("Preparing")}</h3>
<div class="progress-bar">
<div class="progress-fill"></div>
</div>
<p class="copy">${_("Preparing to start the export")}</p>
</div>
</li>
<li class="item-progresspoint item-progresspoint-export is-started">
<span class="deco status-visual">
<span class="icon fa fa-cog" aria-hidden="true"></span>
<span class="icon fa fa-warning" aria-hidden="true"></span>
</span>
<div class="status-detail">
<h3 class="title">${_("Exporting")}</h3>
<p class="copy">${_("Creating the export data files (You can now leave this page safely, but avoid making drastic changes to content until this export is complete)")}</p>
</div>
</li>
<li class="item-progresspoint item-progresspoint-compress is-not-started">
<span class="deco status-visual">
<span class="icon fa fa-cog" aria-hidden="true"></span>
<span class="icon fa fa-warning" aria-hidden="true"></span>
</span>
<div class="status-detail">
<h3 class="title">${_("Compressing")}</h3>
<p class="copy">${_("Compressing the exported data and preparing it for download")}</p>
</div>
</li>
<li class="item-progresspoint item-progresspoint-success has-actions is-not-started">
<span class="deco status-visual">
<span class="icon fa fa-square-o" aria-hidden="true"></span>
</span>
<div class="status-detail">
<h3 class="title">
${_("Success")}
<span class="item-progresspoint-success-date"></span>
</h3>
<p class="copy">
%if library:
${_("Your exported library can now be downloaded")}
%else:
${_("Your exported course can now be downloaded")}
%endif
</p>
<ul class="list-actions">
<li class="item-action">
<a href="#" id="download-exported-button" class="action action-primary">
%if library:
${_("Download Exported Library")}
%else:
${_("Download Exported Course")}
%endif
</a>
</li>
</ul>
</div>
</li>
</ol>
</div>
%if not library:
<div class="export-contents">
<div class="export-includes">
......
<%page expression_filter="h"/>
<%inherit file="base.html" />
<%def name="online_help_token()">
<%
......@@ -13,6 +14,7 @@ else:
from openedx.core.djangolib.js_utils import (
dump_js_escaped_json, js_escaped_string
)
from openedx.core.djangolib.markup import HTML, Text
%>
<%block name="title">
%if library:
......@@ -44,11 +46,11 @@ else:
<div class="introduction">
## Translators: ".tar.gz" is a file extension, and files with that extension are called "gzipped tar files": these terms should not be translated
%if library:
<p>${_("Be sure you want to import a library before continuing. The contents of the imported library will replace the contents of the existing library. {em_start}You cannot undo a library import{em_end}. Before you proceed, we recommend that you export the current library, so that you have a backup copy of it.").format(em_start='<strong>', em_end="</strong>")}</p>
<p>${Text(_("Be sure you want to import a library before continuing. The contents of the imported library will replace the contents of the existing library. {em_start}You cannot undo a library import{em_end}. Before you proceed, we recommend that you export the current library, so that you have a backup copy of it.")).format(em_start=HTML('<strong>'), em_end=HTML("</strong>"))}</p>
<p>${_("The library that you import must be in a .tar.gz file (that is, a .tar file compressed with GNU Zip). This .tar.gz file must contain a library.xml file. It may also contain other files.")}</p>
<p>${_("The import process has five stages. During the first two stages, you must stay on this page. You can leave this page after the Unpacking stage has completed. We recommend, however, that you don't make important changes to your library until the import operation has completed.")}</p>
%else:
<p>${_("Be sure you want to import a course before continuing. The contents of the imported course will replace the contents of the existing course. {em_start}You cannot undo a course import{em_end}. Before you proceed, we recommend that you export the current course, so that you have a backup copy of it.").format(em_start='<strong>', em_end="</strong>")}</p>
<p>${Text(_("Be sure you want to import a course before continuing. The contents of the imported course will replace the contents of the existing course. {em_start}You cannot undo a course import{em_end}. Before you proceed, we recommend that you export the current course, so that you have a backup copy of it.")).format(em_start=HTML('<strong>'), em_end=HTML("</strong>"))}</p>
<p>${_("The course that you import must be in a .tar.gz file (that is, a .tar file compressed with GNU Zip). This .tar.gz file must contain a course.xml file. It may also contain other files.")}</p>
<p>${_("The import process has five stages. During the first two stages, you must stay on this page. You can leave this page after the Unpacking stage has completed. We recommend, however, that you don't make important changes to your course until the import operation has completed.")}</p>
%endif
......
......@@ -96,6 +96,8 @@ urlpatterns += patterns(
url(r'^import/{}$'.format(COURSELIKE_KEY_PATTERN), 'import_handler'),
url(r'^import_status/{}/(?P<filename>.+)$'.format(COURSELIKE_KEY_PATTERN), 'import_status_handler'),
url(r'^export/{}$'.format(COURSELIKE_KEY_PATTERN), 'export_handler'),
url(r'^export_output/{}$'.format(COURSELIKE_KEY_PATTERN), 'export_output_handler'),
url(r'^export_status/{}$'.format(COURSELIKE_KEY_PATTERN), 'export_status_handler'),
url(r'^xblock/outline/{}$'.format(settings.USAGE_KEY_PATTERN), 'xblock_outline_handler'),
url(r'^xblock/container/{}$'.format(settings.USAGE_KEY_PATTERN), 'xblock_container_handler'),
url(r'^xblock/{}/(?P<view_name>[^/]+)$'.format(settings.USAGE_KEY_PATTERN), 'xblock_view_handler'),
......
......@@ -4,8 +4,6 @@ Acceptance tests for the Import and Export pages
from nose.plugins.attrib import attr
from datetime import datetime
from flaky import flaky
from abc import abstractmethod
from common.test.acceptance.tests.studio.base_studio_test import StudioLibraryTest, StudioCourseTest
......@@ -32,10 +30,70 @@ class ExportTestMixin(object):
The download will succeed
And the file will be of the right MIME type.
"""
self.export_page.wait_for_export_click_handler()
self.export_page.click_export()
self.export_page.wait_for_export()
good_status, is_tarball_mimetype = self.export_page.download_tarball()
self.assertTrue(good_status)
self.assertTrue(is_tarball_mimetype)
def test_export_timestamp(self):
"""
Scenario: I perform a course / library export
On export success, the page displays a UTC timestamp previously not visible
And if I refresh the page, the timestamp is still displayed
"""
self.assertFalse(self.export_page.is_timestamp_visible())
# Get the time when the export has started.
# export_page timestamp is in (MM/DD/YYYY at HH:mm) so replacing (second, microsecond) to
# keep the comparison consistent
export_start_time = datetime.utcnow().replace(microsecond=0, second=0)
self.export_page.wait_for_export_click_handler()
self.export_page.click_export()
self.export_page.wait_for_export()
# Get the time when the export has finished.
# export_page timestamp is in (MM/DD/YYYY at HH:mm) so replacing (second, microsecond) to
# keep the comparison consistent
export_finish_time = datetime.utcnow().replace(microsecond=0, second=0)
export_timestamp = self.export_page.parsed_timestamp
self.export_page.wait_for_timestamp_visible()
# Verify that 'export_timestamp' is between start and finish upload time
self.assertLessEqual(
export_start_time,
export_timestamp,
"Course export timestamp should be export_start_time <= export_timestamp <= export_end_time"
)
self.assertGreaterEqual(
export_finish_time,
export_timestamp,
"Course export timestamp should be export_start_time <= export_timestamp <= export_end_time"
)
self.export_page.visit()
self.export_page.wait_for_tasks(completed=True)
self.export_page.wait_for_timestamp_visible()
def test_task_list(self):
"""
Scenario: I should see feedback checkpoints when exporting a course or library
Given that I am on an export page
No task checkpoint list should be showing
When I export the course or library
Each task in the checklist should be marked confirmed
And the task list should be visible
"""
# The task list shouldn't be visible to start.
self.assertFalse(self.export_page.is_task_list_showing(), "Task list shown too early.")
self.export_page.wait_for_tasks()
self.export_page.wait_for_export_click_handler()
self.export_page.click_export()
self.export_page.wait_for_tasks(completed=True)
self.assertTrue(self.export_page.is_task_list_showing(), "Task list did not display.")
@attr(shard=7)
class TestCourseExport(ExportTestMixin, StudioCourseTest):
......@@ -101,7 +159,6 @@ class ImportTestMixin(object):
"""
return []
@flaky # TODO fix this, see PLAT-1186
def test_upload(self):
"""
Scenario: I want to upload a course or library for import.
......@@ -110,6 +167,7 @@ class ImportTestMixin(object):
I can select the file and upload it
And the page will give me confirmation that it uploaded successfully
"""
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball(self.tarball_name)
self.import_page.wait_for_upload()
......@@ -125,6 +183,7 @@ class ImportTestMixin(object):
# import_page timestamp is in (MM/DD/YYYY at HH:mm) so replacing (second, microsecond) to
# keep the comparison consistent
upload_start_time = datetime.utcnow().replace(microsecond=0, second=0)
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball(self.tarball_name)
self.import_page.wait_for_upload()
......@@ -158,6 +217,7 @@ class ImportTestMixin(object):
Given that I upload a library or course
A button will appear that contains the URL to the library or course's main page
"""
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball(self.tarball_name)
self.assertEqual(self.import_page.finished_target_url(), self.landing_page.url)
......@@ -167,6 +227,7 @@ class ImportTestMixin(object):
Given that I select a file that is an .mp4 for upload
An error message will appear
"""
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball('funny_cat_video.mp4')
self.import_page.wait_for_filename_error()
......@@ -182,6 +243,7 @@ class ImportTestMixin(object):
# The task list shouldn't be visible to start.
self.assertFalse(self.import_page.is_task_list_showing(), "Task list shown too early.")
self.import_page.wait_for_tasks()
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball(self.tarball_name)
self.import_page.wait_for_tasks(completed=True)
self.assertTrue(self.import_page.is_task_list_showing(), "Task list did not display.")
......@@ -195,6 +257,7 @@ class ImportTestMixin(object):
And the 'Updating' task should be marked failed
And the remaining tasks should not be marked as started
"""
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball(self.bad_tarball_name)
self.import_page.wait_for_tasks(fail_on='Updating')
......@@ -212,7 +275,6 @@ class TestEntranceExamCourseImport(ImportTestMixin, StudioCourseTest):
def page_args(self):
return [self.browser, self.course_info['org'], self.course_info['number'], self.course_info['run']]
@flaky # TODO fix this, see PLAT-1186
def test_course_updated_with_entrance_exam(self):
"""
Given that I visit an empty course before import
......@@ -229,6 +291,7 @@ class TestEntranceExamCourseImport(ImportTestMixin, StudioCourseTest):
self.assertRaises(IndexError, self.landing_page.section, "Section")
self.assertRaises(IndexError, self.landing_page.section, "Entrance Exam")
self.import_page.visit()
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball(self.tarball_name)
self.import_page.wait_for_upload()
self.landing_page.visit()
......@@ -259,7 +322,6 @@ class TestCourseImport(ImportTestMixin, StudioCourseTest):
def page_args(self):
return [self.browser, self.course_info['org'], self.course_info['number'], self.course_info['run']]
@flaky # TODO fix this, see PLAT-1186
def test_course_updated(self):
"""
Given that I visit an empty course before import
......@@ -273,6 +335,7 @@ class TestCourseImport(ImportTestMixin, StudioCourseTest):
# Should not exist yet.
self.assertRaises(IndexError, self.landing_page.section, "Section")
self.import_page.visit()
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball(self.tarball_name)
self.import_page.wait_for_upload()
self.landing_page.visit()
......@@ -299,6 +362,7 @@ class TestCourseImport(ImportTestMixin, StudioCourseTest):
Then timestamp is not visible
"""
self.import_page.visit()
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball(self.tarball_name)
self.import_page.wait_for_upload()
self.assertTrue(self.import_page.is_timestamp_visible())
......@@ -330,7 +394,6 @@ class TestLibraryImport(ImportTestMixin, StudioLibraryTest):
def page_args(self):
return [self.browser, self.library_key]
@flaky # TODO fix this, see PLAT-1186
def test_library_updated(self):
"""
Given that I visit an empty library
......@@ -345,6 +408,7 @@ class TestLibraryImport(ImportTestMixin, StudioLibraryTest):
# No items should be in the library to start.
self.assertEqual(len(self.landing_page.xblocks), 0)
self.import_page.visit()
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball(self.tarball_name)
self.import_page.wait_for_upload()
self.landing_page.visit()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment