From c5b99ec035f59e43f66d1d523f65af8262487b3d Mon Sep 17 00:00:00 2001 From: Michael Youngstrom Date: Thu, 28 Mar 2019 10:15:08 -0400 Subject: [PATCH] python-modernize and isort --- .../catalog/management/commands/cache_programs.py | 3 ++- .../commands/create_catalog_integrations.py | 1 + .../catalog/management/commands/sync_course_runs.py | 4 +++- .../management/commands/tests/test_cache_programs.py | 8 ++++++-- .../tests/test_create_catalog_integrations.py | 1 + .../commands/tests/test_sync_course_runs.py | 4 +++- .../djangoapps/catalog/migrations/0001_initial.py | 4 ++-- .../migrations/0002_catalogintegration_username.py | 2 +- .../migrations/0003_catalogintegration_page_size.py | 2 +- .../catalog/migrations/0004_auto_20170616_0618.py | 2 +- .../0005_catalogintegration_long_term_cache_ttl.py | 2 +- openedx/core/djangoapps/catalog/tests/factories.py | 5 +++-- openedx/core/djangoapps/catalog/tests/mixins.py | 2 ++ openedx/core/djangoapps/catalog/tests/test_models.py | 2 ++ openedx/core/djangoapps/catalog/tests/test_utils.py | 11 +++++++---- 15 files changed, 36 insertions(+), 17 deletions(-) diff --git a/openedx/core/djangoapps/catalog/management/commands/cache_programs.py b/openedx/core/djangoapps/catalog/management/commands/cache_programs.py index 5388ccc855..b8c64f7424 100644 --- a/openedx/core/djangoapps/catalog/management/commands/cache_programs.py +++ b/openedx/core/djangoapps/catalog/management/commands/cache_programs.py @@ -1,4 +1,5 @@ """"Management command to add program information to the cache.""" +from __future__ import absolute_import from collections import defaultdict import logging import sys @@ -84,7 +85,7 @@ class Command(BaseCommand): )) cache.set(SITE_PROGRAM_UUIDS_CACHE_KEY_TPL.format(domain=site.domain), uuids, None) - pathway_ids = new_pathways.keys() + pathway_ids = list(new_pathways.keys()) logger.info(u'Caching ids for {total} pathways for site {site_name}.'.format( total=len(pathway_ids), site_name=site.domain, diff --git a/openedx/core/djangoapps/catalog/management/commands/create_catalog_integrations.py b/openedx/core/djangoapps/catalog/management/commands/create_catalog_integrations.py index f85b3e2ece..f533082e4d 100644 --- a/openedx/core/djangoapps/catalog/management/commands/create_catalog_integrations.py +++ b/openedx/core/djangoapps/catalog/management/commands/create_catalog_integrations.py @@ -1,5 +1,6 @@ '''CatalogIntegration management command''' +from __future__ import absolute_import from django.core.management import BaseCommand, CommandError from openedx.core.djangoapps.catalog.models import CatalogIntegration diff --git a/openedx/core/djangoapps/catalog/management/commands/sync_course_runs.py b/openedx/core/djangoapps/catalog/management/commands/sync_course_runs.py index 86ae6540a7..f9bceac94e 100644 --- a/openedx/core/djangoapps/catalog/management/commands/sync_course_runs.py +++ b/openedx/core/djangoapps/catalog/management/commands/sync_course_runs.py @@ -1,6 +1,7 @@ """ Sync course runs from catalog service. """ +from __future__ import absolute_import from collections import namedtuple import logging @@ -9,6 +10,7 @@ from opaque_keys.edx.keys import CourseKey from openedx.core.djangoapps.catalog.utils import get_course_runs from openedx.core.djangoapps.content.course_overviews.models import CourseOverview +import six log = logging.getLogger(__name__) @@ -43,7 +45,7 @@ class Command(BaseCommand): except CourseOverview.DoesNotExist: log.info( u'[sync_course_runs] course overview record not found for course run: %s', - unicode(course_key), + six.text_type(course_key), ) continue diff --git a/openedx/core/djangoapps/catalog/management/commands/tests/test_cache_programs.py b/openedx/core/djangoapps/catalog/management/commands/tests/test_cache_programs.py index 499fd00ed3..062e1ea149 100644 --- a/openedx/core/djangoapps/catalog/management/commands/tests/test_cache_programs.py +++ b/openedx/core/djangoapps/catalog/management/commands/tests/test_cache_programs.py @@ -1,3 +1,7 @@ +""" +Test cases for cache_programs command. +""" +from __future__ import absolute_import import json import httpretty @@ -192,7 +196,7 @@ class TestCachePrograms(CatalogIntegrationMixin, CacheIsolationTestCase, SiteMix call_command('cache_programs') cached_pathway_keys = cache.get(SITE_PATHWAY_IDS_CACHE_KEY_TPL.format(domain=self.site_domain)) - pathway_keys = pathways.keys() + pathway_keys = list(pathways.keys()) self.assertEqual( set(cached_pathway_keys), set(pathway_keys) @@ -244,7 +248,7 @@ class TestCachePrograms(CatalogIntegrationMixin, CacheIsolationTestCase, SiteMix pathways_dict = { PATHWAY_CACHE_KEY_TPL.format(id=pathway['id']): pathway for pathway in pathways } - pathway_keys = pathways_dict.keys() + pathway_keys = list(pathways_dict.keys()) cached_pathway_keys = cache.get(SITE_PATHWAY_IDS_CACHE_KEY_TPL.format(domain=self.site_domain)) self.assertEqual( diff --git a/openedx/core/djangoapps/catalog/management/commands/tests/test_create_catalog_integrations.py b/openedx/core/djangoapps/catalog/management/commands/tests/test_create_catalog_integrations.py index a777669854..84923a3d75 100644 --- a/openedx/core/djangoapps/catalog/management/commands/tests/test_create_catalog_integrations.py +++ b/openedx/core/djangoapps/catalog/management/commands/tests/test_create_catalog_integrations.py @@ -1,6 +1,7 @@ """ Test cases for catalog_integrations command. """ +from __future__ import absolute_import from django.test import TestCase from django.core.management import call_command, CommandError diff --git a/openedx/core/djangoapps/catalog/management/commands/tests/test_sync_course_runs.py b/openedx/core/djangoapps/catalog/management/commands/tests/test_sync_course_runs.py index b8492bbbe2..454af59416 100644 --- a/openedx/core/djangoapps/catalog/management/commands/tests/test_sync_course_runs.py +++ b/openedx/core/djangoapps/catalog/management/commands/tests/test_sync_course_runs.py @@ -1,6 +1,7 @@ """ Tests for the sync course runs management command. """ +from __future__ import absolute_import import ddt import mock @@ -11,6 +12,7 @@ from openedx.core.djangoapps.catalog.management.commands.sync_course_runs import from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory +import six COMMAND_MODULE = 'openedx.core.djangoapps.catalog.management.commands.sync_course_runs' @@ -29,7 +31,7 @@ class TestSyncCourseRunsCommand(ModuleStoreTestCase): self.course_overview = CourseOverview.get_from_id(self.course.id) # create a catalog course run with the same course id. self.catalog_course_run = CourseRunFactory( - key=unicode(self.course.id), + key=six.text_type(self.course.id), marketing_url='test_marketing_url', eligible_for_financial_aid=False ) diff --git a/openedx/core/djangoapps/catalog/migrations/0001_initial.py b/openedx/core/djangoapps/catalog/migrations/0001_initial.py index 4c934f57ac..07a020a8e1 100644 --- a/openedx/core/djangoapps/catalog/migrations/0001_initial.py +++ b/openedx/core/djangoapps/catalog/migrations/0001_initial.py @@ -1,9 +1,9 @@ # -*- 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 from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/catalog/migrations/0002_catalogintegration_username.py b/openedx/core/djangoapps/catalog/migrations/0002_catalogintegration_username.py index 26218c13ba..a81f73c5d1 100644 --- a/openedx/core/djangoapps/catalog/migrations/0002_catalogintegration_username.py +++ b/openedx/core/djangoapps/catalog/migrations/0002_catalogintegration_username.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 diff --git a/openedx/core/djangoapps/catalog/migrations/0003_catalogintegration_page_size.py b/openedx/core/djangoapps/catalog/migrations/0003_catalogintegration_page_size.py index 567c60fcf9..1a2f026d29 100644 --- a/openedx/core/djangoapps/catalog/migrations/0003_catalogintegration_page_size.py +++ b/openedx/core/djangoapps/catalog/migrations/0003_catalogintegration_page_size.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 diff --git a/openedx/core/djangoapps/catalog/migrations/0004_auto_20170616_0618.py b/openedx/core/djangoapps/catalog/migrations/0004_auto_20170616_0618.py index 762ca77f8b..386c25d086 100644 --- a/openedx/core/djangoapps/catalog/migrations/0004_auto_20170616_0618.py +++ b/openedx/core/djangoapps/catalog/migrations/0004_auto_20170616_0618.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 diff --git a/openedx/core/djangoapps/catalog/migrations/0005_catalogintegration_long_term_cache_ttl.py b/openedx/core/djangoapps/catalog/migrations/0005_catalogintegration_long_term_cache_ttl.py index e0ee395c77..13da1bf44b 100644 --- a/openedx/core/djangoapps/catalog/migrations/0005_catalogintegration_long_term_cache_ttl.py +++ b/openedx/core/djangoapps/catalog/migrations/0005_catalogintegration_long_term_cache_ttl.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 diff --git a/openedx/core/djangoapps/catalog/tests/factories.py b/openedx/core/djangoapps/catalog/tests/factories.py index 357ee54d38..e15d5c5589 100644 --- a/openedx/core/djangoapps/catalog/tests/factories.py +++ b/openedx/core/djangoapps/catalog/tests/factories.py @@ -1,15 +1,16 @@ """Factories for generating fake catalog data.""" # pylint: disable=missing-docstring, invalid-name +from __future__ import absolute_import + +import uuid from functools import partial import factory -import uuid from factory.fuzzy import FuzzyChoice from faker import Faker from openedx.core.djangoapps.catalog.constants import PathwayType - fake = Faker() VERIFIED_MODE = 'verified' diff --git a/openedx/core/djangoapps/catalog/tests/mixins.py b/openedx/core/djangoapps/catalog/tests/mixins.py index 4ea51bf9f1..8bb38ccdf5 100644 --- a/openedx/core/djangoapps/catalog/tests/mixins.py +++ b/openedx/core/djangoapps/catalog/tests/mixins.py @@ -1,4 +1,6 @@ """Mixins to help test catalog integration.""" +from __future__ import absolute_import + from openedx.core.djangoapps.catalog.models import CatalogIntegration diff --git a/openedx/core/djangoapps/catalog/tests/test_models.py b/openedx/core/djangoapps/catalog/tests/test_models.py index 32b19cf1db..bd983445ac 100644 --- a/openedx/core/djangoapps/catalog/tests/test_models.py +++ b/openedx/core/djangoapps/catalog/tests/test_models.py @@ -1,4 +1,6 @@ """Catalog model tests.""" +from __future__ import absolute_import + import ddt import mock from django.test import TestCase, override_settings diff --git a/openedx/core/djangoapps/catalog/tests/test_utils.py b/openedx/core/djangoapps/catalog/tests/test_utils.py index fb7a481c46..082ad7ecda 100644 --- a/openedx/core/djangoapps/catalog/tests/test_utils.py +++ b/openedx/core/djangoapps/catalog/tests/test_utils.py @@ -1,9 +1,12 @@ """Tests covering utilities for integrating with the catalog service.""" # pylint: disable=missing-docstring +from __future__ import absolute_import + from datetime import timedelta import mock +import six from django.contrib.auth import get_user_model from django.core.cache import cache from django.test import TestCase, override_settings @@ -32,9 +35,9 @@ from openedx.core.djangoapps.catalog.tests.factories import ( ) from openedx.core.djangoapps.catalog.tests.mixins import CatalogIntegrationMixin from openedx.core.djangoapps.catalog.utils import ( + get_course_run_details, get_course_runs, get_course_runs_for_course, - get_course_run_details, get_currency_data, get_localized_price_text, get_owners_for_course, @@ -535,7 +538,7 @@ class TestSessionEntitlement(CatalogIntegrationMixin, TestCase): course_overview = CourseOverviewFactory.create(id=course_key, start=self.tomorrow) CourseModeFactory.create(mode_slug=CourseMode.VERIFIED, min_price=100, course_id=course_overview.id) course_enrollment = CourseEnrollmentFactory( - user=self.user, course_id=unicode(course_overview.id), mode=CourseMode.VERIFIED + user=self.user, course_id=six.text_type(course_overview.id), mode=CourseMode.VERIFIED ) entitlement = CourseEntitlementFactory( user=self.user, enrollment_course_run=course_enrollment, mode=CourseMode.VERIFIED @@ -560,7 +563,7 @@ class TestSessionEntitlement(CatalogIntegrationMixin, TestCase): expiration_datetime=now() - timedelta(days=1) ) course_enrollment = CourseEnrollmentFactory( - user=self.user, course_id=unicode(course_overview.id), mode=CourseMode.VERIFIED + user=self.user, course_id=six.text_type(course_overview.id), mode=CourseMode.VERIFIED ) entitlement = CourseEntitlementFactory( user=self.user, enrollment_course_run=course_enrollment, mode=CourseMode.VERIFIED @@ -586,7 +589,7 @@ class TestSessionEntitlement(CatalogIntegrationMixin, TestCase): expiration_datetime=now() - timedelta(days=1) ) course_enrollment = CourseEnrollmentFactory( - user=self.user, course_id=unicode(course_overview.id), mode=CourseMode.VERIFIED + user=self.user, course_id=six.text_type(course_overview.id), mode=CourseMode.VERIFIED ) entitlement = CourseEntitlementFactory( user=self.user, enrollment_course_run=course_enrollment, mode=CourseMode.VERIFIED