2828from lms .djangoapps .courseware .block_render import get_block_for_descriptor
2929from lms .djangoapps .courseware .tests .helpers import XModuleRenderingTestBase
3030from openedx .core .djangoapps .discussions .models import DiscussionsConfiguration , Provider
31+ from openedx .core .djangoapps .discussions .services import DiscussionConfigService
3132from common .djangoapps .student .tests .factories import CourseEnrollmentFactory , UserFactory
3233
3334
@@ -193,6 +194,14 @@ def test_student_perms_are_correct(self, permissions):
193194 'can_create_subcomment' : permission_dict ['create_sub_comment' ],
194195 }
195196
197+ self .add_patcher (
198+ patch .multiple (
199+ DiscussionConfigService ,
200+ is_discussion_visible = mock .Mock (return_value = True ),
201+ is_discussion_enabled = mock .Mock (return_value = True )
202+ )
203+ )
204+
196205 self .block .has_permission = lambda perm : permission_dict [perm ]
197206 with mock .patch ('xmodule.discussion_block.render_to_string' , return_value = '' ) as mock_render :
198207 self .block .student_view ()
@@ -223,13 +232,10 @@ def test_has_permission(self):
223232 Test for has_permission method.
224233 """
225234 permission_canary = object ()
226- with mock .patch (
227- 'xmodule.discussion_block.has_permission' ,
228- return_value = permission_canary ,
229- ) as has_perm :
230- actual_permission = self .block .has_permission ("test_permission" )
235+ self .block .has_permission = mock .Mock (return_value = permission_canary )
236+ actual_permission = self .block .has_permission ("test_permission" )
231237 assert actual_permission == permission_canary
232- has_perm . assert_called_once_with (self . django_user_canary , ' test_permission' , self . course_id )
238+ self . block . has_permission . assert_called_once_with (" test_permission" )
233239
234240 def test_studio_view (self ):
235241 """Test for studio view."""
@@ -252,6 +258,14 @@ def test_student_perms_are_correct(self, permissions):
252258 'create_sub_comment' : permissions [2 ]
253259 }
254260
261+ self .add_patcher (
262+ patch .multiple (
263+ DiscussionConfigService ,
264+ is_discussion_visible = mock .Mock (return_value = True ),
265+ is_discussion_enabled = mock .Mock (return_value = True )
266+ )
267+ )
268+
255269 self .block .has_permission = lambda perm : permission_dict [perm ]
256270 fragment = self .block .student_view ()
257271 read_only = 'false' if permissions [0 ] else 'true'
@@ -296,7 +310,7 @@ def get_root(self, block):
296310 block = block .get_parent ()
297311 return block
298312
299- @override_settings (FEATURES = dict ( settings . FEATURES , ENABLE_DISCUSSION_SERVICE = ' True' ) )
313+ @override_settings (ENABLE_DISCUSSION_SERVICE = True )
300314 def test_html_with_user (self ):
301315 """
302316 Test rendered DiscussionXBlock permissions.
@@ -317,7 +331,7 @@ def test_html_with_user(self):
317331 assert 'data-user-create-comment="false"' in html
318332 assert 'data-user-create-subcomment="false"' in html
319333
320- @override_settings (FEATURES = dict ( settings . FEATURES , ENABLE_DISCUSSION_SERVICE = ' True' ) )
334+ @override_settings (ENABLE_DISCUSSION_SERVICE = True )
321335 def test_discussion_render_successfully_with_orphan_parent (self ):
322336 """
323337 Test that discussion xblock render successfully
@@ -393,11 +407,11 @@ def test_discussion_xblock_visibility(self):
393407 """
394408 # Enable new OPEN_EDX provider for this course
395409 course_key = self .course .location .course_key
396- DiscussionsConfiguration .objects .create (
397- context_key = course_key ,
398- enabled = True ,
399- provider_type = Provider .OPEN_EDX ,
400- )
410+ # DiscussionsConfiguration.objects.create(
411+ # context_key=course_key,
412+ # enabled=True,
413+ # provider_type=Provider.OPEN_EDX,
414+ # )
401415
402416 discussion_xblock = get_block_for_descriptor (
403417 user = self .user ,
@@ -421,7 +435,7 @@ class TestXBlockQueryLoad(SharedModuleStoreTestCase):
421435 Test the number of queries executed when rendering the XBlock.
422436 """
423437
424- @override_settings (FEATURES = dict ( settings . FEATURES , ENABLE_DISCUSSION_SERVICE = ' True' ) )
438+ @override_settings (ENABLE_DISCUSSION_SERVICE = True )
425439 def test_permissions_query_load (self ):
426440 """
427441 Tests that the permissions queries are cached when rendering numerous discussion XBlocks.
0 commit comments