diff --git a/openedx/core/djangoapps/site_configuration/admin.py b/openedx/core/djangoapps/site_configuration/admin.py index d8b52647b6..6414069942 100644 --- a/openedx/core/djangoapps/site_configuration/admin.py +++ b/openedx/core/djangoapps/site_configuration/admin.py @@ -15,7 +15,7 @@ class SiteConfigurationAdmin(admin.ModelAdmin): list_display = ('site', 'enabled', 'site_values') search_fields = ('site__domain', 'site_values') - class Meta(object): + class Meta: """ Meta class for SiteConfiguration admin model """ @@ -33,7 +33,7 @@ class SiteConfigurationHistoryAdmin(admin.ModelAdmin): ordering = ['-created'] - class Meta(object): + class Meta: """ Meta class for SiteConfigurationHistory admin model """ diff --git a/openedx/core/djangoapps/site_configuration/helpers.py b/openedx/core/djangoapps/site_configuration/helpers.py index dd99297cf9..9782435ed0 100644 --- a/openedx/core/djangoapps/site_configuration/helpers.py +++ b/openedx/core/djangoapps/site_configuration/helpers.py @@ -249,6 +249,6 @@ def page_title_breadcrumbs(*crumbs, **kwargs): separator = kwargs.get("separator", " | ") crumbs = [c for c in crumbs if c is not None] if crumbs: - return u'{}{}{}'.format(separator.join(crumbs), separator, platform_name) + return '{}{}{}'.format(separator.join(crumbs), separator, platform_name) else: return platform_name diff --git a/openedx/core/djangoapps/site_configuration/management/commands/create_or_update_site_configuration.py b/openedx/core/djangoapps/site_configuration/management/commands/create_or_update_site_configuration.py index f891984f20..fd3f97f86a 100644 --- a/openedx/core/djangoapps/site_configuration/management/commands/create_or_update_site_configuration.py +++ b/openedx/core/djangoapps/site_configuration/management/commands/create_or_update_site_configuration.py @@ -83,9 +83,9 @@ class Command(BaseCommand): name=domain, ) if created: - LOG.info("Site does not exist. Created new site '{site_name}'".format(site_name=site.domain)) + LOG.info(f"Site does not exist. Created new site '{site.domain}'") else: - LOG.info("Found existing site for '{site_name}'".format(site_name=site.domain)) + LOG.info(f"Found existing site for '{site.domain}'") site_configuration, created = SiteConfiguration.objects.get_or_create(site=site) if created: @@ -96,7 +96,7 @@ class Command(BaseCommand): ) else: LOG.info( - "Found existing site configuration for '{site_name}'. Updating it.".format(site_name=site.domain) + f"Found existing site configuration for '{site.domain}'. Updating it." ) site_configuration_values = configuration or config_file_data diff --git a/openedx/core/djangoapps/site_configuration/management/commands/tests/test_create_or_update_site_configuration.py b/openedx/core/djangoapps/site_configuration/management/commands/tests/test_create_or_update_site_configuration.py index 90fb18fd4d..5b4d3f8ae1 100644 --- a/openedx/core/djangoapps/site_configuration/management/commands/tests/test_create_or_update_site_configuration.py +++ b/openedx/core/djangoapps/site_configuration/management/commands/tests/test_create_or_update_site_configuration.py @@ -22,7 +22,7 @@ class CreateOrUpdateSiteConfigurationTest(TestCase): command = 'create_or_update_site_configuration' def setUp(self): - super(CreateOrUpdateSiteConfigurationTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() self.site_id = 1 self.site_id_arg = ['--site-id', str(self.site_id)] self.json_file_path = Path(__file__).parent / "fixtures/config1.json" @@ -123,7 +123,7 @@ class CreateOrUpdateSiteConfigurationTest(TestCase): Verify that the SiteConfiguration instance is enabled/disabled as per the flag used. """ self.assert_site_configuration_does_not_exist() - call_command(self.command, '--{}'.format(flag), *self.site_id_arg) + call_command(self.command, f'--{flag}', *self.site_id_arg) site_configuration = SiteConfiguration.objects.get(site=self.site) assert not site_configuration.site_values assert enabled == site_configuration.enabled diff --git a/openedx/core/djangoapps/site_configuration/migrations/0001_initial.py b/openedx/core/djangoapps/site_configuration/migrations/0001_initial.py index fefc51bf20..f6b14a25ec 100644 --- a/openedx/core/djangoapps/site_configuration/migrations/0001_initial.py +++ b/openedx/core/djangoapps/site_configuration/migrations/0001_initial.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - from django.db import migrations, models import django.utils.timezone import jsonfield.fields diff --git a/openedx/core/djangoapps/site_configuration/migrations/0002_auto_20160720_0231.py b/openedx/core/djangoapps/site_configuration/migrations/0002_auto_20160720_0231.py index 84343dd469..534368b00c 100644 --- a/openedx/core/djangoapps/site_configuration/migrations/0002_auto_20160720_0231.py +++ b/openedx/core/djangoapps/site_configuration/migrations/0002_auto_20160720_0231.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - from django.db import migrations, models @@ -14,11 +11,11 @@ class Migration(migrations.Migration): migrations.AddField( model_name='siteconfiguration', name='enabled', - field=models.BooleanField(default=False, verbose_name=u'Enabled'), + field=models.BooleanField(default=False, verbose_name='Enabled'), ), migrations.AddField( model_name='siteconfigurationhistory', name='enabled', - field=models.BooleanField(default=False, verbose_name=u'Enabled'), + field=models.BooleanField(default=False, verbose_name='Enabled'), ), ] diff --git a/openedx/core/djangoapps/site_configuration/migrations/0003_auto_20200217_1058.py b/openedx/core/djangoapps/site_configuration/migrations/0003_auto_20200217_1058.py index 8a7394f32a..3ac9b1d932 100644 --- a/openedx/core/djangoapps/site_configuration/migrations/0003_auto_20200217_1058.py +++ b/openedx/core/djangoapps/site_configuration/migrations/0003_auto_20200217_1058.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Generated by Django 1.11.28 on 2020-02-17 10:58 diff --git a/openedx/core/djangoapps/site_configuration/migrations/0004_add_site_values_field.py b/openedx/core/djangoapps/site_configuration/migrations/0004_add_site_values_field.py index 2efdd1bebd..5ea974a548 100644 --- a/openedx/core/djangoapps/site_configuration/migrations/0004_add_site_values_field.py +++ b/openedx/core/djangoapps/site_configuration/migrations/0004_add_site_values_field.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Generated by Django 1.11.28 on 2020-02-19 16:50 diff --git a/openedx/core/djangoapps/site_configuration/migrations/0005_populate_siteconfig_history_site_values.py b/openedx/core/djangoapps/site_configuration/migrations/0005_populate_siteconfig_history_site_values.py index bf7254ca7e..57aef23044 100644 --- a/openedx/core/djangoapps/site_configuration/migrations/0005_populate_siteconfig_history_site_values.py +++ b/openedx/core/djangoapps/site_configuration/migrations/0005_populate_siteconfig_history_site_values.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - from django.db import migrations forward_sql = """ diff --git a/openedx/core/djangoapps/site_configuration/migrations/0006_copy_values_to_site_values.py b/openedx/core/djangoapps/site_configuration/migrations/0006_copy_values_to_site_values.py index c5c890fd6d..f880490357 100644 --- a/openedx/core/djangoapps/site_configuration/migrations/0006_copy_values_to_site_values.py +++ b/openedx/core/djangoapps/site_configuration/migrations/0006_copy_values_to_site_values.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - from django.db import migrations from ..models import save_siteconfig_without_historical_record diff --git a/openedx/core/djangoapps/site_configuration/migrations/0007_remove_values_field.py b/openedx/core/djangoapps/site_configuration/migrations/0007_remove_values_field.py index aef07b728a..27c4e69280 100644 --- a/openedx/core/djangoapps/site_configuration/migrations/0007_remove_values_field.py +++ b/openedx/core/djangoapps/site_configuration/migrations/0007_remove_values_field.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - from django.db import migrations diff --git a/openedx/core/djangoapps/site_configuration/models.py b/openedx/core/djangoapps/site_configuration/models.py index 8aad073efd..8b999d89e2 100644 --- a/openedx/core/djangoapps/site_configuration/models.py +++ b/openedx/core/djangoapps/site_configuration/models.py @@ -30,7 +30,7 @@ class SiteConfiguration(models.Model): .. no_pii: """ site = models.OneToOneField(Site, related_name='configuration', on_delete=models.CASCADE) - enabled = models.BooleanField(default=False, verbose_name=u"Enabled") + enabled = models.BooleanField(default=False, verbose_name="Enabled") site_values = JSONField( null=False, blank=True, @@ -42,7 +42,7 @@ class SiteConfiguration(models.Model): ) def __str__(self): - return u"".format(site=self.site) # xss-lint: disable=python-wrap-html + return f"" # xss-lint: disable=python-wrap-html def __repr__(self): return self.__str__() @@ -64,9 +64,9 @@ class SiteConfiguration(models.Model): try: return self.site_values.get(name, default) except AttributeError as error: - logger.exception(u'Invalid JSON data. \n [%s]', error) + logger.exception('Invalid JSON data. \n [%s]', error) else: - logger.info(u"Site Configuration is not enabled for site (%s).", self.site) + logger.info("Site Configuration is not enabled for site (%s).", self.site) return default @@ -171,7 +171,7 @@ class SiteConfigurationHistory(TimeStampedModel): .. no_pii: """ site = models.ForeignKey(Site, related_name='configuration_histories', on_delete=models.CASCADE) - enabled = models.BooleanField(default=False, verbose_name=u"Enabled") + enabled = models.BooleanField(default=False, verbose_name="Enabled") site_values = JSONField( null=False, blank=True, @@ -184,7 +184,7 @@ class SiteConfigurationHistory(TimeStampedModel): def __str__(self): # pylint: disable=line-too-long - return u"".format( # xss-lint: disable=python-wrap-html + return "".format( # xss-lint: disable=python-wrap-html modified=self.modified, site=self.site, ) diff --git a/openedx/core/djangoapps/site_configuration/templatetags/configuration.py b/openedx/core/djangoapps/site_configuration/templatetags/configuration.py index f053fe8a4b..b5242a53b5 100644 --- a/openedx/core/djangoapps/site_configuration/templatetags/configuration.py +++ b/openedx/core/djangoapps/site_configuration/templatetags/configuration.py @@ -51,7 +51,7 @@ def microsite_css_overrides_file(): """ file_path = configuration_helpers.get_value('css_overrides_file', None) if file_path is not None: - return HTML(u"").format(static(file_path)) + return HTML("").format(static(file_path)) else: return "" diff --git a/openedx/core/djangoapps/site_configuration/tests/factories.py b/openedx/core/djangoapps/site_configuration/tests/factories.py index db1bb7377f..df7d1eef70 100644 --- a/openedx/core/djangoapps/site_configuration/tests/factories.py +++ b/openedx/core/djangoapps/site_configuration/tests/factories.py @@ -14,7 +14,7 @@ class SiteFactory(DjangoModelFactory): """ Factory class for Site model """ - class Meta(object): + class Meta: model = Site django_get_or_create = ('domain',) @@ -26,7 +26,7 @@ class SiteConfigurationFactory(DjangoModelFactory): """ Factory class for SiteConfiguration model """ - class Meta(object): + class Meta: model = SiteConfiguration enabled = True diff --git a/openedx/core/djangoapps/site_configuration/tests/mixins.py b/openedx/core/djangoapps/site_configuration/tests/mixins.py index 9c52613abe..82a74fe3a6 100644 --- a/openedx/core/djangoapps/site_configuration/tests/mixins.py +++ b/openedx/core/djangoapps/site_configuration/tests/mixins.py @@ -6,12 +6,12 @@ Mixins for TestCase classes that need to account for multiple sites from openedx.core.djangoapps.site_configuration.tests.factories import SiteConfigurationFactory, SiteFactory -class SiteMixin(object): +class SiteMixin: """ Mixin for setting up Site framework models """ def setUp(self): - super(SiteMixin, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() self.site = SiteFactory.create() site_config = { diff --git a/openedx/core/djangoapps/site_configuration/tests/test_helpers.py b/openedx/core/djangoapps/site_configuration/tests/test_helpers.py index 7b71d2f7f3..2b5215a8ec 100644 --- a/openedx/core/djangoapps/site_configuration/tests/test_helpers.py +++ b/openedx/core/djangoapps/site_configuration/tests/test_helpers.py @@ -3,7 +3,6 @@ Tests for helper function provided by site_configuration app. """ -import six from django.test import TestCase from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers @@ -74,8 +73,7 @@ class TestHelpers(TestCase): Test that get_dict returns correct value for any given key. """ # Make sure entry is saved and retrieved correctly - six.assertCountEqual( - self, + self.assertCountEqual( configuration_helpers.get_dict("REGISTRATION_EXTRA_FIELDS"), test_config['REGISTRATION_EXTRA_FIELDS'], ) @@ -85,8 +83,7 @@ class TestHelpers(TestCase): expected.update(test_config['REGISTRATION_EXTRA_FIELDS']) # Test that the default value is returned if the value for the given key is not found in the configuration - six.assertCountEqual( - self, + self.assertCountEqual( configuration_helpers.get_dict("REGISTRATION_EXTRA_FIELDS", default), expected, ) @@ -124,8 +121,7 @@ class TestHelpers(TestCase): assert configuration_helpers.get_value_for_org(test_org, 'css_overrides_file') ==\ test_config['css_overrides_file'] - six.assertCountEqual( - self, + self.assertCountEqual( configuration_helpers.get_value_for_org(test_org, "REGISTRATION_EXTRA_FIELDS"), test_config['REGISTRATION_EXTRA_FIELDS'] ) @@ -155,8 +151,7 @@ class TestHelpers(TestCase): """ test_orgs = [test_config['course_org_filter']] with with_site_configuration_context(configuration=test_config): - six.assertCountEqual( - self, + self.assertCountEqual( list(configuration_helpers.get_all_orgs()), test_orgs, ) @@ -164,8 +159,7 @@ class TestHelpers(TestCase): @with_site_configuration(configuration=test_config_multi_org) def test_get_current_site_orgs(self): test_orgs = test_config_multi_org['course_org_filter'] - six.assertCountEqual( - self, + self.assertCountEqual( list(configuration_helpers.get_current_site_orgs()), test_orgs ) diff --git a/openedx/core/djangoapps/site_configuration/tests/test_middleware.py b/openedx/core/djangoapps/site_configuration/tests/test_middleware.py index 97c91cc390..8bba58a4e8 100644 --- a/openedx/core/djangoapps/site_configuration/tests/test_middleware.py +++ b/openedx/core/djangoapps/site_configuration/tests/test_middleware.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ Test site_configuration middleware. """ @@ -23,7 +22,7 @@ class SessionCookieDomainTests(TestCase): """ def setUp(self): - super(SessionCookieDomainTests, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() # Create a test client, and log it in so that it will save some session # data. self.user = UserFactory.create() @@ -62,7 +61,7 @@ class SessionCookieDomainSiteConfigurationOverrideTests(TestCase): """ def setUp(self): - super(SessionCookieDomainSiteConfigurationOverrideTests, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() # Create a test client, and log it in so that it will save some session data. self.user = UserFactory.create() self.user.set_password('password') diff --git a/openedx/core/djangoapps/site_configuration/tests/test_models.py b/openedx/core/djangoapps/site_configuration/tests/test_models.py index f6735b13d1..22b82b63f5 100644 --- a/openedx/core/djangoapps/site_configuration/tests/test_models.py +++ b/openedx/core/djangoapps/site_configuration/tests/test_models.py @@ -1,12 +1,11 @@ """ Tests for site configuration's django models. """ -import six +from unittest.mock import patch import pytest from django.contrib.sites.models import Site from django.db import IntegrityError, transaction from django.test import TestCase -from mock import patch from openedx.core.djangoapps.site_configuration.models import ( SiteConfiguration, SiteConfigurationHistory, @@ -48,7 +47,7 @@ class SiteConfigurationTests(TestCase): @classmethod def setUpClass(cls): - super(SiteConfigurationTests, cls).setUpClass() + super().setUpClass() cls.site, _ = Site.objects.get_or_create(domain=cls.domain, name=cls.domain) cls.site2, _ = Site.objects.get_or_create( domain=cls.test_config2['SITE_NAME'], @@ -300,7 +299,7 @@ class SiteConfigurationTests(TestCase): ) # Test that the default value is returned if the value for the given key is not found in the configuration - six.assertCountEqual(self, SiteConfiguration.get_all_orgs(), expected_orgs) + self.assertCountEqual(SiteConfiguration.get_all_orgs(), expected_orgs) def test_get_all_orgs_returns_only_enabled(self): """ @@ -319,4 +318,4 @@ class SiteConfigurationTests(TestCase): ) # Test that the default value is returned if the value for the given key is not found in the configuration - six.assertCountEqual(self, SiteConfiguration.get_all_orgs(), expected_orgs) + self.assertCountEqual(SiteConfiguration.get_all_orgs(), expected_orgs) diff --git a/openedx/core/djangoapps/site_configuration/tests/test_util.py b/openedx/core/djangoapps/site_configuration/tests/test_util.py index 6bfb5b760e..489beca82a 100644 --- a/openedx/core/djangoapps/site_configuration/tests/test_util.py +++ b/openedx/core/djangoapps/site_configuration/tests/test_util.py @@ -6,7 +6,7 @@ Test helpers for Site Configuration. from functools import wraps import contextlib -from mock import patch +from unittest.mock import patch from django.contrib.sites.models import Site