@@ -98,8 +98,8 @@ def test_send_digest_emails_basic_flow(self):
9898
9999 # Check email details
100100 self .assertEqual (email .to , [self .user1 .email ])
101- self .assertIn ( " 1 new notification", email . subject )
102- self .assertIn ( " This is a test notification", email . body )
101+ self .assertEqual ( email . subject , "Daily digest - 1 new notification" )
102+ self .assertEqual ( email . body , "You have 1 new notification: \n \n - This is a test notification" )
103103
104104 # Verify notification was marked as sent
105105 notification .refresh_from_db ()
@@ -150,8 +150,7 @@ def test_only_includes_unread_notifications(self):
150150 # Should send one email with only unread notification
151151 self .assertEqual (len (mail .outbox ), 1 )
152152 email = mail .outbox [0 ]
153- self .assertIn ("Unread notification text" , email .body )
154- self .assertNotIn ("Read notification text" , email .body )
153+ self .assertEqual (email .body , "You have 1 new notification:\n \n - Unread notification text" )
155154
156155 # Only unread notification should be marked as sent
157156 read_notification .refresh_from_db ()
@@ -184,8 +183,7 @@ def test_only_includes_unsent_notifications(self):
184183 # Should send one email with only unsent notification
185184 self .assertEqual (len (mail .outbox ), 1 )
186185 email = mail .outbox [0 ]
187- self .assertIn ("Unsent notification text" , email .body )
188- self .assertNotIn ("Sent notification text" , email .body )
186+ self .assertEqual (email .body , "You have 1 new notification:\n \n - Unsent notification text" )
189187
190188 # Unsent notification should now be marked as sent
191189 unsent_notification .refresh_from_db ()
@@ -220,9 +218,10 @@ def test_sends_all_unsent_notifications(self):
220218 # Should send one email with both notifications (no time window filtering)
221219 self .assertEqual (len (mail .outbox ), 1 )
222220 email = mail .outbox [0 ]
223- self .assertIn ("Recent notification text" , email .body )
224- self .assertIn ("Old notification text" , email .body )
225- self .assertIn ("2 new notifications" , email .subject )
221+ self .assertEqual (email .subject , "Daily digest - 2 new notifications" )
222+ self .assertEqual (
223+ email .body , "You have 2 new notifications:\n \n - Recent notification text\n - Old notification text"
224+ )
226225
227226 # Both notifications should be marked as sent
228227 old_notification .refresh_from_db ()
@@ -258,7 +257,7 @@ def test_specific_frequency_filter(self):
258257 self .assertEqual (len (mail .outbox ), 1 )
259258 email = mail .outbox [0 ]
260259 self .assertEqual (email .to , [self .user1 .email ])
261- self .assertIn ( " Daily user notification text", email . body )
260+ self .assertEqual ( email . body , "You have 1 new notification: \n \n - Daily user notification text" )
262261
263262 # Clear outbox and test weekly frequency
264263 mail .outbox .clear ()
@@ -268,7 +267,7 @@ def test_specific_frequency_filter(self):
268267 self .assertEqual (len (mail .outbox ), 1 )
269268 email = mail .outbox [0 ]
270269 self .assertEqual (email .to , [self .user2 .email ])
271- self .assertIn ( " Weekly user notification text", email . body )
270+ self .assertEqual ( email . body , "You have 1 new notification: \n \n - Weekly user notification text" )
272271
273272 def test_multiple_notification_types_for_user (self ):
274273 # Set up user with multiple notification types for daily frequency
@@ -297,9 +296,10 @@ def test_multiple_notification_types_for_user(self):
297296 self .assertEqual (len (mail .outbox ), 1 )
298297 email = mail .outbox [0 ]
299298 self .assertEqual (email .to , [self .user1 .email ])
300- self .assertIn ("2 new notifications" , email .subject )
301- self .assertIn ("Test type notification text" , email .body )
302- self .assertIn ("Other type notification text" , email .body )
299+ self .assertEqual (email .subject , "Daily digest - 2 new notifications" )
300+ self .assertEqual (
301+ email .body , "You have 2 new notifications:\n \n - Other type notification text\n - Test type notification text"
302+ )
303303
304304 # Both notifications should be marked as sent
305305 notification1 .refresh_from_db ()
@@ -357,8 +357,7 @@ def test_users_with_default_frequencies_get_digest(self):
357357 self .assertEqual (len (mail .outbox ), 1 )
358358 email = mail .outbox [0 ]
359359 self .assertEqual (email .to , [self .user1 .email ])
360- self .assertIn ("This is a test notification" , email .body )
361- self .assertNotIn ("This is another type of notification" , email .body )
360+ self .assertEqual (email .body , "You have 1 new notification:\n \n - This is a test notification" )
362361
363362 # Verify only test notification was marked as sent
364363 test_notification .refresh_from_db ()
@@ -396,8 +395,7 @@ def test_mixed_explicit_and_default_preferences(self):
396395 call_command ("send_digest_emails" , "--frequency" , "weekly" )
397396 self .assertEqual (len (mail .outbox ), 1 )
398397 email = mail .outbox [0 ]
399- self .assertIn ("Test notification text" , email .body )
400- self .assertNotIn ("Other notification text" , email .body )
398+ self .assertEqual (email .body , "You have 1 new notification:\n \n - Test notification text" )
401399
402400 def test_multiple_users_default_and_explicit_mix (self ):
403401 """Test digest emails work correctly with multiple users having different preference configurations."""
@@ -423,13 +421,11 @@ def test_multiple_users_default_and_explicit_mix(self):
423421 self .assertEqual (len (mail .outbox ), 2 )
424422
425423 recipients = {email .to [0 ] for email in mail .outbox }
426- self .assertIn (self .user1 .email , recipients )
427- self .assertIn (self .user3 .email , recipients )
428- self .assertNotIn (self .user2 .email , recipients )
424+ self .assertEqual (set (recipients ), {self .user1 .email , self .user3 .email })
429425
430426 # Clear outbox and run weekly digest - should get user2
431427 mail .outbox .clear ()
432428 call_command ("send_digest_emails" , "--frequency" , "weekly" )
433429 self .assertEqual (len (mail .outbox ), 1 )
434430 self .assertEqual (mail .outbox [0 ].to [0 ], self .user2 .email )
435- self .assertIn ( " Test notification for user 2 text", mail . outbox [ 0 ]. body )
431+ self .assertEqual ( mail . outbox [ 0 ]. body , "You have 1 new notification: \n \n - Test notification for user 2 text" )
0 commit comments