Merge pull request #20066 from edx/youngstrom/INCR-117

INCR-117: Run python-modernize on catalog/management, catalog/migrations, catalog/tests
This commit is contained in:
Michael Youngstrom
2019-03-28 15:56:05 -04:00
committed by GitHub
15 changed files with 36 additions and 17 deletions

View File

@@ -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,

View File

@@ -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

View File

@@ -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

View File

@@ -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(

View File

@@ -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

View File

@@ -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
)

View File

@@ -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):

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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'

View File

@@ -1,4 +1,6 @@
"""Mixins to help test catalog integration."""
from __future__ import absolute_import
from openedx.core.djangoapps.catalog.models import CatalogIntegration

View File

@@ -1,4 +1,6 @@
"""Catalog model tests."""
from __future__ import absolute_import
import ddt
import mock
from django.test import TestCase, override_settings

View File

@@ -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