From d0ed3ee94299d798e992eeaec0b0c176adeeee6e Mon Sep 17 00:00:00 2001 From: Awais Qureshi Date: Mon, 8 Mar 2021 13:13:52 +0500 Subject: [PATCH] BOM-2442 pyupgrade in calendar-sync. --- openedx/features/calendar_sync/__init__.py | 2 +- openedx/features/calendar_sync/admin.py | 1 + openedx/features/calendar_sync/apps.py | 2 +- .../features/calendar_sync/migrations/0001_initial.py | 3 +-- openedx/features/calendar_sync/models.py | 3 +-- openedx/features/calendar_sync/plugins.py | 2 +- openedx/features/calendar_sync/tests/factories.py | 3 ++- openedx/features/calendar_sync/tests/test_api.py | 6 +++--- openedx/features/calendar_sync/tests/test_ics.py | 4 ++-- openedx/features/calendar_sync/tests/test_init.py | 4 ++-- openedx/features/calendar_sync/tests/test_models.py | 6 +++--- openedx/features/calendar_sync/tests/test_plugins.py | 4 ++-- openedx/features/calendar_sync/tests/test_views.py | 9 ++++----- openedx/features/calendar_sync/utils.py | 5 +++-- openedx/features/calendar_sync/views/calendar_sync.py | 9 ++++++--- 15 files changed, 33 insertions(+), 30 deletions(-) diff --git a/openedx/features/calendar_sync/__init__.py b/openedx/features/calendar_sync/__init__.py index 47f76c832d..5696374dc7 100644 --- a/openedx/features/calendar_sync/__init__.py +++ b/openedx/features/calendar_sync/__init__.py @@ -16,4 +16,4 @@ def get_calendar_event_id(user, block_key, date_type, hostname): Returns: event id (str) """ - return '{}.{}.{}@{}'.format(user.id, block_key, date_type, hostname) + return f'{user.id}.{block_key}.{date_type}@{hostname}' diff --git a/openedx/features/calendar_sync/admin.py b/openedx/features/calendar_sync/admin.py index 3efffa361e..b368aeef00 100644 --- a/openedx/features/calendar_sync/admin.py +++ b/openedx/features/calendar_sync/admin.py @@ -1,5 +1,6 @@ # lint-amnesty, pylint: disable=missing-module-docstring from django.contrib import admin + from .models import UserCalendarSyncConfig admin.site.register(UserCalendarSyncConfig) diff --git a/openedx/features/calendar_sync/apps.py b/openedx/features/calendar_sync/apps.py index 180e752a7c..fde6dfb152 100644 --- a/openedx/features/calendar_sync/apps.py +++ b/openedx/features/calendar_sync/apps.py @@ -12,7 +12,7 @@ class UserCalendarSyncConfig(AppConfig): # lint-amnesty, pylint: disable=missin name = 'openedx.features.calendar_sync' def ready(self): - super(UserCalendarSyncConfig, self).ready() # lint-amnesty, pylint: disable=super-with-arguments + super().ready() # noinspection PyUnresolvedReferences import openedx.features.calendar_sync.signals # pylint: disable=import-outside-toplevel,unused-import diff --git a/openedx/features/calendar_sync/migrations/0001_initial.py b/openedx/features/calendar_sync/migrations/0001_initial.py index 666152e776..0f33881c58 100644 --- a/openedx/features/calendar_sync/migrations/0001_initial.py +++ b/openedx/features/calendar_sync/migrations/0001_initial.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Generated by Django 1.11.28 on 2020-02-20 20:20 @@ -48,6 +47,6 @@ class Migration(migrations.Migration): ), migrations.AlterUniqueTogether( name='usercalendarsyncconfig', - unique_together=set([('user', 'course_key')]), + unique_together={('user', 'course_key')}, ), ] diff --git a/openedx/features/calendar_sync/models.py b/openedx/features/calendar_sync/models.py index 7901e920b1..d0d01e0a4c 100644 --- a/openedx/features/calendar_sync/models.py +++ b/openedx/features/calendar_sync/models.py @@ -5,9 +5,8 @@ Models for Calendar Sync from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.db import models -from simple_history.models import HistoricalRecords - from opaque_keys.edx.django.models import CourseKeyField +from simple_history.models import HistoricalRecords class UserCalendarSyncConfig(models.Model): diff --git a/openedx/features/calendar_sync/plugins.py b/openedx/features/calendar_sync/plugins.py index 0c0c801857..41e8712251 100644 --- a/openedx/features/calendar_sync/plugins.py +++ b/openedx/features/calendar_sync/plugins.py @@ -6,11 +6,11 @@ Platform plugins to support Calendar Sync toggle. from django.urls import reverse from django.utils.translation import ugettext as _ +from common.djangoapps.student.models import CourseEnrollment from openedx.features.calendar_sync.api import SUBSCRIBE, UNSUBSCRIBE from openedx.features.calendar_sync.models import UserCalendarSyncConfig from openedx.features.course_experience import CALENDAR_SYNC_FLAG, RELATIVE_DATES_FLAG from openedx.features.course_experience.course_tools import CourseTool, HttpMethod -from common.djangoapps.student.models import CourseEnrollment class CalendarSyncToggleTool(CourseTool): diff --git a/openedx/features/calendar_sync/tests/factories.py b/openedx/features/calendar_sync/tests/factories.py index 40329c9fd7..cfba6ce7de 100644 --- a/openedx/features/calendar_sync/tests/factories.py +++ b/openedx/features/calendar_sync/tests/factories.py @@ -1,5 +1,6 @@ # lint-amnesty, pylint: disable=missing-module-docstring from factory.django import DjangoModelFactory + from openedx.features.calendar_sync.models import UserCalendarSyncConfig @@ -7,7 +8,7 @@ class UserCalendarSyncConfigFactory(DjangoModelFactory): """ Factory class for SiteConfiguration model """ - class Meta(object): + class Meta: model = UserCalendarSyncConfig enabled = True diff --git a/openedx/features/calendar_sync/tests/test_api.py b/openedx/features/calendar_sync/tests/test_api.py index b300bab229..2a06762d21 100644 --- a/openedx/features/calendar_sync/tests/test_api.py +++ b/openedx/features/calendar_sync/tests/test_api.py @@ -1,9 +1,9 @@ """ Tests for the Calendar Sync API """ +from common.djangoapps.student.tests.factories import UserFactory from openedx.features.calendar_sync.api import subscribe_user_to_calendar, unsubscribe_user_to_calendar from openedx.features.calendar_sync.models import UserCalendarSyncConfig -from common.djangoapps.student.tests.factories import UserFactory from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory @@ -15,12 +15,12 @@ class TestCalendarSyncAPI(SharedModuleStoreTestCase): @classmethod def setUpClass(cls): """ Set up any course data """ - super(TestCalendarSyncAPI, cls).setUpClass() + super().setUpClass() cls.course = CourseFactory.create() cls.course_key = cls.course.id def setUp(self): - super(TestCalendarSyncAPI, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() self.user = UserFactory(password=TEST_PASSWORD) def test_subscribe_to_calendar(self): diff --git a/openedx/features/calendar_sync/tests/test_ics.py b/openedx/features/calendar_sync/tests/test_ics.py index 12bc1dff6d..9101e367e0 100644 --- a/openedx/features/calendar_sync/tests/test_ics.py +++ b/openedx/features/calendar_sync/tests/test_ics.py @@ -1,19 +1,19 @@ """ Tests for the Calendar Sync .ics methods """ from datetime import datetime, timedelta +from unittest.mock import patch import pytz from django.test import RequestFactory, TestCase from freezegun import freeze_time -from mock import patch +from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.courseware.courses import _Assignment from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.core.djangoapps.site_configuration.tests.factories import SiteConfigurationFactory, SiteFactory from openedx.features.calendar_sync import get_calendar_event_id from openedx.features.calendar_sync.ics import generate_ics_files_for_user_course from openedx.features.calendar_sync.tests.factories import UserCalendarSyncConfigFactory -from common.djangoapps.student.tests.factories import UserFactory class TestIcsGeneration(TestCase): diff --git a/openedx/features/calendar_sync/tests/test_init.py b/openedx/features/calendar_sync/tests/test_init.py index c2471d9b63..b8c39dc9c3 100644 --- a/openedx/features/calendar_sync/tests/test_init.py +++ b/openedx/features/calendar_sync/tests/test_init.py @@ -3,8 +3,8 @@ from django.test import TestCase -from openedx.features.calendar_sync import get_calendar_event_id from common.djangoapps.student.tests.factories import UserFactory +from openedx.features.calendar_sync import get_calendar_event_id TEST_PASSWORD = 'test' @@ -12,7 +12,7 @@ TEST_PASSWORD = 'test' class TestCalendarSyncInit(TestCase): """ Tests for the contents of __init__.py """ def setUp(self): - super(TestCalendarSyncInit, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() self.user = UserFactory(password=TEST_PASSWORD) def test_get_calendar_event_id(self): diff --git a/openedx/features/calendar_sync/tests/test_models.py b/openedx/features/calendar_sync/tests/test_models.py index 41f4002d63..29a8926b86 100644 --- a/openedx/features/calendar_sync/tests/test_models.py +++ b/openedx/features/calendar_sync/tests/test_models.py @@ -1,8 +1,8 @@ """ Tests for the Calendar Sync models """ -from openedx.features.calendar_sync.models import UserCalendarSyncConfig from common.djangoapps.student.tests.factories import UserFactory +from openedx.features.calendar_sync.models import UserCalendarSyncConfig from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory @@ -14,12 +14,12 @@ class TestUserCalendarSyncConfig(SharedModuleStoreTestCase): @classmethod def setUpClass(cls): """ Set up any course data """ - super(TestUserCalendarSyncConfig, cls).setUpClass() + super().setUpClass() cls.course = CourseFactory.create() cls.course_key = cls.course.id def setUp(self): - super(TestUserCalendarSyncConfig, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() self.user = UserFactory(password=TEST_PASSWORD) def test_is_enabled_for_course(self): diff --git a/openedx/features/calendar_sync/tests/test_plugins.py b/openedx/features/calendar_sync/tests/test_plugins.py index b2877cf7bc..37313e4fa9 100644 --- a/openedx/features/calendar_sync/tests/test_plugins.py +++ b/openedx/features/calendar_sync/tests/test_plugins.py @@ -6,8 +6,8 @@ Unit tests for the calendar sync plugins. import crum import ddt from django.test import RequestFactory - from edx_toggles.toggles.testutils import override_waffle_flag + from lms.djangoapps.experiments.testutils import override_experiment_waffle_flag from openedx.features.calendar_sync.plugins import CalendarSyncToggleTool from openedx.features.course_experience import CALENDAR_SYNC_FLAG, RELATIVE_DATES_FLAG @@ -23,7 +23,7 @@ class TestCalendarSyncToggleTool(SharedModuleStoreTestCase): @classmethod def setUpClass(cls): """ Set up any course data """ - super(TestCalendarSyncToggleTool, cls).setUpClass() + super().setUpClass() cls.course = CourseFactory.create() cls.course_key = cls.course.id diff --git a/openedx/features/calendar_sync/tests/test_views.py b/openedx/features/calendar_sync/tests/test_views.py index 77fd708073..175c2947f4 100644 --- a/openedx/features/calendar_sync/tests/test_views.py +++ b/openedx/features/calendar_sync/tests/test_views.py @@ -4,7 +4,6 @@ Tests for Calendar Sync views. import ddt - from django.test import TestCase from django.urls import reverse @@ -21,20 +20,20 @@ class TestCalendarSyncView(SharedModuleStoreTestCase, TestCase): @classmethod def setUpClass(cls): """ Set up any course data """ - super(TestCalendarSyncView, cls).setUpClass() + super().setUpClass() cls.course = CourseFactory.create() def setUp(self): - super(TestCalendarSyncView, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() self.user = self.create_user_for_course(self.course) self.client.login(username=self.user.username, password=TEST_PASSWORD) self.calendar_sync_url = reverse('openedx.calendar_sync', args=[self.course.id]) @ddt.data( # Redirect on successful subscribe - [{'tool_data': "{{'toggle_data': '{}'}}".format(SUBSCRIBE)}, 302, ''], + [{'tool_data': f"{{'toggle_data': '{SUBSCRIBE}'}}"}, 302, ''], # Redirect on successful unsubscribe - [{'tool_data': "{{'toggle_data': '{}'}}".format(UNSUBSCRIBE)}, 302, ''], + [{'tool_data': f"{{'toggle_data': '{UNSUBSCRIBE}'}}"}, 302, ''], # 422 on unknown toggle_data [{'tool_data': "{{'toggle_data': '{}'}}".format('gibberish')}, 422, 'Toggle data was not provided or had unknown value.'], diff --git a/openedx/features/calendar_sync/utils.py b/openedx/features/calendar_sync/utils.py index e49d9f7abf..49f64219f9 100644 --- a/openedx/features/calendar_sync/utils.py +++ b/openedx/features/calendar_sync/utils.py @@ -1,13 +1,14 @@ # lint-amnesty, pylint: disable=missing-module-docstring import logging +import os from email.mime.application import MIMEApplication from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText + +import boto3 from django.conf import settings from django.utils.html import format_html from django.utils.translation import ugettext_lazy as _ -import os # lint-amnesty, pylint: disable=wrong-import-order -import boto3 logger = logging.getLogger(__name__) diff --git a/openedx/features/calendar_sync/views/calendar_sync.py b/openedx/features/calendar_sync/views/calendar_sync.py index a35b9d7464..2238e1d2aa 100644 --- a/openedx/features/calendar_sync/views/calendar_sync.py +++ b/openedx/features/calendar_sync/views/calendar_sync.py @@ -15,10 +15,13 @@ from django.views.generic import View from opaque_keys.edx.keys import CourseKey from rest_framework import status -from openedx.features.calendar_sync.api import ( - SUBSCRIBE, UNSUBSCRIBE, subscribe_user_to_calendar, unsubscribe_user_to_calendar -) from common.djangoapps.util.views import ensure_valid_course_key +from openedx.features.calendar_sync.api import ( + SUBSCRIBE, + UNSUBSCRIBE, + subscribe_user_to_calendar, + unsubscribe_user_to_calendar +) class CalendarSyncView(View):