From 4ab536e58d0694ab886837da3b0d9f014721f962 Mon Sep 17 00:00:00 2001 From: Awais Qureshi Date: Tue, 23 Feb 2021 16:46:07 +0500 Subject: [PATCH] BOM-2373 Run Pyupgrade on course-action-state. --- common/djangoapps/course_action_state/managers.py | 7 +++---- .../course_action_state/migrations/0001_initial.py | 6 ++---- common/djangoapps/course_action_state/models.py | 9 +++++---- .../course_action_state/tests/test_managers.py | 7 +++---- .../course_action_state/tests/test_rerun_manager.py | 5 ++--- 5 files changed, 15 insertions(+), 19 deletions(-) diff --git a/common/djangoapps/course_action_state/managers.py b/common/djangoapps/course_action_state/managers.py index 310774ee05..57076f11e7 100644 --- a/common/djangoapps/course_action_state/managers.py +++ b/common/djangoapps/course_action_state/managers.py @@ -4,7 +4,6 @@ Model Managers for Course Actions import traceback -import six from django.db import models, transaction @@ -13,7 +12,7 @@ class CourseActionStateManager(models.Manager): An abstract Model Manager class for Course Action State models. This abstract class expects child classes to define the ACTION (string) field. """ - class Meta(object): + class Meta: """Abstract manager class, with subclasses defining the ACTION (string) field.""" abstract = True @@ -90,7 +89,7 @@ class CourseActionUIStateManager(CourseActionStateManager): # update any additional fields in kwargs if kwargs: - for key, value in six.iteritems(kwargs): + for key, value in kwargs.items(): setattr(state_object, key, value) state_object.save() @@ -109,7 +108,7 @@ class CourseRerunUIStateManager(CourseActionUIStateManager): """ ACTION = "rerun" - class State(object): + class State: """ An Enum class for maintaining the list of possible states for Reruns. """ diff --git a/common/djangoapps/course_action_state/migrations/0001_initial.py b/common/djangoapps/course_action_state/migrations/0001_initial.py index 597f49df3b..c04013d8ae 100644 --- a/common/djangoapps/course_action_state/migrations/0001_initial.py +++ b/common/djangoapps/course_action_state/migrations/0001_initial.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - import django.db.models.deletion from django.conf import settings from django.db import migrations, models @@ -25,13 +23,13 @@ class Migration(migrations.Migration): ('should_display', models.BooleanField(default=False)), ('message', models.CharField(max_length=1000)), ('source_course_key', CourseKeyField(max_length=255, db_index=True)), - ('display_name', models.CharField(default=u'', max_length=255, blank=True)), + ('display_name', models.CharField(default='', max_length=255, blank=True)), ('created_user', models.ForeignKey(related_name='created_by_user+', on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL, null=True)), ('updated_user', models.ForeignKey(related_name='updated_by_user+', on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL, null=True)), ], ), migrations.AlterUniqueTogether( name='coursererunstate', - unique_together=set([('course_key', 'action')]), + unique_together={('course_key', 'action')}, ), ] diff --git a/common/djangoapps/course_action_state/models.py b/common/djangoapps/course_action_state/models.py index 0589f1acbe..366f9e636e 100644 --- a/common/djangoapps/course_action_state/models.py +++ b/common/djangoapps/course_action_state/models.py @@ -13,6 +13,7 @@ file and check it in at the same time as your model changes. To do that, from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.db import models from opaque_keys.edx.django.models import CourseKeyField + from common.djangoapps.course_action_state.managers import CourseActionStateManager, CourseRerunUIStateManager @@ -22,7 +23,7 @@ class CourseActionState(models.Model): For example: course copying (reruns), import, export, and validation. """ - class Meta(object): + class Meta: """ For performance reasons, we disable "concrete inheritance", by making the Model base class abstract. With the "abstract base class" inheritance model, tables are only created for derived models, not for @@ -78,7 +79,7 @@ class CourseActionUIState(CourseActionState): """ An abstract django model that is a sub-class of CourseActionState with additional fields related to UI. """ - class Meta(object): + class Meta: """ See comment in CourseActionState on disabling "concrete inheritance". """ @@ -104,7 +105,7 @@ class CourseRerunState(CourseActionUIState): .. no_pii: """ - class Meta(object): + class Meta: """ Set the (destination) course_key field to be unique for the rerun action Although multiple reruns can be in progress simultaneously for a particular source course_key, @@ -117,7 +118,7 @@ class CourseRerunState(CourseActionUIState): source_course_key = CourseKeyField(max_length=255, db_index=True) # Display name for destination course - display_name = models.CharField(max_length=255, default=u"", blank=True) + display_name = models.CharField(max_length=255, default="", blank=True) # MANAGERS # Override the abstract class' manager with a Rerun-specific manager that inherits from the base class' manager. diff --git a/common/djangoapps/course_action_state/tests/test_managers.py b/common/djangoapps/course_action_state/tests/test_managers.py index 41d34f2be2..d1c0a0f41b 100644 --- a/common/djangoapps/course_action_state/tests/test_managers.py +++ b/common/djangoapps/course_action_state/tests/test_managers.py @@ -9,7 +9,6 @@ import pytest from ddt import data, ddt from django.test import TestCase from opaque_keys.edx.locations import CourseLocator -from six.moves import range from common.djangoapps.course_action_state.managers import CourseActionStateItemNotFoundError from common.djangoapps.course_action_state.models import CourseRerunState @@ -23,7 +22,7 @@ class TestCourseActionStateManagerBase(TestCase): Base class for testing Course Action State Managers. """ def setUp(self): - super(TestCourseActionStateManagerBase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() self.course_key = CourseLocator("test_org", "test_course_num", "test_run") @@ -118,8 +117,8 @@ class TestCourseActionUIStateManager(TestCourseActionStateManagerBase): def assertCourseActionStatesEqual(self, expected, found): """Asserts that the set of course keys in the expected state equal those that are found""" self.assertSetEqual( - set(course_action_state.course_key for course_action_state in expected), - set(course_action_state.course_key for course_action_state in found)) + {course_action_state.course_key for course_action_state in expected}, + {course_action_state.course_key for course_action_state in found}) @data(*COURSE_ACTION_STATES) def test_find_all_for_display(self, action_class): diff --git a/common/djangoapps/course_action_state/tests/test_rerun_manager.py b/common/djangoapps/course_action_state/tests/test_rerun_manager.py index 5971c12dc1..f365b91be7 100644 --- a/common/djangoapps/course_action_state/tests/test_rerun_manager.py +++ b/common/djangoapps/course_action_state/tests/test_rerun_manager.py @@ -5,7 +5,6 @@ Tests specific to the CourseRerunState Model and Manager. from django.test import TestCase from opaque_keys.edx.locations import CourseLocator -from six import text_type from common.djangoapps.course_action_state.managers import CourseRerunUIStateManager from common.djangoapps.course_action_state.models import CourseRerunState @@ -17,7 +16,7 @@ class TestCourseRerunStateManager(TestCase): Test class for testing the CourseRerunUIStateManager. """ def setUp(self): - super(TestCourseRerunStateManager, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() self.source_course_key = CourseLocator("source_org", "source_course_num", "source_run") self.course_key = CourseLocator("test_org", "test_course_num", "test_run") self.created_user = UserFactory() @@ -105,7 +104,7 @@ class TestCourseRerunStateManager(TestCase): ) self.expected_rerun_state.pop('message') rerun = self.verify_rerun_state() - assert text_type(exception) in rerun.message + assert str(exception) in rerun.message # dismiss ui and verify self.dismiss_ui_and_verify(rerun)