@@ -98,8 +98,8 @@ def test_send_digest_emails_basic_flow(self):
98
98
99
99
# Check email details
100
100
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" )
103
103
104
104
# Verify notification was marked as sent
105
105
notification .refresh_from_db ()
@@ -150,8 +150,7 @@ def test_only_includes_unread_notifications(self):
150
150
# Should send one email with only unread notification
151
151
self .assertEqual (len (mail .outbox ), 1 )
152
152
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" )
155
154
156
155
# Only unread notification should be marked as sent
157
156
read_notification .refresh_from_db ()
@@ -184,8 +183,7 @@ def test_only_includes_unsent_notifications(self):
184
183
# Should send one email with only unsent notification
185
184
self .assertEqual (len (mail .outbox ), 1 )
186
185
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" )
189
187
190
188
# Unsent notification should now be marked as sent
191
189
unsent_notification .refresh_from_db ()
@@ -220,9 +218,10 @@ def test_sends_all_unsent_notifications(self):
220
218
# Should send one email with both notifications (no time window filtering)
221
219
self .assertEqual (len (mail .outbox ), 1 )
222
220
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
+ )
226
225
227
226
# Both notifications should be marked as sent
228
227
old_notification .refresh_from_db ()
@@ -258,7 +257,7 @@ def test_specific_frequency_filter(self):
258
257
self .assertEqual (len (mail .outbox ), 1 )
259
258
email = mail .outbox [0 ]
260
259
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" )
262
261
263
262
# Clear outbox and test weekly frequency
264
263
mail .outbox .clear ()
@@ -268,7 +267,7 @@ def test_specific_frequency_filter(self):
268
267
self .assertEqual (len (mail .outbox ), 1 )
269
268
email = mail .outbox [0 ]
270
269
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" )
272
271
273
272
def test_multiple_notification_types_for_user (self ):
274
273
# Set up user with multiple notification types for daily frequency
@@ -297,9 +296,10 @@ def test_multiple_notification_types_for_user(self):
297
296
self .assertEqual (len (mail .outbox ), 1 )
298
297
email = mail .outbox [0 ]
299
298
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
+ )
303
303
304
304
# Both notifications should be marked as sent
305
305
notification1 .refresh_from_db ()
@@ -357,8 +357,7 @@ def test_users_with_default_frequencies_get_digest(self):
357
357
self .assertEqual (len (mail .outbox ), 1 )
358
358
email = mail .outbox [0 ]
359
359
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" )
362
361
363
362
# Verify only test notification was marked as sent
364
363
test_notification .refresh_from_db ()
@@ -396,8 +395,7 @@ def test_mixed_explicit_and_default_preferences(self):
396
395
call_command ("send_digest_emails" , "--frequency" , "weekly" )
397
396
self .assertEqual (len (mail .outbox ), 1 )
398
397
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" )
401
399
402
400
def test_multiple_users_default_and_explicit_mix (self ):
403
401
"""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):
423
421
self .assertEqual (len (mail .outbox ), 2 )
424
422
425
423
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 })
429
425
430
426
# Clear outbox and run weekly digest - should get user2
431
427
mail .outbox .clear ()
432
428
call_command ("send_digest_emails" , "--frequency" , "weekly" )
433
429
self .assertEqual (len (mail .outbox ), 1 )
434
430
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