Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions cms/djangoapps/contentstore/tests/test_contentstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ def check_components_on_page(self, component_types, expected_types):
locator = loc_mapper().translate_location(course.location.course_id, descriptor.location, False, True)
resp = self.client.get_html(locator.url_reverse('unit'))
self.assertEqual(resp.status_code, 200)
# TODO: uncomment when video transcripts no longer require IDs.
# _test_no_locations(self, resp)
_test_no_locations(self, resp)

for expected in expected_types:
self.assertIn(expected, resp.content)
Expand Down Expand Up @@ -1354,8 +1353,7 @@ def _check_verticals(self, items, course_id):
unit_locator = loc_mapper().translate_location(course_id, descriptor.location, False, True)
resp = self.client.get_html(unit_locator.url_reverse('unit'))
self.assertEqual(resp.status_code, 200)
# TODO: uncomment when video transcripts no longer require IDs.
# _test_no_locations(self, resp)
_test_no_locations(self, resp)


@override_settings(CONTENTSTORE=TEST_DATA_CONTENTSTORE, MODULESTORE=TEST_MODULESTORE)
Expand Down Expand Up @@ -1682,8 +1680,7 @@ def test_get_html(page):
unit_locator = loc_mapper().translate_location(loc.course_id, unit_location, False, True)
resp = self.client.get_html(unit_locator.url_reverse('unit'))
self.assertEqual(resp.status_code, 200)
# TODO: uncomment when video transcripts no longer require IDs.
# _test_no_locations(self, resp)
_test_no_locations(self, resp)

def delete_item(category, name):
""" Helper method for testing the deletion of an xblock item. """
Expand Down
80 changes: 40 additions & 40 deletions cms/djangoapps/contentstore/tests/test_transcripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def setUp(self):
'type': 'video'
}
resp = self.client.ajax_post('/xblock', data)
self.item_location = self._get_location(resp)
self.item_locator, self.item_location = self._get_locator(resp)
self.assertEqual(resp.status_code, 200)

# hI10vDNYz4M - valid Youtube ID with transcripts.
Expand All @@ -73,10 +73,10 @@ def setUp(self):
# Remove all transcripts for current module.
self.clear_subs_content()

def _get_location(self, resp):
""" Returns the location (as a string) from the response returned by a create operation. """
def _get_locator(self, resp):
""" Returns the locator and old-style location (as a string) from the response returned by a create operation. """
locator = json.loads(resp.content).get('locator')
return loc_mapper().translate_locator_to_location(BlockUsageLocator(locator)).url()
return locator, loc_mapper().translate_locator_to_location(BlockUsageLocator(locator)).url()

def get_youtube_ids(self):
"""Return youtube speeds and ids."""
Expand Down Expand Up @@ -142,7 +142,7 @@ def test_success_video_module_source_subs_uploading(self):
link = reverse('upload_transcripts')
filename = os.path.splitext(os.path.basename(self.good_srt_file.name))[0]
resp = self.client.post(link, {
'id': self.item_location,
'locator': self.item_locator,
'file': self.good_srt_file,
'video_list': json.dumps([{
'type': 'html5',
Expand All @@ -164,20 +164,20 @@ def test_fail_data_without_id(self):
link = reverse('upload_transcripts')
resp = self.client.post(link, {'file': self.good_srt_file})
self.assertEqual(resp.status_code, 400)
self.assertEqual(json.loads(resp.content).get('status'), 'POST data without "id" form data.')
self.assertEqual(json.loads(resp.content).get('status'), 'POST data without "locator" form data.')

def test_fail_data_without_file(self):
link = reverse('upload_transcripts')
resp = self.client.post(link, {'id': self.item_location})
resp = self.client.post(link, {'locator': self.item_locator})
self.assertEqual(resp.status_code, 400)
self.assertEqual(json.loads(resp.content).get('status'), 'POST data without "file" form data.')

def test_fail_data_with_bad_location(self):
def test_fail_data_with_bad_locator(self):
# Test for raising `InvalidLocationError` exception.
link = reverse('upload_transcripts')
filename = os.path.splitext(os.path.basename(self.good_srt_file.name))[0]
resp = self.client.post(link, {
'id': 'BAD_LOCATION',
'locator': 'BAD_LOCATOR',
'file': self.good_srt_file,
'video_list': json.dumps([{
'type': 'html5',
Expand All @@ -186,13 +186,13 @@ def test_fail_data_with_bad_location(self):
}])
})
self.assertEqual(resp.status_code, 400)
self.assertEqual(json.loads(resp.content).get('status'), "Can't find item by location.")
self.assertEqual(json.loads(resp.content).get('status'), "Can't find item by locator.")

# Test for raising `ItemNotFoundError` exception.
link = reverse('upload_transcripts')
filename = os.path.splitext(os.path.basename(self.good_srt_file.name))[0]
resp = self.client.post(link, {
'id': '{0}_{1}'.format(self.item_location, 'BAD_LOCATION'),
'locator': '{0}_{1}'.format(self.item_locator, 'BAD_LOCATOR'),
'file': self.good_srt_file,
'video_list': json.dumps([{
'type': 'html5',
Expand All @@ -201,7 +201,7 @@ def test_fail_data_with_bad_location(self):
}])
})
self.assertEqual(resp.status_code, 400)
self.assertEqual(json.loads(resp.content).get('status'), "Can't find item by location.")
self.assertEqual(json.loads(resp.content).get('status'), "Can't find item by locator.")

def test_fail_for_non_video_module(self):
# non_video module: setup
Expand All @@ -211,7 +211,7 @@ def test_fail_for_non_video_module(self):
'type': 'non_video'
}
resp = self.client.ajax_post('/xblock', data)
item_location = self._get_location(resp)
item_locator, item_location = self._get_locator(resp)
data = '<non_video youtube="0.75:JMD_ifUUfsU,1.0:hI10vDNYz4M" />'
modulestore().update_item(item_location, data)

Expand All @@ -220,7 +220,7 @@ def test_fail_for_non_video_module(self):
link = reverse('upload_transcripts')
filename = os.path.splitext(os.path.basename(self.good_srt_file.name))[0]
resp = self.client.post(link, {
'id': item_location,
'locator': item_locator,
'file': self.good_srt_file,
'video_list': json.dumps([{
'type': 'html5',
Expand All @@ -238,7 +238,7 @@ def test_fail_bad_xml(self):
link = reverse('upload_transcripts')
filename = os.path.splitext(os.path.basename(self.good_srt_file.name))[0]
resp = self.client.post(link, {
'id': self.item_location,
'locator': self.item_locator,
'file': self.good_srt_file,
'video_list': json.dumps([{
'type': 'html5',
Expand All @@ -255,7 +255,7 @@ def test_fail_bad_data_srt_file(self):
link = reverse('upload_transcripts')
filename = os.path.splitext(os.path.basename(self.bad_data_srt_file.name))[0]
resp = self.client.post(link, {
'id': self.item_location,
'locator': self.item_locator,
'file': self.bad_data_srt_file,
'video_list': json.dumps([{
'type': 'html5',
Expand All @@ -270,7 +270,7 @@ def test_fail_bad_name_srt_file(self):
link = reverse('upload_transcripts')
filename = os.path.splitext(os.path.basename(self.bad_name_srt_file.name))[0]
resp = self.client.post(link, {
'id': self.item_location,
'locator': self.item_locator,
'file': self.bad_name_srt_file,
'video_list': json.dumps([{
'type': 'html5',
Expand All @@ -297,7 +297,7 @@ def test_undefined_file_extension(self):
link = reverse('upload_transcripts')
filename = os.path.splitext(os.path.basename(srt_file.name))[0]
resp = self.client.post(link, {
'id': self.item_location,
'locator': self.item_locator,
'file': srt_file,
'video_list': json.dumps([{
'type': 'html5',
Expand Down Expand Up @@ -359,7 +359,7 @@ def test_success_download_youtube(self):
self.save_subs_to_store(subs, 'JMD_ifUUfsU')

link = reverse('download_transcripts')
resp = self.client.get(link, {'id': self.item_location, 'subs_id': "JMD_ifUUfsU"})
resp = self.client.get(link, {'locator': self.item_locator, 'subs_id': "JMD_ifUUfsU"})
self.assertEqual(resp.status_code, 200)
self.assertEqual(resp.content, """0\n00:00:00,100 --> 00:00:00,200\nsubs #1\n\n1\n00:00:00,200 --> 00:00:00,240\nsubs #2\n\n2\n00:00:00,240 --> 00:00:00,380\nsubs #3\n\n""")

Expand All @@ -386,7 +386,7 @@ def test_success_download_nonyoutube(self):
self.save_subs_to_store(subs, subs_id)

link = reverse('download_transcripts')
resp = self.client.get(link, {'id': self.item_location, 'subs_id': subs_id})
resp = self.client.get(link, {'locator': self.item_locator, 'subs_id': subs_id})
self.assertEqual(resp.status_code, 200)
self.assertEqual(
resp.content,
Expand All @@ -397,21 +397,21 @@ def test_success_download_nonyoutube(self):

def test_fail_data_without_file(self):
link = reverse('download_transcripts')
resp = self.client.get(link, {'id': ''})
resp = self.client.get(link, {'locator': ''})
self.assertEqual(resp.status_code, 404)

resp = self.client.get(link, {})
self.assertEqual(resp.status_code, 404)

def test_fail_data_with_bad_location(self):
def test_fail_data_with_bad_locator(self):
# Test for raising `InvalidLocationError` exception.
link = reverse('download_transcripts')
resp = self.client.get(link, {'id': 'BAD_LOCATION'})
resp = self.client.get(link, {'locator': 'BAD_LOCATOR'})
self.assertEqual(resp.status_code, 404)

# Test for raising `ItemNotFoundError` exception.
link = reverse('download_transcripts')
resp = self.client.get(link, {'id': '{0}_{1}'.format(self.item_location, 'BAD_LOCATION')})
resp = self.client.get(link, {'locator': '{0}_{1}'.format(self.item_locator, 'BAD_LOCATOR')})
self.assertEqual(resp.status_code, 404)

def test_fail_for_non_video_module(self):
Expand All @@ -422,7 +422,7 @@ def test_fail_for_non_video_module(self):
'type': 'videoalpha'
}
resp = self.client.ajax_post('/xblock', data)
item_location = self._get_location(resp)
item_locator, item_location = self._get_locator(resp)
subs_id = str(uuid4())
data = textwrap.dedent("""
<videoalpha youtube="" sub="{}">
Expand All @@ -445,7 +445,7 @@ def test_fail_for_non_video_module(self):
self.save_subs_to_store(subs, subs_id)

link = reverse('download_transcripts')
resp = self.client.get(link, {'id': item_location})
resp = self.client.get(link, {'locator': item_locator})
self.assertEqual(resp.status_code, 404)

def test_fail_nonyoutube_subs_dont_exist(self):
Expand All @@ -459,7 +459,7 @@ def test_fail_nonyoutube_subs_dont_exist(self):
modulestore().update_item(self.item_location, data)

link = reverse('download_transcripts')
resp = self.client.get(link, {'id': self.item_location})
resp = self.client.get(link, {'locator': self.item_locator})
self.assertEqual(resp.status_code, 404)

def test_empty_youtube_attr_and_sub_attr(self):
Expand All @@ -473,7 +473,7 @@ def test_empty_youtube_attr_and_sub_attr(self):
modulestore().update_item(self.item_location, data)

link = reverse('download_transcripts')
resp = self.client.get(link, {'id': self.item_location})
resp = self.client.get(link, {'locator': self.item_locator})

self.assertEqual(resp.status_code, 404)

Expand All @@ -498,7 +498,7 @@ def test_fail_bad_sjson_subs(self):
self.save_subs_to_store(subs, 'JMD_ifUUfsU')

link = reverse('download_transcripts')
resp = self.client.get(link, {'id': self.item_location})
resp = self.client.get(link, {'locator': self.item_locator})

self.assertEqual(resp.status_code, 404)

Expand Down Expand Up @@ -553,7 +553,7 @@ def test_success_download_nonyoutube(self):
self.save_subs_to_store(subs, subs_id)

data = {
'id': self.item_location,
'locator': self.item_locator,
'videos': [{
'type': 'html5',
'video': subs_id,
Expand Down Expand Up @@ -597,7 +597,7 @@ def test_check_youtube(self):
self.save_subs_to_store(subs, 'JMD_ifUUfsU')
link = reverse('check_transcripts')
data = {
'id': self.item_location,
'locator': self.item_locator,
'videos': [{
'type': 'youtube',
'video': 'JMD_ifUUfsU',
Expand Down Expand Up @@ -625,7 +625,7 @@ def test_check_youtube(self):
def test_fail_data_without_id(self):
link = reverse('check_transcripts')
data = {
'id': '',
'locator': '',
'videos': [{
'type': '',
'video': '',
Expand All @@ -634,13 +634,13 @@ def test_fail_data_without_id(self):
}
resp = self.client.get(link, {'data': json.dumps(data)})
self.assertEqual(resp.status_code, 400)
self.assertEqual(json.loads(resp.content).get('status'), "Can't find item by location.")
self.assertEqual(json.loads(resp.content).get('status'), "Can't find item by locator.")

def test_fail_data_with_bad_location(self):
def test_fail_data_with_bad_locator(self):
# Test for raising `InvalidLocationError` exception.
link = reverse('check_transcripts')
data = {
'id': '',
'locator': '',
'videos': [{
'type': '',
'video': '',
Expand All @@ -649,11 +649,11 @@ def test_fail_data_with_bad_location(self):
}
resp = self.client.get(link, {'data': json.dumps(data)})
self.assertEqual(resp.status_code, 400)
self.assertEqual(json.loads(resp.content).get('status'), "Can't find item by location.")
self.assertEqual(json.loads(resp.content).get('status'), "Can't find item by locator.")

# Test for raising `ItemNotFoundError` exception.
data = {
'id': '{0}_{1}'.format(self.item_location, 'BAD_LOCATION'),
'locator': '{0}_{1}'.format(self.item_locator, 'BAD_LOCATOR'),
'videos': [{
'type': '',
'video': '',
Expand All @@ -662,7 +662,7 @@ def test_fail_data_with_bad_location(self):
}
resp = self.client.get(link, {'data': json.dumps(data)})
self.assertEqual(resp.status_code, 400)
self.assertEqual(json.loads(resp.content).get('status'), "Can't find item by location.")
self.assertEqual(json.loads(resp.content).get('status'), "Can't find item by locator.")

def test_fail_for_non_video_module(self):
# Not video module: setup
Expand All @@ -672,7 +672,7 @@ def test_fail_for_non_video_module(self):
'type': 'not_video'
}
resp = self.client.ajax_post('/xblock', data)
item_location = self._get_location(resp)
item_locator, item_location = self._get_locator(resp)
subs_id = str(uuid4())
data = textwrap.dedent("""
<not_video youtube="" sub="{}">
Expand All @@ -695,7 +695,7 @@ def test_fail_for_non_video_module(self):
self.save_subs_to_store(subs, subs_id)

data = {
'id': item_location,
'locator': item_locator,
'videos': [{
'type': '',
'video': '',
Expand Down
10 changes: 3 additions & 7 deletions cms/djangoapps/contentstore/views/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,9 @@ def unit_handler(request, tag=None, course_id=None, branch=None, version_guid=No
)

components = [
[
# TODO: old location needed for video transcripts.
component.location.url(),
loc_mapper().translate_location(
course.location.course_id, component.location, False, True
)
]
loc_mapper().translate_location(
course.location.course_id, component.location, False, True
)
for component
in item.get_children()
]
Expand Down
Loading