From 467eb70f50095ab9b30bda5e9106645c3b96d07f Mon Sep 17 00:00:00 2001 From: amitvadhel Date: Fri, 10 May 2019 12:13:17 +0300 Subject: [PATCH] INCR-141: Run python-modernize on openedx/core/djangoapps/content/block_structure [migrations, management, config] --- .../djangoapps/content/block_structure/config/__init__.py | 2 ++ .../djangoapps/content/block_structure/config/models.py | 2 ++ .../management/commands/generate_course_blocks.py | 7 +++++-- .../commands/tests/test_generate_course_blocks.py | 8 ++++++-- .../content/block_structure/migrations/0001_config.py | 2 +- .../migrations/0002_blockstructuremodel.py | 2 +- .../migrations/0003_blockstructuremodel_storage.py | 2 +- .../0004_blockstructuremodel_usagekeywithrun.py | 2 +- 8 files changed, 19 insertions(+), 8 deletions(-) diff --git a/openedx/core/djangoapps/content/block_structure/config/__init__.py b/openedx/core/djangoapps/content/block_structure/config/__init__.py index 063fa4de53..e6a9494d35 100644 --- a/openedx/core/djangoapps/content/block_structure/config/__init__.py +++ b/openedx/core/djangoapps/content/block_structure/config/__init__.py @@ -2,6 +2,8 @@ This module contains various configuration settings via waffle switches for the Block Structure framework. """ +from __future__ import absolute_import + from openedx.core.djangoapps.waffle_utils import WaffleSwitchNamespace from openedx.core.lib.cache_utils import request_cached diff --git a/openedx/core/djangoapps/content/block_structure/config/models.py b/openedx/core/djangoapps/content/block_structure/config/models.py index b8db5e25eb..2e68045112 100644 --- a/openedx/core/djangoapps/content/block_structure/config/models.py +++ b/openedx/core/djangoapps/content/block_structure/config/models.py @@ -1,6 +1,8 @@ """ Models for configuration of Block Structures. """ +from __future__ import absolute_import + from django.db.models import IntegerField from config_models.models import ConfigurationModel diff --git a/openedx/core/djangoapps/content/block_structure/management/commands/generate_course_blocks.py b/openedx/core/djangoapps/content/block_structure/management/commands/generate_course_blocks.py index 4d7bef61ef..3cf2b7d562 100644 --- a/openedx/core/djangoapps/content/block_structure/management/commands/generate_course_blocks.py +++ b/openedx/core/djangoapps/content/block_structure/management/commands/generate_course_blocks.py @@ -1,9 +1,12 @@ """ Command to load course blocks. """ +from __future__ import absolute_import + import logging from django.core.management.base import BaseCommand +import six from six import text_type from xmodule.modulestore.django import modulestore @@ -136,7 +139,7 @@ class Command(BaseCommand): except Exception as ex: # pylint: disable=broad-except log.exception( u'BlockStructure: An error occurred while generating course blocks for %s: %s', - unicode(course_key), + six.text_type(course_key), text_type(ex), ) @@ -148,7 +151,7 @@ class Command(BaseCommand): action = tasks.update_course_in_cache_v2 if options.get('force_update') else tasks.get_course_in_cache_v2 task_options = {'routing_key': options['routing_key']} if options.get('routing_key') else {} result = action.apply_async( - kwargs=dict(course_id=unicode(course_key), with_storage=options.get('with_storage')), + kwargs=dict(course_id=six.text_type(course_key), with_storage=options.get('with_storage')), **task_options ) log.info(u'BlockStructure: ENQUEUED generating for course: %s, task_id: %s.', course_key, result.id) diff --git a/openedx/core/djangoapps/content/block_structure/management/commands/tests/test_generate_course_blocks.py b/openedx/core/djangoapps/content/block_structure/management/commands/tests/test_generate_course_blocks.py index 3de601b239..650ee7df61 100644 --- a/openedx/core/djangoapps/content/block_structure/management/commands/tests/test_generate_course_blocks.py +++ b/openedx/core/djangoapps/content/block_structure/management/commands/tests/test_generate_course_blocks.py @@ -1,9 +1,13 @@ """ Tests for generate_course_blocks management command. """ +from __future__ import absolute_import + import ddt from django.core.management.base import CommandError import itertools +import six +from six.moves import range from mock import patch from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase @@ -82,13 +86,13 @@ class TestGenerateCourseBlocks(ModuleStoreTestCase): def test_one_course(self): self._assert_courses_not_in_block_cache(*self.course_keys) - self.command.handle(courses=[unicode(self.course_keys[0])]) + self.command.handle(courses=[six.text_type(self.course_keys[0])]) self._assert_courses_in_block_cache(self.course_keys[0]) self._assert_courses_not_in_block_cache(*self.course_keys[1:]) self._assert_courses_not_in_block_storage(*self.course_keys) def test_with_storage(self): - self.command.handle(with_storage=True, courses=[unicode(self.course_keys[0])]) + self.command.handle(with_storage=True, courses=[six.text_type(self.course_keys[0])]) self._assert_courses_in_block_cache(self.course_keys[0]) self._assert_courses_in_block_storage(self.course_keys[0]) self._assert_courses_not_in_block_storage(*self.course_keys[1:]) diff --git a/openedx/core/djangoapps/content/block_structure/migrations/0001_config.py b/openedx/core/djangoapps/content/block_structure/migrations/0001_config.py index 24a675dcfb..1d2fc9a9f9 100644 --- a/openedx/core/djangoapps/content/block_structure/migrations/0001_config.py +++ b/openedx/core/djangoapps/content/block_structure/migrations/0001_config.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals from django.db import migrations, models import django.db.models.deletion diff --git a/openedx/core/djangoapps/content/block_structure/migrations/0002_blockstructuremodel.py b/openedx/core/djangoapps/content/block_structure/migrations/0002_blockstructuremodel.py index a1ec8e2862..d1f69f22ea 100644 --- a/openedx/core/djangoapps/content/block_structure/migrations/0002_blockstructuremodel.py +++ b/openedx/core/djangoapps/content/block_structure/migrations/0002_blockstructuremodel.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals from django.db import migrations, models import django.utils.timezone diff --git a/openedx/core/djangoapps/content/block_structure/migrations/0003_blockstructuremodel_storage.py b/openedx/core/djangoapps/content/block_structure/migrations/0003_blockstructuremodel_storage.py index ce13688f22..68786cd80f 100644 --- a/openedx/core/djangoapps/content/block_structure/migrations/0003_blockstructuremodel_storage.py +++ b/openedx/core/djangoapps/content/block_structure/migrations/0003_blockstructuremodel_storage.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals from django.db import migrations, models import openedx.core.djangoapps.content.block_structure.models diff --git a/openedx/core/djangoapps/content/block_structure/migrations/0004_blockstructuremodel_usagekeywithrun.py b/openedx/core/djangoapps/content/block_structure/migrations/0004_blockstructuremodel_usagekeywithrun.py index 670a8ae8bd..6ea7b0cb47 100644 --- a/openedx/core/djangoapps/content/block_structure/migrations/0004_blockstructuremodel_usagekeywithrun.py +++ b/openedx/core/djangoapps/content/block_structure/migrations/0004_blockstructuremodel_usagekeywithrun.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals from django.db import migrations, models import openedx.core.djangoapps.xmodule_django.models