From 293546640819012ef13ef768193c5962e2f95ebb Mon Sep 17 00:00:00 2001 From: Michael Youngstrom Date: Thu, 25 Apr 2019 09:47:14 -0400 Subject: [PATCH] INCR-120 --- .../content/block_structure/tests/helpers.py | 16 +++++++----- .../tests/test_block_structure.py | 18 ++++++++----- .../block_structure/tests/test_factory.py | 9 ++++--- .../block_structure/tests/test_manager.py | 16 ++++++++---- .../block_structure/tests/test_models.py | 26 +++++++++++-------- .../block_structure/tests/test_signals.py | 4 ++- .../block_structure/tests/test_store.py | 4 ++- .../block_structure/tests/test_tasks.py | 2 ++ .../tests/test_transformer_registry.py | 7 +++-- .../tests/test_transformers.py | 11 ++++---- 10 files changed, 71 insertions(+), 42 deletions(-) diff --git a/openedx/core/djangoapps/content/block_structure/tests/helpers.py b/openedx/core/djangoapps/content/block_structure/tests/helpers.py index bd37e0c51e..931055827c 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/helpers.py +++ b/openedx/core/djangoapps/content/block_structure/tests/helpers.py @@ -1,12 +1,16 @@ """ Common utilities for tests in block_structure module """ +from __future__ import absolute_import + from contextlib import contextmanager -from mock import patch -from xmodule.modulestore.exceptions import ItemNotFoundError from uuid import uuid4 -from opaque_keys.edx.locator import CourseLocator, BlockUsageLocator +import six +from mock import patch +from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator + +from xmodule.modulestore.exceptions import ItemNotFoundError from ..api import get_cache from ..block_structure import BlockStructureBlockData @@ -304,7 +308,7 @@ class ChildrenMapTestMixin(object): self.block_key_factory(block_key) in block_structure, block_key not in missing_blocks, u'Expected presence in block_structure for block_key {} to match absence in missing_blocks.'.format( - unicode(block_key) + six.text_type(block_key) ), ) @@ -333,10 +337,10 @@ class UsageKeyFactoryMixin(object): """ def setUp(self): super(UsageKeyFactoryMixin, self).setUp() - self.course_key = CourseLocator('org', 'course', unicode(uuid4())) + self.course_key = CourseLocator('org', 'course', six.text_type(uuid4())) def block_key_factory(self, block_id): """ Returns a block key object for the given block_id. """ - return BlockUsageLocator(course_key=self.course_key, block_type='course', block_id=unicode(block_id)) + return BlockUsageLocator(course_key=self.course_key, block_type='course', block_id=six.text_type(block_id)) diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_block_structure.py b/openedx/core/djangoapps/content/block_structure/tests/test_block_structure.py index 5b19670fbb..cba1fe43f1 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/test_block_structure.py +++ b/openedx/core/djangoapps/content/block_structure/tests/test_block_structure.py @@ -1,20 +1,24 @@ """ Tests for block_structure.py """ -from datetime import datetime +from __future__ import absolute_import + +import itertools # pylint: disable=protected-access from collections import namedtuple from copy import deepcopy -import itertools +from datetime import datetime from unittest import TestCase import ddt +import six +from six.moves import range from openedx.core.lib.graph_traversals import traverse_post_order from ..block_structure import BlockStructure, BlockStructureModulestoreData from ..exceptions import TransformerException -from .helpers import MockXBlock, MockTransformer, ChildrenMapTestMixin +from .helpers import ChildrenMapTestMixin, MockTransformer, MockXBlock @ddt.ddt @@ -97,7 +101,7 @@ class TestBlockStructureData(TestCase, ChildrenMapTestMixin): block_structure._add_transformer(t_info.transformer) for key, val in t_info.structure_wide_data: block_structure.set_transformer_data(t_info.transformer, key, val) - for block, block_data in t_info.block_specific_data.iteritems(): + for block, block_data in six.iteritems(t_info.block_specific_data): for key, val in block_data: block_structure.set_transformer_block_field(block, t_info.transformer, key, val) @@ -112,7 +116,7 @@ class TestBlockStructureData(TestCase, ChildrenMapTestMixin): block_structure.get_transformer_data(t_info.transformer, key), val, ) - for block, block_data in t_info.block_specific_data.iteritems(): + for block, block_data in six.iteritems(t_info.block_specific_data): for key, val in block_data: self.assertEquals( block_structure.get_transformer_block_field(block, t_info.transformer, key), @@ -172,7 +176,7 @@ class TestBlockStructureData(TestCase, ChildrenMapTestMixin): block_structure._add_xblock(block.location, block) block_structure._get_or_create_block(block.location) - fields = attribute.keys() + fields = list(attribute.keys()) block_structure.request_xblock_fields(*fields) # collect fields @@ -199,7 +203,7 @@ class TestBlockStructureData(TestCase, ChildrenMapTestMixin): @ddt.data( *itertools.product( [True, False], - range(7), + list(range(7)), [ ChildrenMapTestMixin.SIMPLE_CHILDREN_MAP, ChildrenMapTestMixin.LINEAR_CHILDREN_MAP, diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_factory.py b/openedx/core/djangoapps/content/block_structure/tests/test_factory.py index 15f10cc5e2..f6524f7d02 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/test_factory.py +++ b/openedx/core/djangoapps/content/block_structure/tests/test_factory.py @@ -1,15 +1,16 @@ """ Tests for block_structure_factory.py """ +from __future__ import absolute_import + from django.test import TestCase + from xmodule.modulestore.exceptions import ItemNotFoundError -from ..store import BlockStructureStore from ..exceptions import BlockStructureNotFound from ..factory import BlockStructureFactory -from .helpers import ( - MockCache, MockModulestoreFactory, ChildrenMapTestMixin -) +from ..store import BlockStructureStore +from .helpers import ChildrenMapTestMixin, MockCache, MockModulestoreFactory class TestBlockStructureFactory(TestCase, ChildrenMapTestMixin): diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_manager.py b/openedx/core/djangoapps/content/block_structure/tests/test_manager.py index 5c657c1193..1bdab3a174 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/test_manager.py +++ b/openedx/core/djangoapps/content/block_structure/tests/test_manager.py @@ -1,18 +1,24 @@ """ Tests for manager.py """ +from __future__ import absolute_import + import ddt +import six from django.test import TestCase from ..block_structure import BlockStructureBlockData from ..config import RAISE_ERROR_WHEN_NOT_FOUND, STORAGE_BACKING_FOR_CACHE, waffle -from ..exceptions import UsageKeyNotInBlockStructure, BlockStructureNotFound +from ..exceptions import BlockStructureNotFound, UsageKeyNotInBlockStructure from ..manager import BlockStructureManager from ..transformers import BlockStructureTransformers from .helpers import ( - MockModulestoreFactory, MockCache, MockTransformer, - ChildrenMapTestMixin, UsageKeyFactoryMixin, - mock_registered_transformers, + ChildrenMapTestMixin, + MockCache, + MockModulestoreFactory, + MockTransformer, + UsageKeyFactoryMixin, + mock_registered_transformers ) @@ -85,7 +91,7 @@ class TestTransformer1(MockTransformer): Returns a unique deterministic value for the given block key and data key. """ - return data_key + 't1.val1.' + unicode(block_key) + return data_key + 't1.val1.' + six.text_type(block_key) @ddt.ddt diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_models.py b/openedx/core/djangoapps/content/block_structure/tests/test_models.py index 343fe823db..227101af73 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/test_models.py +++ b/openedx/core/djangoapps/content/block_structure/tests/test_models.py @@ -2,16 +2,20 @@ Unit tests for Block Structure models. """ # pylint: disable=protected-access +from __future__ import absolute_import + +from itertools import product +from uuid import uuid4 + import ddt +import six +from six.moves import range from django.conf import settings from django.core.exceptions import SuspiciousOperation from django.test import TestCase from django.utils.timezone import now -from itertools import product -from mock import patch, Mock -from uuid import uuid4 - -from opaque_keys.edx.locator import CourseLocator, BlockUsageLocator +from mock import Mock, patch +from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator from ..exceptions import BlockStructureNotFound from ..models import BlockStructureModel, _directory_name, _storage_error_handling @@ -24,7 +28,7 @@ class BlockStructureModelTestCase(TestCase): """ def setUp(self): super(BlockStructureModelTestCase, self).setUp() - self.course_key = CourseLocator('org', 'course', unicode(uuid4())) + self.course_key = CourseLocator('org', 'course', six.text_type(uuid4())) self.usage_key = BlockUsageLocator(course_key=self.course_key, block_type='course', block_id='course') self.params = self._create_bsm_params() @@ -38,7 +42,7 @@ class BlockStructureModelTestCase(TestCase): Verifies that the field values and serialized data on the given bsm are as expected. """ - for field_name, field_value in self.params.iteritems(): + for field_name, field_value in six.iteritems(self.params): self.assertEqual(field_value, getattr(bsm, field_name)) self.assertEqual(bsm.get_serialized_data(), expected_serialized_data) @@ -60,7 +64,7 @@ class BlockStructureModelTestCase(TestCase): data_version='DV', data_edit_timestamp=now(), transformers_schema_version='TV', - block_structure_schema_version=unicode(1), + block_structure_schema_version=six.text_type(1), ) def _verify_update_or_create_call(self, serialized_data, mock_log=None, expect_created=None): @@ -123,8 +127,8 @@ class BlockStructureModelTestCase(TestCase): @ddt.data( *product( - range(1, 3), # prune_keep_count - range(4), # num_prior_edits + list(range(1, 3)), # prune_keep_count + list(range(4)), # num_prior_edits ) ) @ddt.unpack @@ -159,7 +163,7 @@ class BlockStructureModelTestCase(TestCase): @patch('openedx.core.djangoapps.content.block_structure.models.log') def test_old_mongo_keys(self, mock_log): - self.course_key = CourseLocator('org2', 'course2', unicode(uuid4()), deprecated=True) + self.course_key = CourseLocator('org2', 'course2', six.text_type(uuid4()), deprecated=True) self.usage_key = BlockUsageLocator(course_key=self.course_key, block_type='course', block_id='course') serialized_data = 'test data for old course' self.params['data_usage_key'] = self.usage_key diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_signals.py b/openedx/core/djangoapps/content/block_structure/tests/test_signals.py index 1c23f3319e..65f461eabd 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/test_signals.py +++ b/openedx/core/djangoapps/content/block_structure/tests/test_signals.py @@ -1,10 +1,12 @@ """ Unit tests for the Course Blocks signals """ +from __future__ import absolute_import + import ddt from mock import patch +from opaque_keys.edx.locator import CourseLocator, LibraryLocator -from opaque_keys.edx.locator import LibraryLocator, CourseLocator from xmodule.modulestore.exceptions import ItemNotFoundError from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_store.py b/openedx/core/djangoapps/content/block_structure/tests/test_store.py index 52241cd414..eb67e855b0 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/test_store.py +++ b/openedx/core/djangoapps/content/block_structure/tests/test_store.py @@ -1,6 +1,8 @@ """ Tests for block_structure/cache.py """ +from __future__ import absolute_import + import ddt from openedx.core.djangolib.testing.utils import CacheIsolationTestCase @@ -9,7 +11,7 @@ from ..config import STORAGE_BACKING_FOR_CACHE, waffle from ..config.models import BlockStructureConfiguration from ..exceptions import BlockStructureNotFound from ..store import BlockStructureStore -from .helpers import ChildrenMapTestMixin, UsageKeyFactoryMixin, MockCache, MockTransformer +from .helpers import ChildrenMapTestMixin, MockCache, MockTransformer, UsageKeyFactoryMixin @ddt.ddt diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_tasks.py b/openedx/core/djangoapps/content/block_structure/tests/test_tasks.py index a4d3bf2f3b..d36efe3734 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/test_tasks.py +++ b/openedx/core/djangoapps/content/block_structure/tests/test_tasks.py @@ -2,6 +2,8 @@ Unit tests for the Course Blocks tasks """ +from __future__ import absolute_import + from mock import patch from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_transformer_registry.py b/openedx/core/djangoapps/content/block_structure/tests/test_transformer_registry.py index 4a1ad21567..49b7b39928 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/test_transformer_registry.py +++ b/openedx/core/djangoapps/content/block_structure/tests/test_transformer_registry.py @@ -2,11 +2,14 @@ Tests for transformer_registry.py """ -import ddt +from __future__ import absolute_import + from unittest import TestCase +import ddt + from ..transformer_registry import TransformerRegistry -from .helpers import MockTransformer, mock_registered_transformers, clear_registered_transformers_cache +from .helpers import MockTransformer, clear_registered_transformers_cache, mock_registered_transformers class TestTransformer1(MockTransformer): diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_transformers.py b/openedx/core/djangoapps/content/block_structure/tests/test_transformers.py index adcfe52936..7911d6b273 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/test_transformers.py +++ b/openedx/core/djangoapps/content/block_structure/tests/test_transformers.py @@ -1,15 +1,16 @@ """ Tests for transformers.py """ -from mock import MagicMock, patch +from __future__ import absolute_import + from unittest import TestCase +from mock import MagicMock, patch + from ..block_structure import BlockStructureModulestoreData -from ..exceptions import TransformerException, TransformerDataIncompatible +from ..exceptions import TransformerDataIncompatible, TransformerException from ..transformers import BlockStructureTransformers -from .helpers import ( - ChildrenMapTestMixin, MockTransformer, MockFilteringTransformer, mock_registered_transformers -) +from .helpers import ChildrenMapTestMixin, MockFilteringTransformer, MockTransformer, mock_registered_transformers class TestBlockStructureTransformers(ChildrenMapTestMixin, TestCase):