Commit eaa4b3ef by Julian Arni

Pep8 and pylint fixes

parent d991595e
...@@ -2,12 +2,7 @@ ...@@ -2,12 +2,7 @@
Unit tests for the asset upload endpoint. Unit tests for the asset upload endpoint.
""" """
import os
import json import json
import shutil
import tarfile
import tempfile
from subprocess import call
from datetime import datetime from datetime import datetime
from io import BytesIO from io import BytesIO
from pytz import UTC from pytz import UTC
......
...@@ -38,8 +38,6 @@ from util.json_request import JsonResponse ...@@ -38,8 +38,6 @@ from util.json_request import JsonResponse
__all__ = ['asset_index', 'upload_asset'] __all__ = ['asset_index', 'upload_asset']
MAX_UP_LENGTH = 20000352 # Max chunk size
# Regex to capture Content-Range header ranges. # Regex to capture Content-Range header ranges.
CONTENT_RE = re.compile(r"(?P<start>\d{1,11})-(?P<stop>\d{1,11})/(?P<end>\d{1,11})") CONTENT_RE = re.compile(r"(?P<start>\d{1,11})-(?P<stop>\d{1,11})/(?P<end>\d{1,11})")
......
...@@ -63,7 +63,7 @@ def import_course(request, org, course, name): ...@@ -63,7 +63,7 @@ def import_course(request, org, course, name):
filename = request.FILES['course-data'].name filename = request.FILES['course-data'].name
if not filename.endswith('.tar.gz'): if not filename.endswith('.tar.gz'):
return JsonResponse( return JsonResponse(
{ 'ErrMsg': 'We only support uploading a .tar.gz file.' }, {'ErrMsg': 'We only support uploading a .tar.gz file.'},
status=415 status=415
) )
temp_filepath = course_dir / filename temp_filepath = course_dir / filename
...@@ -96,11 +96,10 @@ def import_course(request, org, course, name): ...@@ -96,11 +96,10 @@ def import_course(request, org, course, name):
content_range['start'] content_range['start']
) )
return JsonResponse( return JsonResponse(
{ 'ErrMsg': 'File upload corrupted. Please try again' }, {'ErrMsg': 'File upload corrupted. Please try again'},
status=409 status=409
) )
with open(temp_filepath, mode) as temp_file: with open(temp_filepath, mode) as temp_file:
for chunk in request.FILES['course-data'].chunks(): for chunk in request.FILES['course-data'].chunks():
temp_file.write(chunk) temp_file.write(chunk)
...@@ -121,8 +120,8 @@ def import_course(request, org, course, name): ...@@ -121,8 +120,8 @@ def import_course(request, org, course, name):
'name': location.name 'name': location.name
}), }),
"thumbnailUrl": "" "thumbnailUrl": ""
}] }]
}) })
else: # This was the last chunk. else: # This was the last chunk.
...@@ -167,7 +166,7 @@ def import_course(request, org, course, name): ...@@ -167,7 +166,7 @@ def import_course(request, org, course, name):
if not dirpath: if not dirpath:
return JsonResponse( return JsonResponse(
{'ErrMsg': 'Could not find the course.xml file in the package.' }, {'ErrMsg': 'Could not find the course.xml file in the package.'},
status=415 status=415
) )
...@@ -178,13 +177,13 @@ def import_course(request, org, course, name): ...@@ -178,13 +177,13 @@ def import_course(request, org, course, name):
shutil.move(dirpath / fname, course_dir) shutil.move(dirpath / fname, course_dir)
_module_store, course_items = import_from_xml( _module_store, course_items = import_from_xml(
modulestore('direct'), modulestore('direct'),
settings.GITHUB_REPO_ROOT, settings.GITHUB_REPO_ROOT,
[course_subdir], [course_subdir],
load_error_modules=False, load_error_modules=False,
static_content_store=contentstore(), static_content_store=contentstore(),
target_location_namespace=location, target_location_namespace=location,
draft_store=modulestore() draft_store=modulestore()
) )
# we can blow this away when we're done importing. # we can blow this away when we're done importing.
......
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