From c36c343c582b53e08d52a2aadfca5a7fe9ec1956 Mon Sep 17 00:00:00 2001 From: stvn Date: Tue, 2 Feb 2021 15:49:45 -0800 Subject: [PATCH] style: Fix pylint issues in discussions app --- openedx/core/djangoapps/discussions/admin.py | 4 ++++ openedx/core/djangoapps/discussions/models.py | 6 +++++- .../core/djangoapps/discussions/tests/test_models.py | 10 ++++++---- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/openedx/core/djangoapps/discussions/admin.py b/openedx/core/djangoapps/discussions/admin.py index 02414b2e36..33866b3f16 100644 --- a/openedx/core/djangoapps/discussions/admin.py +++ b/openedx/core/djangoapps/discussions/admin.py @@ -12,6 +12,10 @@ from .models import ProviderFilter class DiscussionsConfigurationAdmin(SimpleHistoryAdmin): + """ + Customize the admin interface for the discussions configuration + """ + search_fields = ( 'context_key', 'enabled', diff --git a/openedx/core/djangoapps/discussions/models.py b/openedx/core/djangoapps/discussions/models.py index ed1c6b7466..62a9422bd3 100644 --- a/openedx/core/djangoapps/discussions/models.py +++ b/openedx/core/djangoapps/discussions/models.py @@ -130,7 +130,9 @@ class DiscussionsConfiguration(TimeStampedModel): db_index=True, unique=True, max_length=255, - # Translators: A key specifying a course, library, program, website, or some other collection of content where learning happens. + # Translators: A key specifying a course, library, program, + # website, or some other collection of content where learning + # happens. verbose_name=_("Learning Context Key"), ) enabled = models.BooleanField( @@ -184,6 +186,7 @@ class DiscussionsConfiguration(TimeStampedModel): configuration = cls.get(context_key) return configuration.enabled + # pylint: disable=undefined-variable @classmethod def get(cls, context_key) -> cls: """ @@ -194,6 +197,7 @@ class DiscussionsConfiguration(TimeStampedModel): except cls.DoesNotExist: configuration = cls(context_key=context_key, enabled=False) return configuration + # pylint: enable=undefined-variable @property def available_providers(self) -> List[str]: diff --git a/openedx/core/djangoapps/discussions/tests/test_models.py b/openedx/core/djangoapps/discussions/tests/test_models.py index b3f5b479fa..f68a5fa9e5 100644 --- a/openedx/core/djangoapps/discussions/tests/test_models.py +++ b/openedx/core/djangoapps/discussions/tests/test_models.py @@ -124,6 +124,7 @@ class DiscussionsConfigurationModelTest(TestCase): """ Configure shared test data (configuration, course_key, etc.) """ + super().setUp() self.course_key_with_defaults = CourseKey.from_string("course-v1:TestX+Course+Configured") self.course_key_without_config = CourseKey.from_string("course-v1:TestX+Course+NoConfig") self.course_key_with_values = CourseKey.from_string("course-v1:TestX+Course+Values") @@ -140,14 +141,13 @@ class DiscussionsConfigurationModelTest(TestCase): }, ) self.configuration_with_values.save() - pass def test_get_nonexistent(self): """ Assert we can not fetch a non-existent record """ with self.assertRaises(DiscussionsConfiguration.DoesNotExist): - configuration = DiscussionsConfiguration.objects.get( + DiscussionsConfiguration.objects.get( context_key=self.course_key_without_config, ) @@ -170,7 +170,9 @@ class DiscussionsConfigurationModelTest(TestCase): assert configuration is not None assert not configuration.enabled assert configuration.lti_configuration is None - assert configuration.plugin_configuration['url'] == self.configuration_with_values.plugin_configuration['url'] + actual_url = configuration.plugin_configuration.get('url') + expected_url = self.configuration_with_values.plugin_configuration.get('url') + assert actual_url == expected_url assert configuration.provider_type == self.configuration_with_values.provider_type def test_update_defaults(self): @@ -212,7 +214,7 @@ class DiscussionsConfigurationModelTest(TestCase): is_enabled = DiscussionsConfiguration.is_enabled(self.course_key_with_values) assert not is_enabled - def test_get_nonexistent(self): + def test_get_nonexistent_empty(self): """ Assert we get an "empty" model back for nonexistent records """