BOM-2442
pyupgrade in calendar-sync.
This commit is contained in:
@@ -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}'
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# lint-amnesty, pylint: disable=missing-module-docstring
|
||||
from django.contrib import admin
|
||||
|
||||
from .models import UserCalendarSyncConfig
|
||||
|
||||
admin.site.register(UserCalendarSyncConfig)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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')},
|
||||
),
|
||||
]
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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.'],
|
||||
|
||||
@@ -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__)
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user