1010
1111from common .djangoapps .student .tests .factories import UserFactory
1212from openedx .core .djangoapps .notifications .config .waffle import (
13- ENABLE_ACCOUNT_LEVEL_PREFERENCES , ENABLE_NOTIFICATIONS , ENABLE_EMAIL_NOTIFICATIONS
13+ ENABLE_NOTIFICATIONS , ENABLE_EMAIL_NOTIFICATIONS
1414)
1515from openedx .core .djangoapps .notifications .tasks import send_notifications
1616from openedx .core .djangoapps .notifications .email_notifications import EmailCadence
@@ -127,7 +127,6 @@ def test_notification_content(self, cadence_type, created_time, notification_cre
127127 assert mock_func .called is notification_created
128128
129129
130- @override_waffle_flag (ENABLE_ACCOUNT_LEVEL_PREFERENCES , True )
131130@ddt .ddt
132131class TestEmailDigestForUserWithAccountPreferences (ModuleStoreTestCase ):
133132 """
@@ -331,23 +330,22 @@ def test_email_send_for_digest_preference(self, mock_func):
331330 self .preference .save ()
332331 with override_waffle_flag (ENABLE_EMAIL_NOTIFICATIONS , True ):
333332 send_digest_email_to_user (self .user , EmailCadence .DAILY , start_date , end_date )
334- assert mock_func .called
333+ assert not mock_func .called
335334
336- @ddt .data (True , False )
337335 @patch ('edx_ace.ace.send' )
338- def test_email_send_for_email_preference_value (self , pref_value , mock_func ):
336+ def test_email_send_for_email_preference_value (self , mock_func ):
339337 """
340338 Tests email is sent iff preference value is True
341339 """
342340 start_date , end_date = get_start_end_date (EmailCadence .DAILY )
343341 config = self .preference .notification_preference_config
344342 types = config ['discussion' ]['notification_types' ]
345343 types ['new_discussion_post' ]['email_cadence' ] = EmailCadence .DAILY
346- types ['new_discussion_post' ]['email' ] = pref_value
344+ types ['new_discussion_post' ]['email' ] = True
347345 self .preference .save ()
348346 with override_waffle_flag (ENABLE_EMAIL_NOTIFICATIONS , True ):
349347 send_digest_email_to_user (self .user , EmailCadence .DAILY , start_date , end_date )
350- assert mock_func .called is pref_value
348+ assert not mock_func .called
351349
352350 @patch ('edx_ace.ace.send' )
353351 def test_email_not_send_if_different_digest_preference (self , mock_func ):
@@ -364,7 +362,6 @@ def test_email_not_send_if_different_digest_preference(self, mock_func):
364362 assert not mock_func .called
365363
366364
367- @override_waffle_flag (ENABLE_ACCOUNT_LEVEL_PREFERENCES , True )
368365@ddt .ddt
369366class TestAccountPreferences (ModuleStoreTestCase ):
370367 """
@@ -435,17 +432,21 @@ def setUp(self):
435432 super ().setUp ()
436433 self .user = UserFactory ()
437434 self .course = CourseFactory .create (display_name = 'test course' , run = "Testing_course" )
435+ self .preference , _ = NotificationPreference .objects .get_or_create (
436+ user = self .user ,
437+ type = 'new_discussion_post' ,
438+ app = 'discussion'
439+ )
438440
439441 @patch ('edx_ace.ace.send' )
440442 def test_email_sent_when_cadence_is_immediate (self , mock_func ):
441443 """
442444 Tests email is sent when cadence is immediate
443445 """
444- preference = CourseNotificationPreference .objects .create (user = self .user , course_id = self .course .id )
445- app_prefs = preference .notification_preference_config ['discussion' ]['notification_types' ]
446- app_prefs ['new_discussion_post' ]['email' ] = True
447- app_prefs ['new_discussion_post' ]['email_cadence' ] = EmailCadence .IMMEDIATELY
448- preference .save ()
446+
447+ self .preference .email = True
448+ self .preference .email_cadence = EmailCadence .IMMEDIATELY
449+ self .preference .save ()
449450 context = {
450451 'username' : 'User' ,
451452 'post_title' : 'title'
@@ -461,7 +462,9 @@ def test_email_not_sent_when_cadence_is_not_immediate(self, mock_func):
461462 """
462463 Tests email is not sent when cadence is not immediate
463464 """
464- CourseNotificationPreference .objects .create (user = self .user , course_id = self .course .id )
465+ self .preference .email = True
466+ self .preference .email_cadence = EmailCadence .DAILY
467+ self .preference .save ()
465468 context = {
466469 'replier_name' : 'User' ,
467470 'post_title' : 'title'
0 commit comments