diff --git a/cms/djangoapps/contentstore/views/tests/test_access.py b/cms/djangoapps/contentstore/views/tests/test_access.py index a9aefbd4c4..5a17c31e0d 100644 --- a/cms/djangoapps/contentstore/views/tests/test_access.py +++ b/cms/djangoapps/contentstore/views/tests/test_access.py @@ -1,6 +1,8 @@ """ Tests access.py """ +from __future__ import absolute_import + from django.contrib.auth.models import User from django.test import TestCase from opaque_keys.edx.locator import CourseLocator diff --git a/cms/djangoapps/contentstore/views/tests/test_assets.py b/cms/djangoapps/contentstore/views/tests/test_assets.py index 4db1a66bbd..49d141f3c6 100644 --- a/cms/djangoapps/contentstore/views/tests/test_assets.py +++ b/cms/djangoapps/contentstore/views/tests/test_assets.py @@ -1,11 +1,14 @@ """ Unit tests for the asset upload endpoint. """ +from __future__ import absolute_import + import json from datetime import datetime from io import BytesIO import mock +import six from ddt import data, ddt from django.conf import settings from django.test.utils import override_settings @@ -301,7 +304,9 @@ class PaginationTestCase(AssetsTestCase): for content_type in content_types: # content_type is either not any defined type (i.e. OTHER) or is a defined type (if multiple # parameters including OTHER are used) - self.assertTrue(content_type in requested_file_extensions or content_type not in all_file_extensions) + self.assertTrue( + content_type in requested_file_extensions or content_type not in all_file_extensions + ) else: for content_type in content_types: self.assertIn(content_type, requested_file_extensions) @@ -329,7 +334,7 @@ class PaginationTestCase(AssetsTestCase): for asset_response in assets_response: for token in text_search_tokens: - self.assertTrue(token.lower() in asset_response['display_name'].lower()) + self.assertIn(token.lower(), asset_response['display_name'].lower()) @ddt @@ -424,10 +429,12 @@ class AssetToJsonTestCase(AssetsTestCase): self.assertEquals(output["display_name"], "my_file") self.assertEquals(output["date_added"], "Jun 01, 2013 at 10:30 UTC") self.assertEquals(output["url"], "/asset-v1:org+class+run+type@asset+block@my_file_name.jpg") - self.assertEquals(output["external_url"], "lms_base_url/asset-v1:org+class+run+type@asset+block@my_file_name.jpg") + self.assertEquals( + output["external_url"], "lms_base_url/asset-v1:org+class+run+type@asset+block@my_file_name.jpg" + ) self.assertEquals(output["portable_url"], "/static/my_file_name.jpg") self.assertEquals(output["thumbnail"], "/asset-v1:org+class+run+type@thumbnail+block@my_file_name_thumb.jpg") - self.assertEquals(output["id"], unicode(location)) + self.assertEquals(output["id"], six.text_type(location)) self.assertEquals(output['locked'], True) output = assets._get_asset_json("name", content_type, upload_date, location, None, False) @@ -454,7 +461,9 @@ class LockAssetTestCase(AssetsTestCase): content_type = 'application/txt' upload_date = datetime(2013, 6, 1, 10, 30, tzinfo=UTC) asset_location = course.id.make_asset_key('asset', 'sample_static.html') - url = reverse_course_url('assets_handler', course.id, kwargs={'asset_key_string': unicode(asset_location)}) + url = reverse_course_url( + 'assets_handler', course.id, kwargs={'asset_key_string': six.text_type(asset_location)} + ) resp = self.client.post( url, @@ -513,7 +522,7 @@ class DeleteAssetTestCase(AssetsTestCase): def test_delete_asset(self): """ Tests the happy path :) """ test_url = reverse_course_url( - 'assets_handler', self.course.id, kwargs={'asset_key_string': unicode(self.uploaded_url)}) + 'assets_handler', self.course.id, kwargs={'asset_key_string': six.text_type(self.uploaded_url)}) resp = self.client.delete(test_url, HTTP_ACCEPT="application/json") self.assertEquals(resp.status_code, 204) @@ -542,21 +551,23 @@ class DeleteAssetTestCase(AssetsTestCase): mock_asset_key.return_value = thumbnail_location test_url = reverse_course_url( - 'assets_handler', self.course.id, kwargs={'asset_key_string': unicode(uploaded_image_url)}) + 'assets_handler', self.course.id, kwargs={'asset_key_string': six.text_type(uploaded_image_url)}) resp = self.client.delete(test_url, HTTP_ACCEPT="application/json") self.assertEquals(resp.status_code, 204) def test_delete_asset_with_invalid_asset(self): """ Tests the sad path :( """ test_url = reverse_course_url( - 'assets_handler', self.course.id, kwargs={'asset_key_string': unicode("/c4x/edX/toy/asset/invalid.pdf")}) + 'assets_handler', + self.course.id, kwargs={'asset_key_string': six.text_type("/c4x/edX/toy/asset/invalid.pdf")} + ) resp = self.client.delete(test_url, HTTP_ACCEPT="application/json") self.assertEquals(resp.status_code, 404) def test_delete_asset_with_invalid_thumbnail(self): """ Tests the sad path :( """ test_url = reverse_course_url( - 'assets_handler', self.course.id, kwargs={'asset_key_string': unicode(self.uploaded_url)}) + 'assets_handler', self.course.id, kwargs={'asset_key_string': six.text_type(self.uploaded_url)}) self.content.thumbnail_location = StaticContent.get_location_from_path('/c4x/edX/toy/asset/invalid') contentstore().save(self.content) resp = self.client.delete(test_url, HTTP_ACCEPT="application/json") diff --git a/cms/djangoapps/contentstore/views/tests/test_certificates.py b/cms/djangoapps/contentstore/views/tests/test_certificates.py index e315cf76fe..9f267c0a22 100644 --- a/cms/djangoapps/contentstore/views/tests/test_certificates.py +++ b/cms/djangoapps/contentstore/views/tests/test_certificates.py @@ -3,14 +3,18 @@ """ Certificates Tests. """ +from __future__ import absolute_import + import itertools import json import ddt import mock +import six from django.conf import settings from django.test.utils import override_settings from opaque_keys.edx.keys import AssetKey +from six.moves import range from contentstore.tests.utils import CourseTestCase from contentstore.utils import get_lms_link_for_certificate_web_view, reverse_course_url @@ -80,7 +84,7 @@ class HelperMethods(object): 'title': 'Title ' + str(i), 'signature_image_path': asset_path_format.format(i), 'id': i - } for i in xrange(signatory_count) + } for i in range(signatory_count) ] @@ -95,7 +99,7 @@ class HelperMethods(object): 'signatories': signatories, 'version': CERTIFICATE_SCHEMA_VERSION, 'is_active': is_active - } for i in xrange(count) + } for i in range(count) ] self.course.certificates = {'certificates': certificates} self.save_course() @@ -236,7 +240,7 @@ class CertificatesListHandlerTestCase( self.assertEqual(content, expected) self.assert_event_emitted( 'edx.certificate.configuration.created', - course_id=unicode(self.course.id), + course_id=six.text_type(self.course.id), configuration_id=certificate_id, ) @@ -265,7 +269,7 @@ class CertificatesListHandlerTestCase( @override_settings(LMS_BASE="lms_base_url") def test_lms_link_for_certificate_web_view(self): test_url = "//lms_base_url/certificates/user/" \ - + str(self.user.id) + "/course/" + unicode(self.course.id) + '?preview=honor' + + str(self.user.id) + "/course/" + six.text_type(self.course.id) + '?preview=honor' link = get_lms_link_for_certificate_web_view( user_id=self.user.id, course_key=self.course.id, @@ -471,7 +475,7 @@ class CertificatesDetailHandlerTestCase( self.assertEqual(content, expected) self.assert_event_emitted( 'edx.certificate.configuration.created', - course_id=unicode(self.course.id), + course_id=six.text_type(self.course.id), configuration_id=666, ) @@ -503,7 +507,7 @@ class CertificatesDetailHandlerTestCase( self.assertEqual(content, expected) self.assert_event_emitted( 'edx.certificate.configuration.modified', - course_id=unicode(self.course.id), + course_id=six.text_type(self.course.id), configuration_id=1, ) self.reload_course() @@ -568,7 +572,7 @@ class CertificatesDetailHandlerTestCase( self.assertEqual(response.status_code, 204) self.assert_event_emitted( 'edx.certificate.configuration.deleted', - course_id=unicode(self.course.id), + course_id=six.text_type(self.course.id), configuration_id='1', ) self.reload_course() @@ -592,7 +596,7 @@ class CertificatesDetailHandlerTestCase( self.assertEqual(response.status_code, 204) self.assert_event_emitted( 'edx.certificate.configuration.deleted', - course_id=unicode(self.course.id), + course_id=six.text_type(self.course.id), configuration_id='1', ) self.reload_course() @@ -617,7 +621,7 @@ class CertificatesDetailHandlerTestCase( self.assertEqual(response.status_code, 204) self.assert_event_emitted( 'edx.certificate.configuration.deleted', - course_id=unicode(self.course.id), + course_id=six.text_type(self.course.id), configuration_id='1', ) self.reload_course() @@ -785,7 +789,7 @@ class CertificatesDetailHandlerTestCase( cert_event_type = 'activated' if is_active else 'deactivated' self.assert_event_emitted( '.'.join(['edx.certificate.configuration', cert_event_type]), - course_id=unicode(self.course.id), + course_id=six.text_type(self.course.id), ) @ddt.data(*itertools.product([True, False], [C4X_SIGNATORY_PATH, SIGNATORY_PATH])) diff --git a/cms/djangoapps/contentstore/views/tests/test_course_index.py b/cms/djangoapps/contentstore/views/tests/test_course_index.py index d1f0154538..020b3bb2f0 100644 --- a/cms/djangoapps/contentstore/views/tests/test_course_index.py +++ b/cms/djangoapps/contentstore/views/tests/test_course_index.py @@ -1,6 +1,8 @@ """ Unit tests for getting the list of courses and the course outline. """ +from __future__ import absolute_import + import datetime import json @@ -8,24 +10,25 @@ import ddt import lxml import mock import pytz +import six from django.conf import settings from django.core.exceptions import PermissionDenied from django.test.utils import override_settings from django.utils.translation import ugettext as _ +from edx_django_utils.monitoring.middleware import _DEFAULT_NAMESPACE as DJANGO_UTILS_NAMESPACE from opaque_keys.edx.locator import CourseLocator from search.api import perform_search -from edx_django_utils.monitoring.middleware import _DEFAULT_NAMESPACE as DJANGO_UTILS_NAMESPACE +from contentstore.config.waffle import WAFFLE_NAMESPACE as STUDIO_WAFFLE_NAMESPACE from contentstore.courseware_index import CoursewareSearchIndexer, SearchIndexingError from contentstore.tests.utils import CourseTestCase from contentstore.utils import add_instructor, reverse_course_url, reverse_usage_url +from contentstore.views.course import WAFFLE_NAMESPACE as COURSE_WAFFLE_NAMESPACE from contentstore.views.course import ( _deprecated_blocks_info, course_outline_initial_state, reindex_course_and_check_access ) -from contentstore.config.waffle import WAFFLE_NAMESPACE as STUDIO_WAFFLE_NAMESPACE -from contentstore.views.course import WAFFLE_NAMESPACE as COURSE_WAFFLE_NAMESPACE from contentstore.views.item import VisibilityState, create_xblock_info from course_action_state.managers import CourseRerunUIStateManager from course_action_state.models import CourseRerunState @@ -143,7 +146,7 @@ class TestCourseIndex(CourseTestCase): # First spot check some values in the root response self.assertEqual(json_response['category'], 'course') - self.assertEqual(json_response['id'], unicode(self.course.location)) + self.assertEqual(json_response['id'], six.text_type(self.course.location)) self.assertEqual(json_response['display_name'], self.course.display_name) self.assertTrue(json_response['published']) self.assertIsNone(json_response['visibility_state']) @@ -153,7 +156,7 @@ class TestCourseIndex(CourseTestCase): self.assertGreater(len(children), 0) first_child_response = children[0] self.assertEqual(first_child_response['category'], 'chapter') - self.assertEqual(first_child_response['id'], unicode(chapter.location)) + self.assertEqual(first_child_response['id'], six.text_type(chapter.location)) self.assertEqual(first_child_response['display_name'], 'Week 1') self.assertTrue(json_response['published']) self.assertEqual(first_child_response['visibility_state'], VisibilityState.unscheduled) @@ -465,7 +468,7 @@ class TestCourseOutline(CourseTestCase): # First spot check some values in the root response self.assertEqual(json_response['category'], 'course') - self.assertEqual(json_response['id'], unicode(self.course.location)) + self.assertEqual(json_response['id'], six.text_type(self.course.location)) self.assertEqual(json_response['display_name'], self.course.display_name) self.assertNotEqual(json_response.get('published', False), is_concise) self.assertIsNone(json_response.get('visibility_state')) @@ -475,7 +478,7 @@ class TestCourseOutline(CourseTestCase): self.assertGreater(len(children), 0) first_child_response = children[0] self.assertEqual(first_child_response['category'], 'chapter') - self.assertEqual(first_child_response['id'], unicode(self.chapter.location)) + self.assertEqual(first_child_response['id'], six.text_type(self.chapter.location)) self.assertEqual(first_child_response['display_name'], 'Week 1') self.assertNotEqual(json_response.get('published', False), is_concise) if not is_concise: @@ -509,12 +512,12 @@ class TestCourseOutline(CourseTestCase): self.assertIsNone(course_outline_initial_state('no-such-locator', course_structure)) # Verify that the correct initial state is returned for the test chapter - chapter_locator = unicode(self.chapter.location) + chapter_locator = six.text_type(self.chapter.location) initial_state = course_outline_initial_state(chapter_locator, course_structure) self.assertEqual(initial_state['locator_to_show'], chapter_locator) expanded_locators = initial_state['expanded_locators'] - self.assertIn(unicode(self.sequential.location), expanded_locators) - self.assertIn(unicode(self.vertical.location), expanded_locators) + self.assertIn(six.text_type(self.sequential.location), expanded_locators) + self.assertIn(six.text_type(self.vertical.location), expanded_locators) def _create_test_data(self, course_module, create_blocks=False, publish=True, block_types=None): """ @@ -703,7 +706,7 @@ class TestCourseReIndex(CourseTestCase): user=self.user, size=10, from_=0, - course_id=unicode(self.course.id)) + course_id=six.text_type(self.course.id)) self.assertEqual(response['total'], 1) # Start manual reindex @@ -715,7 +718,7 @@ class TestCourseReIndex(CourseTestCase): user=self.user, size=10, from_=0, - course_id=unicode(self.course.id)) + course_id=six.text_type(self.course.id)) self.assertEqual(response['total'], 1) @mock.patch('xmodule.video_module.VideoBlock.index_dictionary') @@ -729,7 +732,7 @@ class TestCourseReIndex(CourseTestCase): user=self.user, size=10, from_=0, - course_id=unicode(self.course.id)) + course_id=six.text_type(self.course.id)) self.assertEqual(response['total'], 1) # set mocked exception response @@ -751,7 +754,7 @@ class TestCourseReIndex(CourseTestCase): user=self.user, size=10, from_=0, - course_id=unicode(self.course.id)) + course_id=six.text_type(self.course.id)) self.assertEqual(response['total'], 1) # set mocked exception response @@ -773,7 +776,7 @@ class TestCourseReIndex(CourseTestCase): user=self.user, size=10, from_=0, - course_id=unicode(self.course.id)) + course_id=six.text_type(self.course.id)) self.assertEqual(response['total'], 1) # set mocked exception response @@ -813,7 +816,7 @@ class TestCourseReIndex(CourseTestCase): user=self.user, size=10, from_=0, - course_id=unicode(self.course.id)) + course_id=six.text_type(self.course.id)) self.assertEqual(response['total'], 1) # Start manual reindex @@ -825,7 +828,7 @@ class TestCourseReIndex(CourseTestCase): user=self.user, size=10, from_=0, - course_id=unicode(self.course.id)) + course_id=six.text_type(self.course.id)) self.assertEqual(response['total'], 1) @mock.patch('xmodule.video_module.VideoBlock.index_dictionary') @@ -839,7 +842,7 @@ class TestCourseReIndex(CourseTestCase): user=self.user, size=10, from_=0, - course_id=unicode(self.course.id)) + course_id=six.text_type(self.course.id)) self.assertEqual(response['total'], 1) # set mocked exception response @@ -861,7 +864,7 @@ class TestCourseReIndex(CourseTestCase): user=self.user, size=10, from_=0, - course_id=unicode(self.course.id)) + course_id=six.text_type(self.course.id)) self.assertEqual(response['total'], 1) # set mocked exception response @@ -883,7 +886,7 @@ class TestCourseReIndex(CourseTestCase): user=self.user, size=10, from_=0, - course_id=unicode(self.course.id)) + course_id=six.text_type(self.course.id)) self.assertEqual(response['total'], 1) # set mocked exception response diff --git a/cms/djangoapps/contentstore/views/tests/test_helpers.py b/cms/djangoapps/contentstore/views/tests/test_helpers.py index ace156d281..e141adcd62 100644 --- a/cms/djangoapps/contentstore/views/tests/test_helpers.py +++ b/cms/djangoapps/contentstore/views/tests/test_helpers.py @@ -2,6 +2,9 @@ Unit tests for helpers.py. """ +from __future__ import absolute_import + +import six from django.utils import http from contentstore.tests.utils import CourseTestCase @@ -17,7 +20,7 @@ class HelpersTestCase(CourseTestCase): def test_xblock_studio_url(self): # Verify course URL - course_url = u'/course/{}'.format(unicode(self.course.id)) + course_url = u'/course/{}'.format(six.text_type(self.course.id)) self.assertEqual(xblock_studio_url(self.course), course_url) # Verify chapter URL @@ -53,7 +56,7 @@ class HelpersTestCase(CourseTestCase): # Verify library URL library = LibraryFactory.create() - expected_url = u'/library/{}'.format(unicode(library.location.library_key)) + expected_url = u'/library/{}'.format(six.text_type(library.location.library_key)) self.assertEqual(xblock_studio_url(library), expected_url) def test_xblock_type_display_name(self): diff --git a/cms/djangoapps/contentstore/views/tests/test_import_export.py b/cms/djangoapps/contentstore/views/tests/test_import_export.py index e2162d7840..462fe67e0c 100644 --- a/cms/djangoapps/contentstore/views/tests/test_import_export.py +++ b/cms/djangoapps/contentstore/views/tests/test_import_export.py @@ -1,6 +1,8 @@ """ Unit tests for course import and export """ +from __future__ import absolute_import + import copy import json import logging @@ -14,6 +16,7 @@ from uuid import uuid4 import ddt import lxml +import six from django.conf import settings from django.core.files.storage import FileSystemStorage from django.test.utils import override_settings @@ -21,6 +24,7 @@ from milestones.tests.utils import MilestonesTestCaseMixin from mock import Mock, patch from opaque_keys.edx.locator import LibraryLocator from path import Path as path +from six.moves import zip from storages.backends.s3boto import S3BotoStorage from user_tasks.models import UserTaskStatus @@ -103,7 +107,7 @@ class ImportEntranceExamTestCase(CourseTestCase, MilestonesTestCaseMixin): """ Check that pre existed entrance exam content should be overwrite with the imported course. """ - exam_url = '/course/{}/entrance_exam/'.format(unicode(self.course.id)) + exam_url = '/course/{}/entrance_exam/'.format(six.text_type(self.course.id)) resp = self.client.post(exam_url, {'entrance_exam_minimum_score_pct': 0.5}, http_accept='application/json') self.assertEqual(resp.status_code, 201) @@ -113,9 +117,9 @@ class ImportEntranceExamTestCase(CourseTestCase, MilestonesTestCaseMixin): self.assertTrue(metadata['entrance_exam_enabled']) self.assertIsNotNone(metadata['entrance_exam_minimum_score_pct']) self.assertEqual(metadata['entrance_exam_minimum_score_pct']['value'], 0.5) - self.assertTrue(len(milestones_helpers.get_course_milestones(unicode(self.course.id)))) + self.assertTrue(len(milestones_helpers.get_course_milestones(six.text_type(self.course.id)))) content_milestones = milestones_helpers.get_course_content_milestones( - unicode(self.course.id), + six.text_type(self.course.id), metadata['entrance_exam_id']['value'], milestones_helpers.get_milestone_relationship_types()['FULFILLS'] ) @@ -149,7 +153,7 @@ class ImportTestCase(CourseTestCase): def touch(name): """ Equivalent to shell's 'touch'""" - with file(name, 'a'): + with open(name, 'a'): # pylint: disable=W6005 os.utime(name, None) # Create tar test files ----------------------------------------------- diff --git a/cms/djangoapps/contentstore/views/tests/test_preview.py b/cms/djangoapps/contentstore/views/tests/test_preview.py index 07d1a208ae..4aa284ecd9 100644 --- a/cms/djangoapps/contentstore/views/tests/test_preview.py +++ b/cms/djangoapps/contentstore/views/tests/test_preview.py @@ -1,10 +1,13 @@ """ Tests for contentstore.views.preview.py """ +from __future__ import absolute_import + import re import ddt import mock +import six from django.test.client import Client, RequestFactory from xblock.core import XBlock, XBlockAside @@ -56,7 +59,9 @@ class GetPreviewHtmlTestCase(ModuleStoreTestCase): html = get_preview_fragment(request, html, context).content # Verify student view html is returned, and the usage ID is as expected. - html_pattern = re.escape(unicode(course.id.make_usage_key('html', 'replaceme'))).replace('replaceme', r'html_[0-9]*') + html_pattern = re.escape( + six.text_type(course.id.make_usage_key('html', 'replaceme')) + ).replace('replaceme', r'html_[0-9]*') self.assertRegexpMatches( html, 'data-usage-id="{}"'.format(html_pattern) diff --git a/cms/djangoapps/contentstore/views/tests/test_textbooks.py b/cms/djangoapps/contentstore/views/tests/test_textbooks.py index 5b6076f49d..72e02d5668 100644 --- a/cms/djangoapps/contentstore/views/tests/test_textbooks.py +++ b/cms/djangoapps/contentstore/views/tests/test_textbooks.py @@ -1,3 +1,7 @@ +""" Test cases for the textbook index page. """ + +from __future__ import absolute_import + import json from unittest import TestCase diff --git a/cms/djangoapps/contentstore/views/tests/test_user.py b/cms/djangoapps/contentstore/views/tests/test_user.py index a2bd27b514..502ff0f676 100644 --- a/cms/djangoapps/contentstore/views/tests/test_user.py +++ b/cms/djangoapps/contentstore/views/tests/test_user.py @@ -1,6 +1,8 @@ """ Tests for contentstore/views/user.py. """ +from __future__ import absolute_import + import json from django.contrib.auth.models import User