Skip to content
Snippets Groups Projects
Commit 590286f3 authored by stvn's avatar stvn
Browse files

Add is_enabled helper for discussions plugins

parent f569664d
No related branches found
No related tags found
No related merge requests found
......@@ -67,3 +67,16 @@ class DiscussionsConfiguration(TimeStampedModel):
provider=self.provider_type,
enabled=self.enabled,
)
@classmethod
def is_enabled(cls, context_key) -> bool:
"""
Check if there is an active configuration for a given course key
Default to False, if no configuration exists
"""
try:
configuration = cls.objects.get(context_key=context_key)
except cls.DoesNotExist:
return False
return configuration.enabled
......@@ -82,3 +82,24 @@ class DiscussionsConfigurationModelTest(TestCase):
assert configuration.lti_configuration is None
assert configuration.plugin_configuration['url'] == 'http://localhost'
assert configuration.provider_type == 'cs_comments_service'
def test_is_enabled_nonexistent(self):
"""
Assert that discussions are disabled, when no configuration exists
"""
is_enabled = DiscussionsConfiguration.is_enabled(self.course_key_without_config)
assert not is_enabled
def test_is_enabled_default(self):
"""
Assert that discussions are enabled by default, when a configuration exists
"""
is_enabled = DiscussionsConfiguration.is_enabled(self.course_key_with_defaults)
assert is_enabled
def test_is_enabled_explicit(self):
"""
Assert that discussions can be explitly disabled
"""
is_enabled = DiscussionsConfiguration.is_enabled(self.course_key_with_values)
assert not is_enabled
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment