diff --git a/lms/djangoapps/discussion/rest_api/tests/test_utils.py b/lms/djangoapps/discussion/rest_api/tests/test_utils.py index 401902d1fd77..655e78670208 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_utils.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_utils.py @@ -5,6 +5,7 @@ from datetime import datetime, timedelta from unittest.mock import Mock +import ddt from django.conf import settings from httpretty import httpretty from pytz import UTC @@ -310,6 +311,7 @@ def test_comment_creators_own_response(self): self.assertEqual(args_comment.app_name, 'discussion') +@ddt.ddt class TestBlackoutDates(ForumsEnableMixin, CommentsServiceMockMixin, ModuleStoreTestCase): """ Test for the is_posting_allowed function @@ -354,41 +356,21 @@ def _check_posting_allowed(self, posting_restriction): self.course.get_discussion_blackout_datetimes() ) - def test_posting_disabled(self): + @ddt.data( + (PostingRestriction.DISABLED, True), + (PostingRestriction.ENABLED, False), + (PostingRestriction.SCHEDULED, False), + ) + @ddt.unpack + def test_blackout_dates(self, restriction, state): """ - Test posting when the posting restriction is disabled. - Assertion: - Posting should be allowed. - """ - date_ranges = self._get_date_ranges() - self._set_discussion_blackouts(date_ranges) - - posting_allowed = self._check_posting_allowed(PostingRestriction.DISABLED) - self.assertTrue(posting_allowed) - - def test_posting_enabled(self): - """ - Test posting when the posting restriction is enabled. - Assertion: - Posting should not be allowed. + Test is_posting_allowed function with the misc posting restriction """ date_ranges = self._get_date_ranges() self._set_discussion_blackouts(date_ranges) - posting_allowed = self._check_posting_allowed(PostingRestriction.ENABLED) - self.assertFalse(posting_allowed) - - def test_posting_scheduled(self): - """ - Test posting when the posting restriction is scheduled. - Assertion: - Posting should not be allowed. - """ - date_ranges = self._get_date_ranges() - self._set_discussion_blackouts(date_ranges) - - posting_allowed = self._check_posting_allowed(PostingRestriction.SCHEDULED) - self.assertFalse(posting_allowed) + posting_allowed = self._check_posting_allowed(restriction) + self.assertEqual(state, posting_allowed) def test_posting_scheduled_future(self): """ diff --git a/lms/djangoapps/discussion/rest_api/utils.py b/lms/djangoapps/discussion/rest_api/utils.py index 6d8cc4438ccc..a774e579b45e 100644 --- a/lms/djangoapps/discussion/rest_api/utils.py +++ b/lms/djangoapps/discussion/rest_api/utils.py @@ -42,9 +42,12 @@ def discussion_open_for_user(course, user): course: Course to check discussions for user: User to check for privileges in course """ - discussions_config = DiscussionsConfiguration.get(course.id).posting_restrictions + discussions_posting_restrictions = DiscussionsConfiguration.get(course.id).posting_restrictions blackout_dates = course.get_discussion_blackout_datetimes() - return is_posting_allowed(discussions_config, blackout_dates) or has_discussion_privileges(user, course.id) + return ( + is_posting_allowed(discussions_posting_restrictions, blackout_dates) or + has_discussion_privileges(user, course.id) + ) def set_attribute(threads, attribute, value):