From e542cd9f81f3427e99334bdaf6e3c5c1e3f8c814 Mon Sep 17 00:00:00 2001 From: Julia Eskew Date: Thu, 2 Jan 2020 17:03:15 -0500 Subject: [PATCH 1/3] This stage does the following: - Adds the new field and migration to create the column. - Makes all writes go to both old and new field. --- .../discussion/tests/test_signals.py | 8 +++- .../tests/views/test_instructor_dashboard.py | 14 ++++++- .../ace_common/tests/test_tracking.py | 3 ++ openedx/core/djangoapps/catalog/views.py | 1 + .../commands/tests/test_notify_credentials.py | 1 + .../credentials/tests/test_signals.py | 1 + .../djangoapps/programs/tests/test_signals.py | 1 + .../commands/tests/send_email_base.py | 10 ++++- .../schedules/tests/test_resolvers.py | 1 + .../commands/create_site_configuration.py | 7 +++- .../migrations/0003_add_site_values_field.py | 26 ++++++++++++ .../djangoapps/site_configuration/models.py | 19 ++++++++- .../site_configuration/tests/mixins.py | 42 +++++++++++-------- .../tests/test_middleware.py | 6 +++ .../site_configuration/tests/test_models.py | 22 ++++++++++ .../site_configuration/tests/test_util.py | 6 ++- .../create_sites_and_configurations.py | 7 +++- .../tests/test_sync_hubspot_contacts.py | 1 + .../content_type_gating/tests/test_models.py | 30 ++++++++++--- .../tests/test_models.py | 22 ++++++++-- .../tests/test_discount_restriction_models.py | 7 +++- 21 files changed, 195 insertions(+), 40 deletions(-) create mode 100644 openedx/core/djangoapps/site_configuration/migrations/0003_add_site_values_field.py diff --git a/lms/djangoapps/discussion/tests/test_signals.py b/lms/djangoapps/discussion/tests/test_signals.py index f30a422e0a15..e303bc11c9be 100644 --- a/lms/djangoapps/discussion/tests/test_signals.py +++ b/lms/djangoapps/discussion/tests/test_signals.py @@ -28,7 +28,9 @@ def setUp(self): @mock.patch('lms.djangoapps.discussion.signals.handlers.send_message') def test_comment_created_signal_sends_message(self, mock_send_message, mock_get_current_site): site_config = SiteConfigurationFactory.create(site=self.site) - site_config.values[ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY] = True + enable_notifications_cfg = {ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY: True} + site_config.site_values = enable_notifications_cfg + site_config.values = enable_notifications_cfg site_config.save() mock_get_current_site.return_value = self.site signals.comment_created.send(sender=self.sender, user=self.user, post=self.post) @@ -56,7 +58,9 @@ def test_comment_created_signal_msg_not_sent_with_site_config_disabled( self, mock_send_message, mock_get_current_site ): site_config = SiteConfigurationFactory.create(site=self.site) - site_config.values[ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY] = False + enable_notifications_cfg = {ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY: False} + site_config.site_values = enable_notifications_cfg + site_config.values = enable_notifications_cfg site_config.save() mock_get_current_site.return_value = self.site signals.comment_created.send(sender=self.sender, user=self.user, post=self.post) diff --git a/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py b/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py index f3ee5954e599..52deefd82fe2 100644 --- a/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py +++ b/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py @@ -168,7 +168,12 @@ def test_membership_reason_field_visibility(self, enbale_reason_field): "ENABLE_MANUAL_ENROLLMENT_REASON_FIELD": enbale_reason_field } site = Site.objects.first() - SiteConfiguration.objects.create(site=site, values=configuration_values, enabled=True) + SiteConfiguration.objects.create( + site=site, + site_values=configuration_values, + values=configuration_values, + enabled=True + ) url = reverse( 'instructor_dashboard', @@ -196,7 +201,12 @@ def test_membership_site_configuration_role(self): ] } site = Site.objects.first() - SiteConfiguration.objects.create(site=site, values=configuration_values, enabled=True) + SiteConfiguration.objects.create( + site=site, + site_values=configuration_values, + values=configuration_values, + enabled=True + ) url = reverse( 'instructor_dashboard', kwargs={ diff --git a/openedx/core/djangoapps/ace_common/tests/test_tracking.py b/openedx/core/djangoapps/ace_common/tests/test_tracking.py index 85f71eaf94c8..1412acf25283 100644 --- a/openedx/core/djangoapps/ace_common/tests/test_tracking.py +++ b/openedx/core/djangoapps/ace_common/tests/test_tracking.py @@ -122,6 +122,9 @@ def test_missing_settings(self): @override_settings(GOOGLE_ANALYTICS_TRACKING_ID='UA-123456-1') def test_site_config_override(self): site_config = SiteConfigurationFactory.create( + site_values=dict( + GOOGLE_ANALYTICS_ACCOUNT='UA-654321-1' + ), values=dict( GOOGLE_ANALYTICS_ACCOUNT='UA-654321-1' ) diff --git a/openedx/core/djangoapps/catalog/views.py b/openedx/core/djangoapps/catalog/views.py index ecc1fd381fb3..41874667c1ee 100644 --- a/openedx/core/djangoapps/catalog/views.py +++ b/openedx/core/djangoapps/catalog/views.py @@ -27,6 +27,7 @@ def cache_programs(request): SiteConfiguration.objects.create( site=request.site, enabled=True, + site_values={"COURSE_CATALOG_API_URL": "{catalog_url}/api/v1/".format(catalog_url=CATALOG_STUB_URL)}, values={"COURSE_CATALOG_API_URL": "{catalog_url}/api/v1/".format(catalog_url=CATALOG_STUB_URL)} ) diff --git a/openedx/core/djangoapps/credentials/management/commands/tests/test_notify_credentials.py b/openedx/core/djangoapps/credentials/management/commands/tests/test_notify_credentials.py index a987d393e1a1..98c2d5e4d01a 100644 --- a/openedx/core/djangoapps/credentials/management/commands/tests/test_notify_credentials.py +++ b/openedx/core/djangoapps/credentials/management/commands/tests/test_notify_credentials.py @@ -127,6 +127,7 @@ def test_page_size(self): @mock.patch(COMMAND_MODULE + '.handle_cert_change') def test_site(self, mock_grade_interesting, mock_cert_change): site_config = SiteConfigurationFactory.create( + site_values={'course_org_filter': ['testX']}, values={'course_org_filter': ['testX']}, ) diff --git a/openedx/core/djangoapps/credentials/tests/test_signals.py b/openedx/core/djangoapps/credentials/tests/test_signals.py index 0ad7d47bc459..ef2a8196d525 100644 --- a/openedx/core/djangoapps/credentials/tests/test_signals.py +++ b/openedx/core/djangoapps/credentials/tests/test_signals.py @@ -110,6 +110,7 @@ def test_send_grade_without_issuance_enabled(self, _mock_is_course_run_in_a_prog def test_send_grade_records_enabled(self, _mock_is_course_run_in_a_program, mock_send_grade_to_credentials, _mock_is_learner_issuance_enabled): site_config = SiteConfigurationFactory.create( + site_values={'course_org_filter': [self.key.org]}, values={'course_org_filter': [self.key.org]}, ) diff --git a/openedx/core/djangoapps/programs/tests/test_signals.py b/openedx/core/djangoapps/programs/tests/test_signals.py index 1a524bb395ad..82c5299cb7b5 100644 --- a/openedx/core/djangoapps/programs/tests/test_signals.py +++ b/openedx/core/djangoapps/programs/tests/test_signals.py @@ -146,6 +146,7 @@ def test_records_enabled(self, mock_is_learner_issuance_enabled, mock_task): mock_is_learner_issuance_enabled.return_value = True site_config = SiteConfigurationFactory.create( + site_values={'course_org_filter': ['edX']}, values={'course_org_filter': ['edX']}, ) diff --git a/openedx/core/djangoapps/schedules/management/commands/tests/send_email_base.py b/openedx/core/djangoapps/schedules/management/commands/tests/send_email_base.py index c7651388d3d8..1296b87e20f4 100644 --- a/openedx/core/djangoapps/schedules/management/commands/tests/send_email_base.py +++ b/openedx/core/djangoapps/schedules/management/commands/tests/send_email_base.py @@ -306,8 +306,14 @@ def test_enqueue_config(self, is_enabled): def test_site_config(self, this_org_list, other_org_list, expected_message_count, mock_ace): filtered_org = 'filtered_org' unfiltered_org = 'unfiltered_org' - this_config = SiteConfigurationFactory.create(values={'course_org_filter': this_org_list}) - other_config = SiteConfigurationFactory.create(values={'course_org_filter': other_org_list}) + this_config = SiteConfigurationFactory.create( + site_values={'course_org_filter': this_org_list}, + values={'course_org_filter': this_org_list} + ) + other_config = SiteConfigurationFactory.create( + site_values={'course_org_filter': other_org_list}, + values={'course_org_filter': other_org_list} + ) for config in (this_config, other_config): ScheduleConfigFactory.create(site=config.site) diff --git a/openedx/core/djangoapps/schedules/tests/test_resolvers.py b/openedx/core/djangoapps/schedules/tests/test_resolvers.py index e47458f5e897..83c801b9b154 100644 --- a/openedx/core/djangoapps/schedules/tests/test_resolvers.py +++ b/openedx/core/djangoapps/schedules/tests/test_resolvers.py @@ -88,6 +88,7 @@ def test_get_course_org_filter_include__in(self, course_org_filter, expected_org ) def test_get_course_org_filter_exclude__in(self, course_org_filter, expected_org_list): SiteConfigurationFactory.create( + site_values={'course_org_filter': course_org_filter}, values={'course_org_filter': course_org_filter}, ) mock_query = Mock() diff --git a/openedx/core/djangoapps/site_configuration/management/commands/create_site_configuration.py b/openedx/core/djangoapps/site_configuration/management/commands/create_site_configuration.py index c35ba87c7872..82ecf83cf157 100644 --- a/openedx/core/djangoapps/site_configuration/management/commands/create_site_configuration.py +++ b/openedx/core/djangoapps/site_configuration/management/commands/create_site_configuration.py @@ -47,4 +47,9 @@ def handle(self, *args, **options): LOG.info(u"Found existing site for '{site_name}'".format(site_name=domain)) LOG.info(u"Creating '{site_name}' SiteConfiguration".format(site_name=domain)) - SiteConfiguration.objects.create(site=site, values=configuration, enabled=True) + SiteConfiguration.objects.create( + site=site, + site_values=configuration, + values=configuration, + enabled=True + ) diff --git a/openedx/core/djangoapps/site_configuration/migrations/0003_add_site_values_field.py b/openedx/core/djangoapps/site_configuration/migrations/0003_add_site_values_field.py new file mode 100644 index 000000000000..e9750d686888 --- /dev/null +++ b/openedx/core/djangoapps/site_configuration/migrations/0003_add_site_values_field.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.27 on 2020-01-02 22:05 +from __future__ import unicode_literals + +from django.db import migrations +import jsonfield.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('site_configuration', '0002_auto_20160720_0231'), + ] + + operations = [ + migrations.AddField( + model_name='siteconfiguration', + name='site_values', + field=jsonfield.fields.JSONField(blank=True), + ), + migrations.AddField( + model_name='siteconfigurationhistory', + name='site_values', + field=jsonfield.fields.JSONField(blank=True), + ), + ] diff --git a/openedx/core/djangoapps/site_configuration/models.py b/openedx/core/djangoapps/site_configuration/models.py index fb5d885447f8..42869389835b 100644 --- a/openedx/core/djangoapps/site_configuration/models.py +++ b/openedx/core/djangoapps/site_configuration/models.py @@ -25,12 +25,19 @@ class SiteConfiguration(models.Model): Fields: site (OneToOneField): one to one field relating each configuration to a single site - values (JSONField): json field to store configurations for a site + site_values (JSONField): json field to store configurations for a site .. no_pii: """ site = models.OneToOneField(Site, related_name='configuration', on_delete=models.CASCADE) enabled = models.BooleanField(default=False, verbose_name=u"Enabled") + site_values = JSONField( + null=False, + blank=True, + load_kwargs={'object_pairs_hook': collections.OrderedDict} + ) + # TODO: Delete this deprecated field during the later stages of the rollout + # which renames 'values' to 'site_values'. values = JSONField( null=False, blank=True, @@ -146,12 +153,19 @@ class SiteConfigurationHistory(TimeStampedModel): Fields: site (ForeignKey): foreign-key to django Site - values (JSONField): json field to store configurations for a site + site_values (JSONField): json field to store configurations for a site .. no_pii: """ site = models.ForeignKey(Site, related_name='configuration_histories', on_delete=models.CASCADE) enabled = models.BooleanField(default=False, verbose_name=u"Enabled") + site_values = JSONField( + null=False, + blank=True, + load_kwargs={'object_pairs_hook': collections.OrderedDict} + ) + # TODO: Delete this deprecated field during the later stages of the rollout + # which renames 'values' to 'site_values'. values = JSONField( null=False, blank=True, @@ -185,6 +199,7 @@ def update_site_configuration_history(sender, instance, **kwargs): # pylint: di """ SiteConfigurationHistory.objects.create( site=instance.site, + site_values=instance.values, values=instance.values, enabled=instance.enabled, ) diff --git a/openedx/core/djangoapps/site_configuration/tests/mixins.py b/openedx/core/djangoapps/site_configuration/tests/mixins.py index 6c30b747b938..95294d289192 100644 --- a/openedx/core/djangoapps/site_configuration/tests/mixins.py +++ b/openedx/core/djangoapps/site_configuration/tests/mixins.py @@ -14,33 +14,39 @@ def setUp(self): super(SiteMixin, self).setUp() self.site = SiteFactory.create() + site_config = { + "SITE_NAME": self.site.domain, + "course_email_from_addr": "fake@example.com", + "course_email_template_name": "fake_email_template", + "course_org_filter": "fakeX" + } self.site_configuration = SiteConfigurationFactory.create( site=self.site, - values={ - "SITE_NAME": self.site.domain, - "course_email_from_addr": "fake@example.com", - "course_email_template_name": "fake_email_template", - "course_org_filter": "fakeX" - } + site_values=site_config, + # TODO: Remove this deprecated value eventually. + values=site_config ) self.site_other = SiteFactory.create( domain='testserver.fakeother', name='testserver.fakeother' ) + site_config_other = { + "SITE_NAME": self.site_other.domain, + "SESSION_COOKIE_DOMAIN": self.site_other.domain, + "course_org_filter": "fakeOtherX", + "ENABLE_MKTG_SITE": True, + "SHOW_ECOMMERCE_REPORTS": True, + "MKTG_URLS": { + "ROOT": "https://marketing.fakeother", + "ABOUT": "/fake-about" + } + } self.site_configuration_other = SiteConfigurationFactory.create( site=self.site_other, - values={ - "SITE_NAME": self.site_other.domain, - "SESSION_COOKIE_DOMAIN": self.site_other.domain, - "course_org_filter": "fakeOtherX", - "ENABLE_MKTG_SITE": True, - "SHOW_ECOMMERCE_REPORTS": True, - "MKTG_URLS": { - "ROOT": "https://marketing.fakeother", - "ABOUT": "/fake-about" - } - } + site_values=site_config_other, + # TODO: Remove this deprecated value eventually. + values=site_config_other ) # Initialize client with default site domain @@ -56,6 +62,8 @@ def set_up_site(self, domain, site_configuration_values): ) __ = SiteConfigurationFactory.create( site=site, + site_values=site_configuration_values, + # TODO: Remove this deprecated value eventually. values=site_configuration_values ) self.use_site(site) diff --git a/openedx/core/djangoapps/site_configuration/tests/test_middleware.py b/openedx/core/djangoapps/site_configuration/tests/test_middleware.py index 890c6453c2df..c66ec84114d8 100644 --- a/openedx/core/djangoapps/site_configuration/tests/test_middleware.py +++ b/openedx/core/djangoapps/site_configuration/tests/test_middleware.py @@ -41,6 +41,9 @@ def setUp(self): ) self.site_configuration = SiteConfigurationFactory.create( site=self.site, + site_values={ + "SESSION_COOKIE_DOMAIN": self.site.domain, + }, values={ "SESSION_COOKIE_DOMAIN": self.site.domain, } @@ -76,6 +79,9 @@ def setUp(self): ) self.site_configuration = SiteConfigurationFactory.create( site=self.site, + site_values={ + "SESSION_COOKIE_DOMAIN": self.site.domain, + }, values={ "SESSION_COOKIE_DOMAIN": self.site.domain, } diff --git a/openedx/core/djangoapps/site_configuration/tests/test_models.py b/openedx/core/djangoapps/site_configuration/tests/test_models.py index 0200c5881235..4b69d57f5870 100644 --- a/openedx/core/djangoapps/site_configuration/tests/test_models.py +++ b/openedx/core/djangoapps/site_configuration/tests/test_models.py @@ -82,6 +82,8 @@ def test_site_configuration_post_update_receiver(self): site=self.site, ) + site_configuration.site_values = {'test': 'test'} + # TODO: Remove this deprecated value eventually. site_configuration.values = {'test': 'test'} site_configuration.save() @@ -131,6 +133,8 @@ def test_get_value(self): # add SiteConfiguration to database site_configuration = SiteConfigurationFactory.create( site=self.site, + site_values=self.test_config1, + # TODO: Remove this deprecated value eventually. values=self.test_config1, ) @@ -179,6 +183,8 @@ def test_invalid_data_error_on_get_value(self): # add SiteConfiguration to database site_configuration = SiteConfigurationFactory.create( site=self.site, + site_values=invalid_data, + # TODO: Remove this deprecated value eventually. values=invalid_data, ) @@ -200,10 +206,14 @@ def test_get_value_for_org(self): # add SiteConfiguration to database SiteConfigurationFactory.create( site=self.site, + site_values=self.test_config1, + # TODO: Remove this deprecated value eventually. values=self.test_config1, ) SiteConfigurationFactory.create( site=self.site2, + site_values=self.test_config2, + # TODO: Remove this deprecated value eventually. values=self.test_config2, ) @@ -285,10 +295,14 @@ def test_get_site_for_org(self): # add SiteConfiguration to database config1 = SiteConfigurationFactory.create( site=self.site, + site_values=self.test_config1, + # TODO: Remove this deprecated value eventually. values=self.test_config1, ) config2 = SiteConfigurationFactory.create( site=self.site2, + site_values=self.test_config2, + # TODO: Remove this deprecated value eventually. values=self.test_config2, ) @@ -314,10 +328,14 @@ def test_get_all_orgs(self): # add SiteConfiguration to database SiteConfigurationFactory.create( site=self.site, + site_values=self.test_config1, + # TODO: Remove this deprecated value eventually. values=self.test_config1, ) SiteConfigurationFactory.create( site=self.site2, + site_values=self.test_config2, + # TODO: Remove this deprecated value eventually. values=self.test_config2, ) @@ -332,11 +350,15 @@ def test_get_all_orgs_returns_only_enabled(self): # add SiteConfiguration to database SiteConfigurationFactory.create( site=self.site, + site_values=self.test_config1, + # TODO: Remove this deprecated value eventually. values=self.test_config1, enabled=False, ) SiteConfigurationFactory.create( site=self.site2, + site_values=self.test_config2, + # TODO: Remove this deprecated value eventually. values=self.test_config2, ) diff --git a/openedx/core/djangoapps/site_configuration/tests/test_util.py b/openedx/core/djangoapps/site_configuration/tests/test_util.py index bd6277dcc80b..6c13a5fadc14 100644 --- a/openedx/core/djangoapps/site_configuration/tests/test_util.py +++ b/openedx/core/djangoapps/site_configuration/tests/test_util.py @@ -29,9 +29,10 @@ def _decorated(*args, **kwargs): # pylint: disable=missing-docstring site, __ = Site.objects.get_or_create(domain=domain, name=domain) site_configuration, created = SiteConfiguration.objects.get_or_create( site=site, - defaults={"enabled": True, "values": configuration}, + defaults={"enabled": True, "site_values": configuration, "values": configuration}, ) if not created: + site_configuration.site_values = configuration site_configuration.values = configuration site_configuration.save() @@ -56,9 +57,10 @@ def with_site_configuration_context(domain="test.localhost", configuration=None) site, __ = Site.objects.get_or_create(domain=domain, name=domain) site_configuration, created = SiteConfiguration.objects.get_or_create( site=site, - defaults={"enabled": True, "values": configuration}, + defaults={"enabled": True, "site_values": configuration, "values": configuration}, ) if not created: + site_configuration.site_values = configuration site_configuration.values = configuration site_configuration.save() diff --git a/openedx/core/djangoapps/theming/management/commands/create_sites_and_configurations.py b/openedx/core/djangoapps/theming/management/commands/create_sites_and_configurations.py index 148655a43e47..255188c719ea 100644 --- a/openedx/core/djangoapps/theming/management/commands/create_sites_and_configurations.py +++ b/openedx/core/djangoapps/theming/management/commands/create_sites_and_configurations.py @@ -109,7 +109,12 @@ def _create_sites(self, site_domain, theme_dir_name, site_configuration): SiteTheme.objects.create(site=site, theme_dir_name=theme_dir_name) LOG.info(u"Creating '{site_name}' SiteConfiguration".format(site_name=site_domain)) - SiteConfiguration.objects.create(site=site, values=site_configuration, enabled=True) + SiteConfiguration.objects.create( + site=site, + site_values=site_configuration, + values=site_configuration, + enabled=True + ) else: LOG.info(u"'{site_domain}' site already exists".format(site_domain=site_domain)) diff --git a/openedx/core/djangoapps/user_api/management/tests/test_sync_hubspot_contacts.py b/openedx/core/djangoapps/user_api/management/tests/test_sync_hubspot_contacts.py index 912a5e4fcf0e..d61bd05f484a 100644 --- a/openedx/core/djangoapps/user_api/management/tests/test_sync_hubspot_contacts.py +++ b/openedx/core/djangoapps/user_api/management/tests/test_sync_hubspot_contacts.py @@ -31,6 +31,7 @@ def setUpClass(cls): super(TestHubspotSyncCommand, cls).setUpClass() cls.site_config = SiteConfigurationFactory() cls.hubspot_site_config = SiteConfigurationFactory.create( + site_values={'HUBSPOT_API_KEY': 'test_key'}, values={'HUBSPOT_API_KEY': 'test_key'}, ) cls.users = [] diff --git a/openedx/features/content_type_gating/tests/test_models.py b/openedx/features/content_type_gating/tests/test_models.py index a13c6bf75658..c6cf276bdcfb 100644 --- a/openedx/features/content_type_gating/tests/test_models.py +++ b/openedx/features/content_type_gating/tests/test_models.py @@ -131,8 +131,14 @@ def test_config_overrides(self, global_setting, site_setting, org_setting, cours # there are no leaks of configuration across contexts non_test_course_enabled = CourseOverviewFactory.create(org='non-test-org-enabled') non_test_course_disabled = CourseOverviewFactory.create(org='non-test-org-disabled') - non_test_site_cfg_enabled = SiteConfigurationFactory.create(values={'course_org_filter': non_test_course_enabled.org}) - non_test_site_cfg_disabled = SiteConfigurationFactory.create(values={'course_org_filter': non_test_course_disabled.org}) + non_test_site_cfg_enabled = SiteConfigurationFactory.create( + site_values={'course_org_filter': non_test_course_enabled.org}, + values={'course_org_filter': non_test_course_enabled.org} + ) + non_test_site_cfg_disabled = SiteConfigurationFactory.create( + site_values={'course_org_filter': non_test_course_disabled.org}, + values={'course_org_filter': non_test_course_disabled.org} + ) ContentTypeGatingConfig.objects.create(course=non_test_course_enabled, enabled=True, enabled_as_of=datetime(2018, 1, 1)) ContentTypeGatingConfig.objects.create(course=non_test_course_disabled, enabled=False) @@ -143,7 +149,10 @@ def test_config_overrides(self, global_setting, site_setting, org_setting, cours # Set up test objects test_course = CourseOverviewFactory.create(org='test-org') - test_site_cfg = SiteConfigurationFactory.create(values={'course_org_filter': test_course.org}) + test_site_cfg = SiteConfigurationFactory.create( + site_values={'course_org_filter': test_course.org}, + values={'course_org_filter': test_course.org} + ) ContentTypeGatingConfig.objects.create(enabled=global_setting, enabled_as_of=datetime(2018, 1, 1)) ContentTypeGatingConfig.objects.create(course=test_course, enabled=course_setting, enabled_as_of=datetime(2018, 1, 1)) @@ -166,7 +175,10 @@ def test_all_current_course_configs(self): for global_setting in (True, False, None): ContentTypeGatingConfig.objects.create(enabled=global_setting, enabled_as_of=datetime(2018, 1, 1)) for site_setting in (True, False, None): - test_site_cfg = SiteConfigurationFactory.create(values={'course_org_filter': []}) + test_site_cfg = SiteConfigurationFactory.create( + site_values={'course_org_filter': []}, + values={'course_org_filter': []} + ) ContentTypeGatingConfig.objects.create(site=test_site_cfg.site, enabled=site_setting, enabled_as_of=datetime(2018, 1, 1)) for org_setting in (True, False, None): @@ -279,7 +291,10 @@ def test_caching_site(self): def test_caching_org(self): course = CourseOverviewFactory.create(org='test-org') - site_cfg = SiteConfigurationFactory.create(values={'course_org_filter': course.org}) + site_cfg = SiteConfigurationFactory.create( + site_values={'course_org_filter': course.org}, + values={'course_org_filter': course.org} + ) org_config = ContentTypeGatingConfig(org=course.org, enabled=True, enabled_as_of=datetime(2018, 1, 1)) org_config.save() @@ -324,7 +339,10 @@ def test_caching_org(self): def test_caching_course(self): course = CourseOverviewFactory.create(org='test-org') - site_cfg = SiteConfigurationFactory.create(values={'course_org_filter': course.org}) + site_cfg = SiteConfigurationFactory.create( + site_values={'course_org_filter': course.org}, + values={'course_org_filter': course.org} + ) course_config = ContentTypeGatingConfig(course=course, enabled=True, enabled_as_of=datetime(2018, 1, 1)) course_config.save() diff --git a/openedx/features/course_duration_limits/tests/test_models.py b/openedx/features/course_duration_limits/tests/test_models.py index 58078777f1a9..fe4865fd774c 100644 --- a/openedx/features/course_duration_limits/tests/test_models.py +++ b/openedx/features/course_duration_limits/tests/test_models.py @@ -142,9 +142,11 @@ def test_config_overrides(self, global_setting, site_setting, org_setting, cours non_test_course_enabled = CourseOverviewFactory.create(org='non-test-org-enabled') non_test_course_disabled = CourseOverviewFactory.create(org='non-test-org-disabled') non_test_site_cfg_enabled = SiteConfigurationFactory.create( + site_values={'course_org_filter': non_test_course_enabled.org}, values={'course_org_filter': non_test_course_enabled.org} ) non_test_site_cfg_disabled = SiteConfigurationFactory.create( + site_values={'course_org_filter': non_test_course_disabled.org}, values={'course_org_filter': non_test_course_disabled.org} ) @@ -157,7 +159,10 @@ def test_config_overrides(self, global_setting, site_setting, org_setting, cours # Set up test objects test_course = CourseOverviewFactory.create(org='test-org') - test_site_cfg = SiteConfigurationFactory.create(values={'course_org_filter': test_course.org}) + test_site_cfg = SiteConfigurationFactory.create( + site_values={'course_org_filter': test_course.org}, + values={'course_org_filter': test_course.org} + ) if reverse_order: CourseDurationLimitConfig.objects.create(site=test_site_cfg.site, enabled=site_setting) @@ -185,7 +190,10 @@ def test_all_current_course_configs(self): for global_setting in (True, False, None): CourseDurationLimitConfig.objects.create(enabled=global_setting, enabled_as_of=datetime(2018, 1, 1)) for site_setting in (True, False, None): - test_site_cfg = SiteConfigurationFactory.create(values={'course_org_filter': []}) + test_site_cfg = SiteConfigurationFactory.create( + site_values={'course_org_filter': []}, + values={'course_org_filter': []} + ) CourseDurationLimitConfig.objects.create( site=test_site_cfg.site, enabled=site_setting, enabled_as_of=datetime(2018, 1, 1) ) @@ -301,7 +309,10 @@ def test_caching_site(self): def test_caching_org(self): course = CourseOverviewFactory.create(org='test-org') - site_cfg = SiteConfigurationFactory.create(values={'course_org_filter': course.org}) + site_cfg = SiteConfigurationFactory.create( + site_values={'course_org_filter': course.org}, + values={'course_org_filter': course.org} + ) org_config = CourseDurationLimitConfig(org=course.org, enabled=True, enabled_as_of=datetime(2018, 1, 1)) org_config.save() @@ -346,7 +357,10 @@ def test_caching_org(self): def test_caching_course(self): course = CourseOverviewFactory.create(org='test-org') - site_cfg = SiteConfigurationFactory.create(values={'course_org_filter': course.org}) + site_cfg = SiteConfigurationFactory.create( + site_values={'course_org_filter': course.org}, + values={'course_org_filter': course.org} + ) course_config = CourseDurationLimitConfig(course=course, enabled=True, enabled_as_of=datetime(2018, 1, 1)) course_config.save() diff --git a/openedx/features/discounts/tests/test_discount_restriction_models.py b/openedx/features/discounts/tests/test_discount_restriction_models.py index 60343d052a36..1de2ca7c7202 100644 --- a/openedx/features/discounts/tests/test_discount_restriction_models.py +++ b/openedx/features/discounts/tests/test_discount_restriction_models.py @@ -59,9 +59,11 @@ def test_config_overrides(self, global_setting, site_setting, org_setting, cours non_test_course_disabled = CourseOverviewFactory.create(org='non-test-org-disabled') non_test_course_enabled = CourseOverviewFactory.create(org='non-test-org-enabled') non_test_site_cfg_disabled = SiteConfigurationFactory.create( + site_values={'course_org_filter': non_test_course_disabled.org}, values={'course_org_filter': non_test_course_disabled.org} ) non_test_site_cfg_enabled = SiteConfigurationFactory.create( + site_values={'course_org_filter': non_test_course_enabled.org}, values={'course_org_filter': non_test_course_enabled.org} ) @@ -74,7 +76,10 @@ def test_config_overrides(self, global_setting, site_setting, org_setting, cours # Set up test objects test_course = CourseOverviewFactory.create(org='test-org') - test_site_cfg = SiteConfigurationFactory.create(values={'course_org_filter': test_course.org}) + test_site_cfg = SiteConfigurationFactory.create( + site_values={'course_org_filter': test_course.org}, + values={'course_org_filter': test_course.org} + ) DiscountRestrictionConfig.objects.create(disabled=global_setting) DiscountRestrictionConfig.objects.create(course=test_course, disabled=course_setting) From 01bfcf51231b81c4d8efcdd7a31a47ffe7550c7d Mon Sep 17 00:00:00 2001 From: Julia Eskew Date: Fri, 3 Jan 2020 16:16:16 -0500 Subject: [PATCH 2/3] Rename values in SiteConfiguration (2/3) This stage does the following: - Includes a data migration to copy the values from old to new field. - Changes business logic to switch to using new field. - Deletes all code references of the old field. --- common/djangoapps/student/admin.py | 2 +- .../student/tests/test_admin_views.py | 4 +- common/djangoapps/util/tests/test_db.py | 2 +- lms/djangoapps/branding/tests/test_views.py | 4 +- .../discussion/tests/test_signals.py | 2 - lms/djangoapps/discussion/tests/test_tasks.py | 2 +- lms/djangoapps/instructor/tests/test_api.py | 6 +-- .../tests/views/test_instructor_dashboard.py | 2 - .../ace_common/tests/test_tracking.py | 3 -- openedx/core/djangoapps/catalog/views.py | 3 +- .../djangoapps/config_model_utils/models.py | 4 +- .../commands/tests/test_notify_credentials.py | 3 +- .../credentials/tests/test_signals.py | 5 +-- .../programs/tasks/v1/tests/test_tasks.py | 2 +- .../djangoapps/programs/tests/test_signals.py | 5 +-- .../commands/tests/send_email_base.py | 6 +-- .../schedules/tests/test_resolvers.py | 7 ++-- .../djangoapps/site_configuration/admin.py | 6 +-- .../djangoapps/site_configuration/helpers.py | 2 +- .../commands/create_site_configuration.py | 1 - .../tests/test_create_site_configuration.py | 2 +- .../0004_copy_values_to_site_values.py | 29 ++++++++++++++ .../djangoapps/site_configuration/models.py | 23 ++--------- .../site_configuration/tests/factories.py | 2 +- .../site_configuration/tests/mixins.py | 12 ++---- .../tests/test_middleware.py | 6 --- .../site_configuration/tests/test_models.py | 40 +++++-------------- .../site_configuration/tests/test_util.py | 6 +-- .../create_sites_and_configurations.py | 1 - .../tests/test_sync_hubspot_contacts.py | 9 ++--- .../content_type_gating/tests/test_models.py | 20 ++++------ .../tests/test_models.py | 20 ++++------ .../tests/test_discount_restriction_models.py | 9 ++--- 33 files changed, 98 insertions(+), 152 deletions(-) create mode 100644 openedx/core/djangoapps/site_configuration/migrations/0004_copy_values_to_site_values.py diff --git a/common/djangoapps/student/admin.py b/common/djangoapps/student/admin.py index 2d536e749cb1..eddb8c61bfc1 100644 --- a/common/djangoapps/student/admin.py +++ b/common/djangoapps/student/admin.py @@ -460,7 +460,7 @@ def clean_email(self): if not allowed_site_email_domain: raise forms.ValidationError( _("Please add a key/value 'THIRD_PARTY_AUTH_ONLY_DOMAIN/{site_email_domain}' in SiteConfiguration " - "model's values field.") + "model's site_values field.") ) elif email_domain != allowed_site_email_domain: raise forms.ValidationError( diff --git a/common/djangoapps/student/tests/test_admin_views.py b/common/djangoapps/student/tests/test_admin_views.py index 7a5f363b3e24..21840fe2451f 100644 --- a/common/djangoapps/student/tests/test_admin_views.py +++ b/common/djangoapps/student/tests/test_admin_views.py @@ -454,7 +454,7 @@ def setUpClass(cls): def _update_site_configuration(self): """ Updates the site's configuration """ - self.site.configuration.values = {'THIRD_PARTY_AUTH_ONLY_DOMAIN': self.email_domain_name} + self.site.configuration.site_values = {'THIRD_PARTY_AUTH_ONLY_DOMAIN': self.email_domain_name} self.site.configuration.save() def _assert_form(self, site, email, is_valid_form=False): @@ -480,7 +480,7 @@ def test_form_with_invalid_site_configuration(self): self.assertEqual( error, "Please add a key/value 'THIRD_PARTY_AUTH_ONLY_DOMAIN/{site_email_domain}' in SiteConfiguration " - "model's values field." + "model's site_values field." ) def test_form_with_invalid_domain_name(self): diff --git a/common/djangoapps/util/tests/test_db.py b/common/djangoapps/util/tests/test_db.py index ddeea5cb0f76..0667a44a9350 100644 --- a/common/djangoapps/util/tests/test_db.py +++ b/common/djangoapps/util/tests/test_db.py @@ -221,7 +221,7 @@ class MigrationTests(TestCase): """ Tests for migrations. """ - + @unittest.skip("Need to skip as part of a 3-release rollout to rename a field in the site_configuration app. This will be unskipped in DE-1826.") @override_settings(MIGRATION_MODULES={}) def test_migrations_are_in_sync(self): """ diff --git a/lms/djangoapps/branding/tests/test_views.py b/lms/djangoapps/branding/tests/test_views.py index 8b2ffc95d28a..1f11b2da8148 100644 --- a/lms/djangoapps/branding/tests/test_views.py +++ b/lms/djangoapps/branding/tests/test_views.py @@ -297,7 +297,7 @@ def test_index_redirects_to_marketing_site_with_site_override(self): response = self.client.get(reverse("root")) self.assertRedirects( response, - self.site_configuration_other.values["MKTG_URLS"]["ROOT"], + self.site_configuration_other.site_values["MKTG_URLS"]["ROOT"], fetch_redirect_response=False ) @@ -309,4 +309,4 @@ def test_header_logo_links_to_marketing_site_with_site_override(self): self.use_site(self.site_other) self.client.login(username=self.user.username, password="password") response = self.client.get(reverse("dashboard")) - self.assertIn(self.site_configuration_other.values["MKTG_URLS"]["ROOT"], response.content.decode('utf-8')) + self.assertIn(self.site_configuration_other.site_values["MKTG_URLS"]["ROOT"], response.content.decode('utf-8')) diff --git a/lms/djangoapps/discussion/tests/test_signals.py b/lms/djangoapps/discussion/tests/test_signals.py index e303bc11c9be..14d588714415 100644 --- a/lms/djangoapps/discussion/tests/test_signals.py +++ b/lms/djangoapps/discussion/tests/test_signals.py @@ -30,7 +30,6 @@ def test_comment_created_signal_sends_message(self, mock_send_message, mock_get_ site_config = SiteConfigurationFactory.create(site=self.site) enable_notifications_cfg = {ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY: True} site_config.site_values = enable_notifications_cfg - site_config.values = enable_notifications_cfg site_config.save() mock_get_current_site.return_value = self.site signals.comment_created.send(sender=self.sender, user=self.user, post=self.post) @@ -60,7 +59,6 @@ def test_comment_created_signal_msg_not_sent_with_site_config_disabled( site_config = SiteConfigurationFactory.create(site=self.site) enable_notifications_cfg = {ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY: False} site_config.site_values = enable_notifications_cfg - site_config.values = enable_notifications_cfg site_config.save() mock_get_current_site.return_value = self.site signals.comment_created.send(sender=self.sender, user=self.user, post=self.post) diff --git a/lms/djangoapps/discussion/tests/test_tasks.py b/lms/djangoapps/discussion/tests/test_tasks.py index c6a8b64ebbc0..4161792a98e7 100644 --- a/lms/djangoapps/discussion/tests/test_tasks.py +++ b/lms/djangoapps/discussion/tests/test_tasks.py @@ -193,7 +193,7 @@ def test_send_discussion_email_notification(self, user_subscribed): comment = cc.Comment.find(id=self.comment['id']).retrieve() site = Site.objects.get_current() site_config = SiteConfigurationFactory.create(site=site) - site_config.values[ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY] = True + site_config.site_values[ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY] = True site_config.save() with mock.patch('lms.djangoapps.discussion.signals.handlers.get_current_site', return_value=site): comment_created.send(sender=None, user=user, post=comment) diff --git a/lms/djangoapps/instructor/tests/test_api.py b/lms/djangoapps/instructor/tests/test_api.py index b1d56fd42304..2ee50f3579f9 100644 --- a/lms/djangoapps/instructor/tests/test_api.py +++ b/lms/djangoapps/instructor/tests/test_api.py @@ -3990,8 +3990,8 @@ def test_send_email_no_message(self): self.assertEqual(response.status_code, 400) def test_send_email_with_site_template_and_from_addr(self): - site_email = self.site_configuration.values.get('course_email_from_addr') - site_template = self.site_configuration.values.get('course_email_template_name') + site_email = self.site_configuration.site_values.get('course_email_from_addr') + site_template = self.site_configuration.site_values.get('course_email_template_name') CourseEmailTemplate.objects.create(name=site_template) url = reverse('send_email', kwargs={'course_id': text_type(self.course.id)}) response = self.client.post(url, self.full_test_message) @@ -4009,7 +4009,7 @@ def test_send_email_with_org_template_and_from_addr(self): org_email = 'fake_org@example.com' org_template = 'fake_org_email_template' CourseEmailTemplate.objects.create(name=org_template) - self.site_configuration.values.update({ + self.site_configuration.site_values.update({ 'course_email_from_addr': {self.course.id.org: org_email}, 'course_email_template_name': {self.course.id.org: org_template} }) diff --git a/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py b/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py index 52deefd82fe2..34aaa2567dc3 100644 --- a/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py +++ b/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py @@ -171,7 +171,6 @@ def test_membership_reason_field_visibility(self, enbale_reason_field): SiteConfiguration.objects.create( site=site, site_values=configuration_values, - values=configuration_values, enabled=True ) @@ -204,7 +203,6 @@ def test_membership_site_configuration_role(self): SiteConfiguration.objects.create( site=site, site_values=configuration_values, - values=configuration_values, enabled=True ) url = reverse( diff --git a/openedx/core/djangoapps/ace_common/tests/test_tracking.py b/openedx/core/djangoapps/ace_common/tests/test_tracking.py index 1412acf25283..62013620551d 100644 --- a/openedx/core/djangoapps/ace_common/tests/test_tracking.py +++ b/openedx/core/djangoapps/ace_common/tests/test_tracking.py @@ -124,9 +124,6 @@ def test_site_config_override(self): site_config = SiteConfigurationFactory.create( site_values=dict( GOOGLE_ANALYTICS_ACCOUNT='UA-654321-1' - ), - values=dict( - GOOGLE_ANALYTICS_ACCOUNT='UA-654321-1' ) ) pixel = GoogleAnalyticsTrackingPixel(site=site_config.site) diff --git a/openedx/core/djangoapps/catalog/views.py b/openedx/core/djangoapps/catalog/views.py index 41874667c1ee..a6c1ba370498 100644 --- a/openedx/core/djangoapps/catalog/views.py +++ b/openedx/core/djangoapps/catalog/views.py @@ -27,8 +27,7 @@ def cache_programs(request): SiteConfiguration.objects.create( site=request.site, enabled=True, - site_values={"COURSE_CATALOG_API_URL": "{catalog_url}/api/v1/".format(catalog_url=CATALOG_STUB_URL)}, - values={"COURSE_CATALOG_API_URL": "{catalog_url}/api/v1/".format(catalog_url=CATALOG_STUB_URL)} + site_values={"COURSE_CATALOG_API_URL": "{catalog_url}/api/v1/".format(catalog_url=CATALOG_STUB_URL)} ) if settings.FEATURES.get('EXPOSE_CACHE_PROGRAMS_ENDPOINT'): diff --git a/openedx/core/djangoapps/config_model_utils/models.py b/openedx/core/djangoapps/config_model_utils/models.py index abf6b5a038d7..5a46541a939e 100644 --- a/openedx/core/djangoapps/config_model_utils/models.py +++ b/openedx/core/djangoapps/config_model_utils/models.py @@ -244,7 +244,7 @@ def all_current_course_configs(cls): """ all_courses = CourseOverview.objects.all() all_site_configs = SiteConfiguration.objects.filter( - values__contains='course_org_filter', enabled=True + site_values__contains='course_org_filter', enabled=True ).select_related('site') try: @@ -254,7 +254,7 @@ def all_current_course_configs(cls): sites_by_org = defaultdict(lambda: default_site) site_cfg_org_filters = ( - (site_cfg.site, site_cfg.values['course_org_filter']) + (site_cfg.site, site_cfg.site_values['course_org_filter']) for site_cfg in all_site_configs ) sites_by_org.update({ diff --git a/openedx/core/djangoapps/credentials/management/commands/tests/test_notify_credentials.py b/openedx/core/djangoapps/credentials/management/commands/tests/test_notify_credentials.py index 98c2d5e4d01a..daaeaa3dee89 100644 --- a/openedx/core/djangoapps/credentials/management/commands/tests/test_notify_credentials.py +++ b/openedx/core/djangoapps/credentials/management/commands/tests/test_notify_credentials.py @@ -127,8 +127,7 @@ def test_page_size(self): @mock.patch(COMMAND_MODULE + '.handle_cert_change') def test_site(self, mock_grade_interesting, mock_cert_change): site_config = SiteConfigurationFactory.create( - site_values={'course_org_filter': ['testX']}, - values={'course_org_filter': ['testX']}, + site_values={'course_org_filter': ['testX']} ) call_command(Command(), '--site', site_config.site.domain, '--start-date', '2017-01-01') diff --git a/openedx/core/djangoapps/credentials/tests/test_signals.py b/openedx/core/djangoapps/credentials/tests/test_signals.py index ef2a8196d525..311be58cc06d 100644 --- a/openedx/core/djangoapps/credentials/tests/test_signals.py +++ b/openedx/core/djangoapps/credentials/tests/test_signals.py @@ -110,8 +110,7 @@ def test_send_grade_without_issuance_enabled(self, _mock_is_course_run_in_a_prog def test_send_grade_records_enabled(self, _mock_is_course_run_in_a_program, mock_send_grade_to_credentials, _mock_is_learner_issuance_enabled): site_config = SiteConfigurationFactory.create( - site_values={'course_org_filter': [self.key.org]}, - values={'course_org_filter': [self.key.org]}, + site_values={'course_org_filter': [self.key.org]} ) # Correctly sent @@ -120,7 +119,7 @@ def test_send_grade_records_enabled(self, _mock_is_course_run_in_a_program, mock mock_send_grade_to_credentials.delay.reset_mock() # Correctly not sent - site_config.values['ENABLE_LEARNER_RECORDS'] = False + site_config.site_values['ENABLE_LEARNER_RECORDS'] = False site_config.save() send_grade_if_interesting(self.user, self.key, 'verified', 'downloadable', None, None) self.assertFalse(mock_send_grade_to_credentials.delay.called) diff --git a/openedx/core/djangoapps/programs/tasks/v1/tests/test_tasks.py b/openedx/core/djangoapps/programs/tasks/v1/tests/test_tasks.py index 96d6a3ecb96d..290ae6abbab9 100644 --- a/openedx/core/djangoapps/programs/tasks/v1/tests/test_tasks.py +++ b/openedx/core/djangoapps/programs/tasks/v1/tests/test_tasks.py @@ -196,7 +196,7 @@ def test_awarding_certs_with_skip_program_certificate( mock_get_certified_programs.return_value = [1] # programs to be skipped - self.site_configuration.values = { + self.site_configuration.site_values = { "programs_without_certificates": [2] } self.site_configuration.save() diff --git a/openedx/core/djangoapps/programs/tests/test_signals.py b/openedx/core/djangoapps/programs/tests/test_signals.py index 82c5299cb7b5..364dc089f632 100644 --- a/openedx/core/djangoapps/programs/tests/test_signals.py +++ b/openedx/core/djangoapps/programs/tests/test_signals.py @@ -146,8 +146,7 @@ def test_records_enabled(self, mock_is_learner_issuance_enabled, mock_task): mock_is_learner_issuance_enabled.return_value = True site_config = SiteConfigurationFactory.create( - site_values={'course_org_filter': ['edX']}, - values={'course_org_filter': ['edX']}, + site_values={'course_org_filter': ['edX']} ) # Correctly sent @@ -156,7 +155,7 @@ def test_records_enabled(self, mock_is_learner_issuance_enabled, mock_task): mock_task.reset_mock() # Correctly not sent - site_config.values['ENABLE_LEARNER_RECORDS'] = False + site_config.site_values['ENABLE_LEARNER_RECORDS'] = False site_config.save() handle_course_cert_changed(**self.signal_kwargs) self.assertFalse(mock_task.called) diff --git a/openedx/core/djangoapps/schedules/management/commands/tests/send_email_base.py b/openedx/core/djangoapps/schedules/management/commands/tests/send_email_base.py index 1296b87e20f4..50ae533c241f 100644 --- a/openedx/core/djangoapps/schedules/management/commands/tests/send_email_base.py +++ b/openedx/core/djangoapps/schedules/management/commands/tests/send_email_base.py @@ -307,12 +307,10 @@ def test_site_config(self, this_org_list, other_org_list, expected_message_count filtered_org = 'filtered_org' unfiltered_org = 'unfiltered_org' this_config = SiteConfigurationFactory.create( - site_values={'course_org_filter': this_org_list}, - values={'course_org_filter': this_org_list} + site_values={'course_org_filter': this_org_list} ) other_config = SiteConfigurationFactory.create( - site_values={'course_org_filter': other_org_list}, - values={'course_org_filter': other_org_list} + site_values={'course_org_filter': other_org_list} ) for config in (this_config, other_config): diff --git a/openedx/core/djangoapps/schedules/tests/test_resolvers.py b/openedx/core/djangoapps/schedules/tests/test_resolvers.py index 83c801b9b154..01f6f90f3942 100644 --- a/openedx/core/djangoapps/schedules/tests/test_resolvers.py +++ b/openedx/core/djangoapps/schedules/tests/test_resolvers.py @@ -61,7 +61,7 @@ def setUp(self): 'course1' ) def test_get_course_org_filter_equal(self, course_org_filter): - self.site_config.values['course_org_filter'] = course_org_filter + self.site_config.site_values['course_org_filter'] = course_org_filter self.site_config.save() mock_query = Mock() result = self.resolver.filter_by_org(mock_query) @@ -73,7 +73,7 @@ def test_get_course_org_filter_equal(self, course_org_filter): (['course1', 'course2'], ['course1', 'course2']) ) def test_get_course_org_filter_include__in(self, course_org_filter, expected_org_list): - self.site_config.values['course_org_filter'] = course_org_filter + self.site_config.site_values['course_org_filter'] = course_org_filter self.site_config.save() mock_query = Mock() result = self.resolver.filter_by_org(mock_query) @@ -88,8 +88,7 @@ def test_get_course_org_filter_include__in(self, course_org_filter, expected_org ) def test_get_course_org_filter_exclude__in(self, course_org_filter, expected_org_list): SiteConfigurationFactory.create( - site_values={'course_org_filter': course_org_filter}, - values={'course_org_filter': course_org_filter}, + site_values={'course_org_filter': course_org_filter} ) mock_query = Mock() result = self.resolver.filter_by_org(mock_query) diff --git a/openedx/core/djangoapps/site_configuration/admin.py b/openedx/core/djangoapps/site_configuration/admin.py index 6fda05f472f7..d8b52647b625 100644 --- a/openedx/core/djangoapps/site_configuration/admin.py +++ b/openedx/core/djangoapps/site_configuration/admin.py @@ -12,8 +12,8 @@ class SiteConfigurationAdmin(admin.ModelAdmin): """ Admin interface for the SiteConfiguration object. """ - list_display = ('site', 'enabled', 'values') - search_fields = ('site__domain', 'values') + list_display = ('site', 'enabled', 'site_values') + search_fields = ('site__domain', 'site_values') class Meta(object): """ @@ -29,7 +29,7 @@ class SiteConfigurationHistoryAdmin(admin.ModelAdmin): Admin interface for the SiteConfigurationHistory object. """ list_display = ('site', 'enabled', 'created', 'modified') - search_fields = ('site__domain', 'values', 'created', 'modified') + search_fields = ('site__domain', 'site_values', 'created', 'modified') ordering = ['-created'] diff --git a/openedx/core/djangoapps/site_configuration/helpers.py b/openedx/core/djangoapps/site_configuration/helpers.py index 07cb3ae9a9bb..45663497f3a9 100644 --- a/openedx/core/djangoapps/site_configuration/helpers.py +++ b/openedx/core/djangoapps/site_configuration/helpers.py @@ -53,7 +53,7 @@ def has_configuration_override(name): (bool): True if given key is present in the configuration. """ configuration = get_current_site_configuration() - if configuration and name in configuration.values: + if configuration and name in configuration.site_values: return True return False diff --git a/openedx/core/djangoapps/site_configuration/management/commands/create_site_configuration.py b/openedx/core/djangoapps/site_configuration/management/commands/create_site_configuration.py index 82ecf83cf157..1297b6d19360 100644 --- a/openedx/core/djangoapps/site_configuration/management/commands/create_site_configuration.py +++ b/openedx/core/djangoapps/site_configuration/management/commands/create_site_configuration.py @@ -50,6 +50,5 @@ def handle(self, *args, **options): SiteConfiguration.objects.create( site=site, site_values=configuration, - values=configuration, enabled=True ) diff --git a/openedx/core/djangoapps/site_configuration/management/commands/tests/test_create_site_configuration.py b/openedx/core/djangoapps/site_configuration/management/commands/tests/test_create_site_configuration.py index 95f3ce612ee7..77ccaf44aefb 100644 --- a/openedx/core/djangoapps/site_configuration/management/commands/tests/test_create_site_configuration.py +++ b/openedx/core/djangoapps/site_configuration/management/commands/tests/test_create_site_configuration.py @@ -21,7 +21,7 @@ def setUp(self): def _validate_site_configuration(self, site): site_configuration = SiteConfiguration.objects.get(site_id=site.id) - self.assertDictEqual(site_configuration.values, self.input_configuration) + self.assertDictEqual(site_configuration.site_values, self.input_configuration) def test_create_site_and_config(self): call_command( diff --git a/openedx/core/djangoapps/site_configuration/migrations/0004_copy_values_to_site_values.py b/openedx/core/djangoapps/site_configuration/migrations/0004_copy_values_to_site_values.py new file mode 100644 index 000000000000..d2c7254b19b6 --- /dev/null +++ b/openedx/core/djangoapps/site_configuration/migrations/0004_copy_values_to_site_values.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.27 on 2020-01-03 20:57 +from __future__ import unicode_literals + +from django.db import migrations + + +def copy_column_values(apps, schema_editor): + """ + Copy the values field into the site_values field. + """ + SiteConfiguration = apps.get_model('site_configuration', 'SiteConfiguration') + for site_configuration in SiteConfiguration.objects.all(): + site_configuration.site_values = site_configuration.values + site_configuration.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('site_configuration', '0003_add_site_values_field'), + ] + + operations = [ + migrations.RunPython( + copy_column_values, + reverse_code=migrations.RunPython.noop, # Allow reverse migrations, but make it a no-op. + ), + ] diff --git a/openedx/core/djangoapps/site_configuration/models.py b/openedx/core/djangoapps/site_configuration/models.py index 42869389835b..cee583340778 100644 --- a/openedx/core/djangoapps/site_configuration/models.py +++ b/openedx/core/djangoapps/site_configuration/models.py @@ -36,13 +36,6 @@ class SiteConfiguration(models.Model): blank=True, load_kwargs={'object_pairs_hook': collections.OrderedDict} ) - # TODO: Delete this deprecated field during the later stages of the rollout - # which renames 'values' to 'site_values'. - values = JSONField( - null=False, - blank=True, - load_kwargs={'object_pairs_hook': collections.OrderedDict} - ) def __str__(self): return u"".format(site=self.site) # xss-lint: disable=python-wrap-html @@ -65,7 +58,7 @@ def get_value(self, name, default=None): """ if self.enabled: try: - return self.values.get(name, default) + return self.site_values.get(name, default) except AttributeError as error: logger.exception(u'Invalid JSON data. \n [%s]', error) else: @@ -83,7 +76,7 @@ def get_configuration_for_org(cls, org, select_related=None): org (str): Org to use to filter SiteConfigurations select_related (list or None): A list of values to pass as arguments to select_related """ - query = cls.objects.filter(values__contains=org, enabled=True).all() + query = cls.objects.filter(site_values__contains=org, enabled=True).all() if select_related is not None: query = query.select_related(*select_related) for configuration in query: @@ -127,7 +120,7 @@ def get_all_orgs(cls): """ org_filter_set = set() - for configuration in cls.objects.filter(values__contains='course_org_filter', enabled=True).all(): + for configuration in cls.objects.filter(site_values__contains='course_org_filter', enabled=True).all(): course_org_filter = configuration.get_value('course_org_filter', []) if not isinstance(course_org_filter, list): course_org_filter = [course_org_filter] @@ -164,13 +157,6 @@ class SiteConfigurationHistory(TimeStampedModel): blank=True, load_kwargs={'object_pairs_hook': collections.OrderedDict} ) - # TODO: Delete this deprecated field during the later stages of the rollout - # which renames 'values' to 'site_values'. - values = JSONField( - null=False, - blank=True, - load_kwargs={'object_pairs_hook': collections.OrderedDict} - ) class Meta: get_latest_by = 'modified' @@ -199,7 +185,6 @@ def update_site_configuration_history(sender, instance, **kwargs): # pylint: di """ SiteConfigurationHistory.objects.create( site=instance.site, - site_values=instance.values, - values=instance.values, + site_values=instance.site_values, enabled=instance.enabled, ) diff --git a/openedx/core/djangoapps/site_configuration/tests/factories.py b/openedx/core/djangoapps/site_configuration/tests/factories.py index 4943ca3670c4..db1bb7377f4e 100644 --- a/openedx/core/djangoapps/site_configuration/tests/factories.py +++ b/openedx/core/djangoapps/site_configuration/tests/factories.py @@ -33,5 +33,5 @@ class Meta(object): site = SubFactory(SiteFactory) @lazy_attribute - def values(self): + def site_values(self): return {} diff --git a/openedx/core/djangoapps/site_configuration/tests/mixins.py b/openedx/core/djangoapps/site_configuration/tests/mixins.py index 95294d289192..f08aca35415f 100644 --- a/openedx/core/djangoapps/site_configuration/tests/mixins.py +++ b/openedx/core/djangoapps/site_configuration/tests/mixins.py @@ -22,9 +22,7 @@ def setUp(self): } self.site_configuration = SiteConfigurationFactory.create( site=self.site, - site_values=site_config, - # TODO: Remove this deprecated value eventually. - values=site_config + site_values=site_config ) self.site_other = SiteFactory.create( @@ -44,9 +42,7 @@ def setUp(self): } self.site_configuration_other = SiteConfigurationFactory.create( site=self.site_other, - site_values=site_config_other, - # TODO: Remove this deprecated value eventually. - values=site_config_other + site_values=site_config_other ) # Initialize client with default site domain @@ -62,9 +58,7 @@ def set_up_site(self, domain, site_configuration_values): ) __ = SiteConfigurationFactory.create( site=site, - site_values=site_configuration_values, - # TODO: Remove this deprecated value eventually. - values=site_configuration_values + site_values=site_configuration_values ) self.use_site(site) return site diff --git a/openedx/core/djangoapps/site_configuration/tests/test_middleware.py b/openedx/core/djangoapps/site_configuration/tests/test_middleware.py index c66ec84114d8..e94be3f1f98f 100644 --- a/openedx/core/djangoapps/site_configuration/tests/test_middleware.py +++ b/openedx/core/djangoapps/site_configuration/tests/test_middleware.py @@ -43,9 +43,6 @@ def setUp(self): site=self.site, site_values={ "SESSION_COOKIE_DOMAIN": self.site.domain, - }, - values={ - "SESSION_COOKIE_DOMAIN": self.site.domain, } ) @@ -81,9 +78,6 @@ def setUp(self): site=self.site, site_values={ "SESSION_COOKIE_DOMAIN": self.site.domain, - }, - values={ - "SESSION_COOKIE_DOMAIN": self.site.domain, } ) self.client = Client() diff --git a/openedx/core/djangoapps/site_configuration/tests/test_models.py b/openedx/core/djangoapps/site_configuration/tests/test_models.py index 4b69d57f5870..8403a6f04289 100644 --- a/openedx/core/djangoapps/site_configuration/tests/test_models.py +++ b/openedx/core/djangoapps/site_configuration/tests/test_models.py @@ -83,8 +83,6 @@ def test_site_configuration_post_update_receiver(self): ) site_configuration.site_values = {'test': 'test'} - # TODO: Remove this deprecated value eventually. - site_configuration.values = {'test': 'test'} site_configuration.save() # Verify an entry to SiteConfigurationHistory was added. @@ -133,9 +131,7 @@ def test_get_value(self): # add SiteConfiguration to database site_configuration = SiteConfigurationFactory.create( site=self.site, - site_values=self.test_config1, - # TODO: Remove this deprecated value eventually. - values=self.test_config1, + site_values=self.test_config1 ) # Make sure entry is saved and retrieved correctly @@ -183,9 +179,7 @@ def test_invalid_data_error_on_get_value(self): # add SiteConfiguration to database site_configuration = SiteConfigurationFactory.create( site=self.site, - site_values=invalid_data, - # TODO: Remove this deprecated value eventually. - values=invalid_data, + site_values=invalid_data ) # make sure get_value logs an error for invalid json data @@ -206,15 +200,11 @@ def test_get_value_for_org(self): # add SiteConfiguration to database SiteConfigurationFactory.create( site=self.site, - site_values=self.test_config1, - # TODO: Remove this deprecated value eventually. - values=self.test_config1, + site_values=self.test_config1 ) SiteConfigurationFactory.create( site=self.site2, - site_values=self.test_config2, - # TODO: Remove this deprecated value eventually. - values=self.test_config2, + site_values=self.test_config2 ) # Make sure entry is saved and retrieved correctly @@ -295,15 +285,11 @@ def test_get_site_for_org(self): # add SiteConfiguration to database config1 = SiteConfigurationFactory.create( site=self.site, - site_values=self.test_config1, - # TODO: Remove this deprecated value eventually. - values=self.test_config1, + site_values=self.test_config1 ) config2 = SiteConfigurationFactory.create( site=self.site2, - site_values=self.test_config2, - # TODO: Remove this deprecated value eventually. - values=self.test_config2, + site_values=self.test_config2 ) # Make sure entry is saved and retrieved correctly @@ -328,15 +314,11 @@ def test_get_all_orgs(self): # add SiteConfiguration to database SiteConfigurationFactory.create( site=self.site, - site_values=self.test_config1, - # TODO: Remove this deprecated value eventually. - values=self.test_config1, + site_values=self.test_config1 ) SiteConfigurationFactory.create( site=self.site2, - site_values=self.test_config2, - # TODO: Remove this deprecated value eventually. - values=self.test_config2, + site_values=self.test_config2 ) # Test that the default value is returned if the value for the given key is not found in the configuration @@ -351,15 +333,11 @@ def test_get_all_orgs_returns_only_enabled(self): SiteConfigurationFactory.create( site=self.site, site_values=self.test_config1, - # TODO: Remove this deprecated value eventually. - values=self.test_config1, enabled=False, ) SiteConfigurationFactory.create( site=self.site2, - site_values=self.test_config2, - # TODO: Remove this deprecated value eventually. - values=self.test_config2, + site_values=self.test_config2 ) # Test that the default value is returned if the value for the given key is not found in the configuration diff --git a/openedx/core/djangoapps/site_configuration/tests/test_util.py b/openedx/core/djangoapps/site_configuration/tests/test_util.py index 6c13a5fadc14..6bfb5b760e79 100644 --- a/openedx/core/djangoapps/site_configuration/tests/test_util.py +++ b/openedx/core/djangoapps/site_configuration/tests/test_util.py @@ -29,11 +29,10 @@ def _decorated(*args, **kwargs): # pylint: disable=missing-docstring site, __ = Site.objects.get_or_create(domain=domain, name=domain) site_configuration, created = SiteConfiguration.objects.get_or_create( site=site, - defaults={"enabled": True, "site_values": configuration, "values": configuration}, + defaults={"enabled": True, "site_values": configuration}, ) if not created: site_configuration.site_values = configuration - site_configuration.values = configuration site_configuration.save() with patch('openedx.core.djangoapps.site_configuration.helpers.get_current_site_configuration', @@ -57,11 +56,10 @@ def with_site_configuration_context(domain="test.localhost", configuration=None) site, __ = Site.objects.get_or_create(domain=domain, name=domain) site_configuration, created = SiteConfiguration.objects.get_or_create( site=site, - defaults={"enabled": True, "site_values": configuration, "values": configuration}, + defaults={"enabled": True, "site_values": configuration}, ) if not created: site_configuration.site_values = configuration - site_configuration.values = configuration site_configuration.save() with patch('openedx.core.djangoapps.site_configuration.helpers.get_current_site_configuration', diff --git a/openedx/core/djangoapps/theming/management/commands/create_sites_and_configurations.py b/openedx/core/djangoapps/theming/management/commands/create_sites_and_configurations.py index 255188c719ea..4aa7f4c17792 100644 --- a/openedx/core/djangoapps/theming/management/commands/create_sites_and_configurations.py +++ b/openedx/core/djangoapps/theming/management/commands/create_sites_and_configurations.py @@ -112,7 +112,6 @@ def _create_sites(self, site_domain, theme_dir_name, site_configuration): SiteConfiguration.objects.create( site=site, site_values=site_configuration, - values=site_configuration, enabled=True ) else: diff --git a/openedx/core/djangoapps/user_api/management/tests/test_sync_hubspot_contacts.py b/openedx/core/djangoapps/user_api/management/tests/test_sync_hubspot_contacts.py index d61bd05f484a..2a966f48c94a 100644 --- a/openedx/core/djangoapps/user_api/management/tests/test_sync_hubspot_contacts.py +++ b/openedx/core/djangoapps/user_api/management/tests/test_sync_hubspot_contacts.py @@ -31,8 +31,7 @@ def setUpClass(cls): super(TestHubspotSyncCommand, cls).setUpClass() cls.site_config = SiteConfigurationFactory() cls.hubspot_site_config = SiteConfigurationFactory.create( - site_values={'HUBSPOT_API_KEY': 'test_key'}, - values={'HUBSPOT_API_KEY': 'test_key'}, + site_values={'HUBSPOT_API_KEY': 'test_key'} ) cls.users = [] cls._create_users(cls.hubspot_site_config) # users for a site with hubspot integration enabled @@ -64,8 +63,8 @@ def test_without_any_hubspot_api_key(self): """ Test no _sync_site call is made if hubspot integration is not enabled for any site """ - orig_values = self.hubspot_site_config.values - self.hubspot_site_config.values = {} + orig_values = self.hubspot_site_config.site_values + self.hubspot_site_config.site_values = {} self.hubspot_site_config.save() sync_site = patch.object(sync_command, '_sync_site') mock_sync_site = sync_site.start() @@ -73,7 +72,7 @@ def test_without_any_hubspot_api_key(self): self.assertFalse(mock_sync_site.called, "_sync_site should not be called") sync_site.stop() # put values back - self.hubspot_site_config.values = orig_values + self.hubspot_site_config.site_values = orig_values self.hubspot_site_config.save() def test_with_initial_sync_days(self): diff --git a/openedx/features/content_type_gating/tests/test_models.py b/openedx/features/content_type_gating/tests/test_models.py index c6cf276bdcfb..89c66668d0b1 100644 --- a/openedx/features/content_type_gating/tests/test_models.py +++ b/openedx/features/content_type_gating/tests/test_models.py @@ -132,12 +132,10 @@ def test_config_overrides(self, global_setting, site_setting, org_setting, cours non_test_course_enabled = CourseOverviewFactory.create(org='non-test-org-enabled') non_test_course_disabled = CourseOverviewFactory.create(org='non-test-org-disabled') non_test_site_cfg_enabled = SiteConfigurationFactory.create( - site_values={'course_org_filter': non_test_course_enabled.org}, - values={'course_org_filter': non_test_course_enabled.org} + site_values={'course_org_filter': non_test_course_enabled.org} ) non_test_site_cfg_disabled = SiteConfigurationFactory.create( - site_values={'course_org_filter': non_test_course_disabled.org}, - values={'course_org_filter': non_test_course_disabled.org} + site_values={'course_org_filter': non_test_course_disabled.org} ) ContentTypeGatingConfig.objects.create(course=non_test_course_enabled, enabled=True, enabled_as_of=datetime(2018, 1, 1)) @@ -150,8 +148,7 @@ def test_config_overrides(self, global_setting, site_setting, org_setting, cours # Set up test objects test_course = CourseOverviewFactory.create(org='test-org') test_site_cfg = SiteConfigurationFactory.create( - site_values={'course_org_filter': test_course.org}, - values={'course_org_filter': test_course.org} + site_values={'course_org_filter': test_course.org} ) ContentTypeGatingConfig.objects.create(enabled=global_setting, enabled_as_of=datetime(2018, 1, 1)) @@ -176,14 +173,13 @@ def test_all_current_course_configs(self): ContentTypeGatingConfig.objects.create(enabled=global_setting, enabled_as_of=datetime(2018, 1, 1)) for site_setting in (True, False, None): test_site_cfg = SiteConfigurationFactory.create( - site_values={'course_org_filter': []}, - values={'course_org_filter': []} + site_values={'course_org_filter': []} ) ContentTypeGatingConfig.objects.create(site=test_site_cfg.site, enabled=site_setting, enabled_as_of=datetime(2018, 1, 1)) for org_setting in (True, False, None): test_org = "{}-{}".format(test_site_cfg.id, org_setting) - test_site_cfg.values['course_org_filter'].append(test_org) + test_site_cfg.site_values['course_org_filter'].append(test_org) test_site_cfg.save() ContentTypeGatingConfig.objects.create(org=test_org, enabled=org_setting, enabled_as_of=datetime(2018, 1, 1)) @@ -292,8 +288,7 @@ def test_caching_site(self): def test_caching_org(self): course = CourseOverviewFactory.create(org='test-org') site_cfg = SiteConfigurationFactory.create( - site_values={'course_org_filter': course.org}, - values={'course_org_filter': course.org} + site_values={'course_org_filter': course.org} ) org_config = ContentTypeGatingConfig(org=course.org, enabled=True, enabled_as_of=datetime(2018, 1, 1)) org_config.save() @@ -340,8 +335,7 @@ def test_caching_org(self): def test_caching_course(self): course = CourseOverviewFactory.create(org='test-org') site_cfg = SiteConfigurationFactory.create( - site_values={'course_org_filter': course.org}, - values={'course_org_filter': course.org} + site_values={'course_org_filter': course.org} ) course_config = ContentTypeGatingConfig(course=course, enabled=True, enabled_as_of=datetime(2018, 1, 1)) course_config.save() diff --git a/openedx/features/course_duration_limits/tests/test_models.py b/openedx/features/course_duration_limits/tests/test_models.py index fe4865fd774c..16414054a367 100644 --- a/openedx/features/course_duration_limits/tests/test_models.py +++ b/openedx/features/course_duration_limits/tests/test_models.py @@ -142,12 +142,10 @@ def test_config_overrides(self, global_setting, site_setting, org_setting, cours non_test_course_enabled = CourseOverviewFactory.create(org='non-test-org-enabled') non_test_course_disabled = CourseOverviewFactory.create(org='non-test-org-disabled') non_test_site_cfg_enabled = SiteConfigurationFactory.create( - site_values={'course_org_filter': non_test_course_enabled.org}, - values={'course_org_filter': non_test_course_enabled.org} + site_values={'course_org_filter': non_test_course_enabled.org} ) non_test_site_cfg_disabled = SiteConfigurationFactory.create( - site_values={'course_org_filter': non_test_course_disabled.org}, - values={'course_org_filter': non_test_course_disabled.org} + site_values={'course_org_filter': non_test_course_disabled.org} ) CourseDurationLimitConfig.objects.create(course=non_test_course_enabled, enabled=True) @@ -160,8 +158,7 @@ def test_config_overrides(self, global_setting, site_setting, org_setting, cours # Set up test objects test_course = CourseOverviewFactory.create(org='test-org') test_site_cfg = SiteConfigurationFactory.create( - site_values={'course_org_filter': test_course.org}, - values={'course_org_filter': test_course.org} + site_values={'course_org_filter': test_course.org} ) if reverse_order: @@ -191,8 +188,7 @@ def test_all_current_course_configs(self): CourseDurationLimitConfig.objects.create(enabled=global_setting, enabled_as_of=datetime(2018, 1, 1)) for site_setting in (True, False, None): test_site_cfg = SiteConfigurationFactory.create( - site_values={'course_org_filter': []}, - values={'course_org_filter': []} + site_values={'course_org_filter': []} ) CourseDurationLimitConfig.objects.create( site=test_site_cfg.site, enabled=site_setting, enabled_as_of=datetime(2018, 1, 1) @@ -200,7 +196,7 @@ def test_all_current_course_configs(self): for org_setting in (True, False, None): test_org = "{}-{}".format(test_site_cfg.id, org_setting) - test_site_cfg.values['course_org_filter'].append(test_org) + test_site_cfg.site_values['course_org_filter'].append(test_org) test_site_cfg.save() CourseDurationLimitConfig.objects.create( @@ -310,8 +306,7 @@ def test_caching_site(self): def test_caching_org(self): course = CourseOverviewFactory.create(org='test-org') site_cfg = SiteConfigurationFactory.create( - site_values={'course_org_filter': course.org}, - values={'course_org_filter': course.org} + site_values={'course_org_filter': course.org} ) org_config = CourseDurationLimitConfig(org=course.org, enabled=True, enabled_as_of=datetime(2018, 1, 1)) org_config.save() @@ -358,8 +353,7 @@ def test_caching_org(self): def test_caching_course(self): course = CourseOverviewFactory.create(org='test-org') site_cfg = SiteConfigurationFactory.create( - site_values={'course_org_filter': course.org}, - values={'course_org_filter': course.org} + site_values={'course_org_filter': course.org} ) course_config = CourseDurationLimitConfig(course=course, enabled=True, enabled_as_of=datetime(2018, 1, 1)) course_config.save() diff --git a/openedx/features/discounts/tests/test_discount_restriction_models.py b/openedx/features/discounts/tests/test_discount_restriction_models.py index 1de2ca7c7202..1288d202e329 100644 --- a/openedx/features/discounts/tests/test_discount_restriction_models.py +++ b/openedx/features/discounts/tests/test_discount_restriction_models.py @@ -59,12 +59,10 @@ def test_config_overrides(self, global_setting, site_setting, org_setting, cours non_test_course_disabled = CourseOverviewFactory.create(org='non-test-org-disabled') non_test_course_enabled = CourseOverviewFactory.create(org='non-test-org-enabled') non_test_site_cfg_disabled = SiteConfigurationFactory.create( - site_values={'course_org_filter': non_test_course_disabled.org}, - values={'course_org_filter': non_test_course_disabled.org} + site_values={'course_org_filter': non_test_course_disabled.org} ) non_test_site_cfg_enabled = SiteConfigurationFactory.create( - site_values={'course_org_filter': non_test_course_enabled.org}, - values={'course_org_filter': non_test_course_enabled.org} + site_values={'course_org_filter': non_test_course_enabled.org} ) DiscountRestrictionConfig.objects.create(course=non_test_course_disabled, disabled=True) @@ -77,8 +75,7 @@ def test_config_overrides(self, global_setting, site_setting, org_setting, cours # Set up test objects test_course = CourseOverviewFactory.create(org='test-org') test_site_cfg = SiteConfigurationFactory.create( - site_values={'course_org_filter': test_course.org}, - values={'course_org_filter': test_course.org} + site_values={'course_org_filter': test_course.org} ) DiscountRestrictionConfig.objects.create(disabled=global_setting) From 25d21fb6fafc1d6dae9625e3190c11d3207cd99f Mon Sep 17 00:00:00 2001 From: Julia Eskew Date: Tue, 7 Jan 2020 16:30:06 -0500 Subject: [PATCH 3/3] Add migration to remove values from SiteConfiguration and unskip migration test. --- common/djangoapps/util/tests/test_db.py | 1 - .../migrations/0005_remove_values_field.py | 23 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 openedx/core/djangoapps/site_configuration/migrations/0005_remove_values_field.py diff --git a/common/djangoapps/util/tests/test_db.py b/common/djangoapps/util/tests/test_db.py index 0667a44a9350..578e3b98925d 100644 --- a/common/djangoapps/util/tests/test_db.py +++ b/common/djangoapps/util/tests/test_db.py @@ -221,7 +221,6 @@ class MigrationTests(TestCase): """ Tests for migrations. """ - @unittest.skip("Need to skip as part of a 3-release rollout to rename a field in the site_configuration app. This will be unskipped in DE-1826.") @override_settings(MIGRATION_MODULES={}) def test_migrations_are_in_sync(self): """ diff --git a/openedx/core/djangoapps/site_configuration/migrations/0005_remove_values_field.py b/openedx/core/djangoapps/site_configuration/migrations/0005_remove_values_field.py new file mode 100644 index 000000000000..400a1cdd4a4b --- /dev/null +++ b/openedx/core/djangoapps/site_configuration/migrations/0005_remove_values_field.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.27 on 2020-01-07 21:26 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('site_configuration', '0004_copy_values_to_site_values'), + ] + + operations = [ + migrations.RemoveField( + model_name='siteconfiguration', + name='values', + ), + migrations.RemoveField( + model_name='siteconfigurationhistory', + name='values', + ), + ]