Skip to content
Snippets Groups Projects
Unverified Commit 30aaeb7d authored by Ayub's avatar Ayub Committed by GitHub
Browse files

Merge pull request #20986 from edx/INCR-334

INCR-334 python3 compatibility
parents 1709ec0d b06fcd27
No related branches found
No related tags found
No related merge requests found
Showing
with 70 additions and 46 deletions
......@@ -2,20 +2,20 @@
Test for assets cleanup of courses for Mac OS metadata files (with filename ".DS_Store"
or with filename which starts with "._")
"""
from django.core.management import call_command
from __future__ import absolute_import
from django.conf import settings
from django.core.management import call_command
from opaque_keys.edx.keys import CourseKey
from xmodule.contentstore.content import XASSET_LOCATION_TAG
from xmodule.contentstore.django import contentstore
from xmodule.modulestore.django import modulestore
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.mongo.base import location_to_query
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.utils import (
add_temp_files_from_dict, remove_temp_files_from_list, DOT_FILES_DICT
)
from xmodule.modulestore.tests.utils import DOT_FILES_DICT, add_temp_files_from_dict, remove_temp_files_from_list
from xmodule.modulestore.xml_importer import import_course_from_xml
from django.conf import settings
TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT
......@@ -32,7 +32,7 @@ class ExportAllCourses(ModuleStoreTestCase):
self.content_store = contentstore()
# pylint: disable=protected-access
self.module_store = modulestore()._get_modulestore_by_type(ModuleStoreEnum.Type.mongo)
self.addCleanup(remove_temp_files_from_list, DOT_FILES_DICT.keys(), self.course_dir / "static")
self.addCleanup(remove_temp_files_from_list, list(DOT_FILES_DICT.keys()), self.course_dir / "static")
add_temp_files_from_dict(DOT_FILES_DICT, self.course_dir / "static")
def test_export_all_courses(self):
......
"""
Unittests for creating a course in an chosen modulestore
"""
from __future__ import absolute_import
from StringIO import StringIO
import ddt
import six
from django.core.management import CommandError, call_command
from django.test import TestCase
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
class TestArgParsing(TestCase):
......@@ -108,7 +112,7 @@ class TestCreateCourse(ModuleStoreTestCase):
)
course = self.store.get_course(lowercase_course_id)
self.assertIsNotNone(course, 'Course not found using lowercase course key.')
self.assertEqual(unicode(course.id), unicode(lowercase_course_id))
self.assertEqual(six.text_type(course.id), six.text_type(lowercase_course_id))
# Verify store does not return course with different case.
uppercase_course_id = self.store.make_course_key(org.upper(), number.upper(), run.upper())
......
"""
Delete course tests.
"""
from __future__ import absolute_import
import mock
from django.core.management import CommandError, call_command
......@@ -6,7 +11,7 @@ from student.tests.factories import UserFactory
from xmodule.contentstore.content import StaticContent
from xmodule.contentstore.django import contentstore
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, TEST_DATA_SPLIT_MODULESTORE
from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
......
"""
Test for export all courses.
"""
from __future__ import absolute_import
import shutil
from tempfile import mkdtemp
from contentstore.management.commands.export_all_courses import export_courses_to_output_path
import six
from contentstore.management.commands.export_all_courses import export_courses_to_output_path
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
......@@ -47,4 +50,4 @@ class ExportAllCourses(ModuleStoreTestCase):
courses, failed_export_courses = export_courses_to_output_path(self.temp_dir)
self.assertEqual(len(courses), 2)
self.assertEqual(len(failed_export_courses), 1)
self.assertEqual(failed_export_courses[0], unicode(second_course_id))
self.assertEqual(failed_export_courses[0], six.text_type(second_course_id))
......@@ -2,7 +2,11 @@
Tests for the fix_not_found management command
"""
from __future__ import absolute_import
import six
from django.core.management import CommandError, call_command
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
......@@ -25,7 +29,7 @@ class TestFixNotFound(ModuleStoreTestCase):
"""
course = CourseFactory.create(default_store=ModuleStoreEnum.Type.mongo)
with self.assertRaisesRegexp(CommandError, "The owning modulestore does not support this command."):
call_command("fix_not_found", unicode(course.id))
call_command("fix_not_found", six.text_type(course.id))
def test_fix_not_found(self):
course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split)
......@@ -45,7 +49,7 @@ class TestFixNotFound(ModuleStoreTestCase):
self.assertEqual(len(course.children), 2)
self.assertIn(dangling_pointer, course.children)
call_command("fix_not_found", unicode(course.id))
call_command("fix_not_found", six.text_type(course.id))
# make sure the dangling pointer was removed from
# the course block's children
......
......@@ -2,10 +2,13 @@
Unittests for importing a course via management command
"""
from __future__ import absolute_import
import os
import shutil
import tempfile
import six
from django.core.management import call_command
from path import Path as path
......@@ -91,4 +94,4 @@ class TestImport(ModuleStoreTestCase):
course = modulestore().get_course(self.base_course_key)
# With the bug, this fails because the chapter's course_key is the split mongo form,
# while the course's course_key is the old mongo form.
self.assertEqual(unicode(course.location.course_key), unicode(course.children[0].course_key))
self.assertEqual(six.text_type(course.location.course_key), six.text_type(course.children[0].course_key))
......@@ -2,26 +2,27 @@
"""
Tests for course transcript migration management command.
"""
from __future__ import absolute_import
import itertools
import logging
from datetime import datetime
import pytz
import ddt
import pytz
import six
from django.core.management import CommandError, call_command
from django.test import TestCase
from django.core.management import call_command, CommandError
from edxval import api as api
from mock import patch
from testfixtures import LogCapture
from openedx.core.djangoapps.video_config.models import (
TranscriptMigrationSetting, MigrationEnqueuedCourse
)
from openedx.core.djangoapps.video_config.models import MigrationEnqueuedCourse, TranscriptMigrationSetting
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.video_module import VideoBlock
from xmodule.video_module.transcripts_utils import save_to_store
from edxval import api as api
from testfixtures import LogCapture
LOGGER_NAME = "cms.djangoapps.contentstore.tasks"
......@@ -94,7 +95,7 @@ class TestMigrateTranscripts(ModuleStoreTestCase):
'client_video_id': 'test1.mp4',
'duration': 42.0,
'status': 'upload',
'courses': [unicode(self.course.id)],
'courses': [six.text_type(self.course.id)],
'encoded_videos': [],
'created': datetime.now(pytz.utc)
}
......@@ -155,7 +156,7 @@ class TestMigrateTranscripts(ModuleStoreTestCase):
self.assertFalse(api.is_transcript_available(self.video_descriptor.edx_video_id, 'ge'))
# now call migrate_transcripts command and check the transcript availability
call_command('migrate_transcripts', '--course-id', unicode(self.course.id), '--commit')
call_command('migrate_transcripts', '--course-id', six.text_type(self.course.id), '--commit')
languages = api.get_available_transcript_languages(self.video_descriptor.edx_video_id)
self.assertEqual(len(languages), 2)
......@@ -173,7 +174,7 @@ class TestMigrateTranscripts(ModuleStoreTestCase):
self.assertFalse(api.is_transcript_available(self.video_descriptor.edx_video_id, 'ge'))
# now call migrate_transcripts command and check the transcript availability
call_command('migrate_transcripts', '--course-id', unicode(self.course.id))
call_command('migrate_transcripts', '--course-id', six.text_type(self.course.id))
# check that transcripts still do not exist
languages = api.get_available_transcript_languages(self.video_descriptor.edx_video_id)
......@@ -191,7 +192,7 @@ class TestMigrateTranscripts(ModuleStoreTestCase):
self.assertFalse(api.is_transcript_available(self.video_descriptor.edx_video_id, 'ge'))
# now call migrate_transcripts command and check the transcript availability
call_command('migrate_transcripts', '--course-id', unicode(self.course.id), '--commit')
call_command('migrate_transcripts', '--course-id', six.text_type(self.course.id), '--commit')
self.assertTrue(api.is_transcript_available(self.video_descriptor.edx_video_id, 'hr'))
self.assertTrue(api.is_transcript_available(self.video_descriptor.edx_video_id, 'ge'))
......@@ -206,19 +207,19 @@ class TestMigrateTranscripts(ModuleStoreTestCase):
self.assertFalse(api.is_transcript_available(self.video_descriptor.edx_video_id, 'ge'))
# now call migrate_transcripts command and check the transcript availability
call_command('migrate_transcripts', '--course-id', unicode(self.course.id), '--commit')
call_command('migrate_transcripts', '--course-id', six.text_type(self.course.id), '--commit')
self.assertTrue(api.is_transcript_available(self.video_descriptor.edx_video_id, 'hr'))
self.assertTrue(api.is_transcript_available(self.video_descriptor.edx_video_id, 'ge'))
# now call migrate_transcripts command again and check the transcript availability
call_command('migrate_transcripts', '--course-id', unicode(self.course.id), '--commit')
call_command('migrate_transcripts', '--course-id', six.text_type(self.course.id), '--commit')
self.assertTrue(api.is_transcript_available(self.video_descriptor.edx_video_id, 'hr'))
self.assertTrue(api.is_transcript_available(self.video_descriptor.edx_video_id, 'ge'))
# now call migrate_transcripts command with --force-update and check the transcript availability
call_command('migrate_transcripts', '--course-id', unicode(self.course.id), '--force-update', '--commit')
call_command('migrate_transcripts', '--course-id', six.text_type(self.course.id), '--force-update', '--commit')
self.assertTrue(api.is_transcript_available(self.video_descriptor.edx_video_id, 'hr'))
self.assertTrue(api.is_transcript_available(self.video_descriptor.edx_video_id, 'ge'))
......@@ -227,7 +228,7 @@ class TestMigrateTranscripts(ModuleStoreTestCase):
"""
Test migrate transcripts logging and output
"""
course_id = unicode(self.course.id)
course_id = six.text_type(self.course.id)
expected_log = (
(
'cms.djangoapps.contentstore.tasks', 'INFO',
......@@ -255,7 +256,7 @@ class TestMigrateTranscripts(ModuleStoreTestCase):
)
with LogCapture(LOGGER_NAME, level=logging.INFO) as logger:
call_command('migrate_transcripts', '--course-id', unicode(self.course.id))
call_command('migrate_transcripts', '--course-id', six.text_type(self.course.id))
logger.check(
*expected_log
)
......@@ -264,7 +265,7 @@ class TestMigrateTranscripts(ModuleStoreTestCase):
"""
Test migrate transcripts exception logging
"""
course_id = unicode(self.course_2.id)
course_id = six.text_type(self.course_2.id)
expected_log = (
(
'cms.djangoapps.contentstore.tasks', 'INFO',
......@@ -292,7 +293,7 @@ class TestMigrateTranscripts(ModuleStoreTestCase):
)
with LogCapture(LOGGER_NAME, level=logging.INFO) as logger:
call_command('migrate_transcripts', '--course-id', unicode(self.course_2.id), '--commit')
call_command('migrate_transcripts', '--course-id', six.text_type(self.course_2.id), '--commit')
logger.check(
*expected_log
)
......
""" Tests for course reindex command """
from __future__ import absolute_import
import ddt
from django.core.management import call_command, CommandError
import mock
from django.core.management import CommandError, call_command
from six import text_type
from contentstore.courseware_index import SearchIndexingError
from contentstore.management.commands.reindex_course import Command as ReindexCommand
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, LibraryFactory
from contentstore.management.commands.reindex_course import Command as ReindexCommand
from contentstore.courseware_index import SearchIndexingError
@ddt.ddt
class TestReindexCourse(ModuleStoreTestCase):
......
"""
Views related to the transcript preferences feature
"""
import os
from __future__ import absolute_import
import logging
import os
from django.contrib.auth.decorators import login_required
from django.core.files.base import ContentFile
from django.http import HttpResponseNotFound, HttpResponse
from django.http import HttpResponse, HttpResponseNotFound
from django.utils.translation import ugettext as _
from django.views.decorators.http import require_http_methods, require_POST, require_GET
from django.views.decorators.http import require_GET, require_http_methods, require_POST
from edxval.api import (
create_or_update_video_transcript,
delete_video_transcript,
get_available_transcript_languages,
get_3rd_party_transcription_plans,
get_available_transcript_languages,
get_video_transcript_data,
update_transcript_credentials_state_for_org,
update_transcript_credentials_state_for_org
)
from opaque_keys.edx.keys import CourseKey
from contentstore.views.videos import TranscriptProvider
from openedx.core.djangoapps.video_config.models import VideoTranscriptEnabledFlag
from openedx.core.djangoapps.video_pipeline.api import update_3rd_party_transcription_service_credentials
from student.auth import has_studio_write_access
from util.json_request import JsonResponse, expect_json
from contentstore.views.videos import TranscriptProvider
from xmodule.video_module.transcripts_utils import Transcript, TranscriptsGenerationException
__all__ = [
......@@ -58,7 +59,7 @@ def validate_transcript_credentials(provider, **credentials):
only returns the validated ones.
"""
error_message, validated_credentials = '', {}
valid_providers = get_3rd_party_transcription_plans().keys()
valid_providers = list(get_3rd_party_transcription_plans().keys())
if provider in valid_providers:
must_have_props = []
if provider == TranscriptProvider.THREE_PLAY_MEDIA:
......@@ -66,7 +67,9 @@ def validate_transcript_credentials(provider, **credentials):
elif provider == TranscriptProvider.CIELO24:
must_have_props = ['api_key', 'username']
missing = [must_have_prop for must_have_prop in must_have_props if must_have_prop not in credentials.keys()]
missing = [
must_have_prop for must_have_prop in must_have_props if must_have_prop not in list(credentials.keys())
]
if missing:
error_message = u'{missing} must be specified.'.format(missing=' and '.join(missing))
return error_message, validated_credentials
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment