Commit 06ff3858 by stv

Fix failing captions test

- Use OpaqueKeys exception
- Remove unused imports
- Clean up syntax
- Remove superfluous print statment
parent 069de1c5
...@@ -18,11 +18,11 @@ from xmodule.modulestore.django import modulestore ...@@ -18,11 +18,11 @@ from xmodule.modulestore.django import modulestore
from xmodule.contentstore.django import contentstore, _CONTENTSTORE from xmodule.contentstore.django import contentstore, _CONTENTSTORE
from xmodule.contentstore.content import StaticContent from xmodule.contentstore.content import StaticContent
from xmodule.exceptions import NotFoundError from xmodule.exceptions import NotFoundError
from xmodule.modulestore.django import loc_mapper
from xmodule.modulestore.keys import UsageKey from xmodule.modulestore.keys import UsageKey
from xmodule.modulestore.locator import BlockUsageLocator
from contentstore.tests.modulestore_config import TEST_MODULESTORE from contentstore.tests.modulestore_config import TEST_MODULESTORE
TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE) TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE)
TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex
...@@ -205,15 +205,16 @@ class TestCheckcaptions(Basetranscripts): ...@@ -205,15 +205,16 @@ class TestCheckcaptions(Basetranscripts):
'video': '', 'video': '',
} }
resp = self.client.get(link, data, HTTP_ACCEPT='application/json') resp = self.client.get(link, data, HTTP_ACCEPT='application/json')
print resp.content
self.assertEqual(resp.status_code, 400) self.assertEqual(resp.status_code, 400)
self.assertEqual(json.loads(resp.content).get('message'), "Invalid location.") self.assertEqual(json.loads(resp.content).get('message'), "Invalid location.")
def test_fail_data_with_bad_locator(self): def test_fail_data_with_bad_locator(self):
# Test for raising `InvalidLocationError` exception. # Test for raising `InvalidKeyError` exception.
link = self.captions_url link = self.captions_url
data = { data = {
'video': json.dumps({'location': ''}), 'video': json.dumps({
'location': '',
}),
} }
resp = self.client.get(link, data) resp = self.client.get(link, data)
self.assertEqual(resp.status_code, 400) self.assertEqual(resp.status_code, 400)
...@@ -221,7 +222,9 @@ class TestCheckcaptions(Basetranscripts): ...@@ -221,7 +222,9 @@ class TestCheckcaptions(Basetranscripts):
# Test for raising `ItemNotFoundError` exception. # Test for raising `ItemNotFoundError` exception.
data = { data = {
'video': json.dumps({'location': '{0}_{1}'.format(self.item_location_string, 'BAD_LOCATION')}), 'video': json.dumps({
'location': '{0}_{1}'.format(self.item_location_string, 'BAD_LOCATION')
}),
} }
resp = self.client.get(link, data) resp = self.client.get(link, data)
self.assertEqual(resp.status_code, 400) self.assertEqual(resp.status_code, 400)
......
...@@ -4,6 +4,7 @@ Views related to operations on course objects ...@@ -4,6 +4,7 @@ Views related to operations on course objects
import json import json
import logging import logging
import os import os
from django_future.csrf import ensure_csrf_cookie from django_future.csrf import ensure_csrf_cookie
from django.conf import settings from django.conf import settings
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
...@@ -11,18 +12,18 @@ from django.core.exceptions import PermissionDenied ...@@ -11,18 +12,18 @@ from django.core.exceptions import PermissionDenied
from django.http import HttpResponseBadRequest, HttpResponseNotFound from django.http import HttpResponseBadRequest, HttpResponseNotFound
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from edxmako.shortcuts import render_to_response from edxmako.shortcuts import render_to_response
from models.settings.course_grading import CourseGradingModel
from opaque_keys import InvalidKeyError
from util.json_request import JsonResponse from util.json_request import JsonResponse
from xmodule.modulestore.django import modulestore, loc_mapper from xmodule.modulestore.django import modulestore
from xmodule.modulestore.exceptions import ItemNotFoundError, InvalidLocationError, InsufficientSpecificationError from xmodule.modulestore.exceptions import ItemNotFoundError, InsufficientSpecificationError
from xmodule.modulestore.keys import CourseKey from xmodule.modulestore.keys import CourseKey
from xmodule.modulestore.keys import UsageKey from xmodule.modulestore.keys import UsageKey
from xmodule.modulestore.locator import BlockUsageLocator
from xmodule.video_module.transcripts_utils import ( from xmodule.video_module.transcripts_utils import (
GetTranscriptsFromYouTubeException, GetTranscriptsFromYouTubeException,
TranscriptsRequestValidationException, TranscriptsRequestValidationException,
download_youtube_subs) download_youtube_subs)
from ..access import has_course_access
from ..transcripts_ajax import get_transcripts_presence from ..transcripts_ajax import get_transcripts_presence
from ..course import _get_course_module from ..course import _get_course_module
...@@ -187,10 +188,10 @@ def _validate_captions_data_update(request, course_key): ...@@ -187,10 +188,10 @@ def _validate_captions_data_update(request, course_key):
def _validate_location(location, course_key): def _validate_location(location, course_key):
location = UsageKey.from_string(location)
try: try:
location = UsageKey.from_string(location)
item = modulestore().get_item(location) item = modulestore().get_item(location)
except (ItemNotFoundError, InvalidLocationError, InsufficientSpecificationError): except (ItemNotFoundError, InvalidKeyError, InsufficientSpecificationError):
raise TranscriptsRequestValidationException(_("Can't find item by locator.")) raise TranscriptsRequestValidationException(_("Can't find item by locator."))
if item.category != 'video': if item.category != 'video':
......
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