"""Tests for items views.""" import os import json import tempfile from uuid import uuid4 import copy import textwrap from pymongo import MongoClient from django.core.urlresolvers import reverse from django.test.utils import override_settings from django.conf import settings from contentstore import transcripts_utils from contentstore.tests.utils import CourseTestCase from cache_toolbox.core import del_cached_content from xmodule.modulestore.django import modulestore from xmodule.contentstore.django import contentstore, _CONTENTSTORE from xmodule.contentstore.content import StaticContent from xmodule.exceptions import NotFoundError from xmodule.modulestore.django import loc_mapper from xmodule.modulestore.locator import BlockUsageLocator from contentstore.tests.modulestore_config import TEST_MODULESTORE TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE) TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex @override_settings(CONTENTSTORE=TEST_DATA_CONTENTSTORE, MODULESTORE=TEST_MODULESTORE) class Basetranscripts(CourseTestCase): """Base test class for transcripts tests.""" org = 'MITx' number = '999' def clear_subs_content(self): """Remove, if transcripts content exists.""" for youtube_id in self.get_youtube_ids().values(): filename = 'subs_{0}.srt.sjson'.format(youtube_id) content_location = StaticContent.compute_location( self.org, self.number, filename) try: content = contentstore().find(content_location) contentstore().delete(content.get_id()) except NotFoundError: pass def setUp(self): """Create initial data.""" super(Basetranscripts, self).setUp() self.unicode_locator = unicode(loc_mapper().translate_location( self.course.location.course_id, self.course.location, False, True )) # Add video module data = { 'parent_locator': self.unicode_locator, 'category': 'video', 'type': 'video' } resp = self.client.ajax_post('/xblock', data) self.item_location = self._get_location(resp) self.assertEqual(resp.status_code, 200) # hI10vDNYz4M - valid Youtube ID with transcripts. # JMD_ifUUfsU, AKqURZnYqpk, DYpADpL7jAY - valid Youtube IDs without transcripts. data = '