@@ -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 notifications " , email .subject )
102
- self .assertIn ("Test notification" , email .body )
101
+ self .assertIn ("1 new notification " , email .subject )
102
+ self .assertIn ("This is a test notification" , email .body )
103
103
104
104
# Verify notification was marked as sent
105
105
notification .refresh_from_db ()
@@ -129,21 +129,29 @@ def test_only_includes_unread_notifications(self):
129
129
130
130
# Create read and unread notifications
131
131
read_notification = Notification .objects .create (
132
- recipient = self .user1 , notification_type = "test_type" , subject = "Read notification" , channels = ["email" ]
132
+ recipient = self .user1 ,
133
+ notification_type = "test_type" ,
134
+ subject = "Read notification subject" ,
135
+ text = "Read notification text" ,
136
+ channels = ["email" ],
133
137
)
134
138
read_notification .mark_as_read ()
135
139
136
140
unread_notification = Notification .objects .create (
137
- recipient = self .user1 , notification_type = "test_type" , subject = "Unread notification" , channels = ["email" ]
141
+ recipient = self .user1 ,
142
+ notification_type = "test_type" ,
143
+ subject = "Unread notification subject" ,
144
+ text = "Unread notification text" ,
145
+ channels = ["email" ],
138
146
)
139
147
140
148
call_command ("send_digest_emails" , "--frequency" , "daily" )
141
149
142
150
# Should send one email with only unread notification
143
151
self .assertEqual (len (mail .outbox ), 1 )
144
152
email = mail .outbox [0 ]
145
- self .assertIn ("Unread notification" , email .body )
146
- self .assertNotIn ("Read notification" , email .body )
153
+ self .assertIn ("Unread notification text " , email .body )
154
+ self .assertNotIn ("Read notification text " , email .body )
147
155
148
156
# Only unread notification should be marked as sent
149
157
read_notification .refresh_from_db ()
@@ -164,16 +172,20 @@ def test_only_includes_unsent_notifications(self):
164
172
)
165
173
166
174
unsent_notification = Notification .objects .create (
167
- recipient = self .user1 , notification_type = "test_type" , subject = "Unsent notification" , channels = ["email" ]
175
+ recipient = self .user1 ,
176
+ notification_type = "test_type" ,
177
+ subject = "Unsent notification subject" ,
178
+ text = "Unsent notification text" ,
179
+ channels = ["email" ],
168
180
)
169
181
170
182
call_command ("send_digest_emails" , "--frequency" , "daily" )
171
183
172
184
# Should send one email with only unsent notification
173
185
self .assertEqual (len (mail .outbox ), 1 )
174
186
email = mail .outbox [0 ]
175
- self .assertIn ("Unsent notification" , email .body )
176
- self .assertNotIn ("Sent notification" , email .body )
187
+ self .assertIn ("Unsent notification text " , email .body )
188
+ self .assertNotIn ("Sent notification text " , email .body )
177
189
178
190
# Unsent notification should now be marked as sent
179
191
unsent_notification .refresh_from_db ()
@@ -184,24 +196,32 @@ def test_sends_all_unsent_notifications(self):
184
196
185
197
# Create notification older than time window (>1 day ago)
186
198
old_notification = Notification .objects .create (
187
- recipient = self .user1 , notification_type = "test_type" , subject = "Old notification" , channels = ["email" ]
199
+ recipient = self .user1 ,
200
+ notification_type = "test_type" ,
201
+ subject = "Old notification subject" ,
202
+ text = "Old notification text" ,
203
+ channels = ["email" ],
188
204
)
189
205
# Manually set old timestamp
190
206
old_time = timezone .now () - timedelta (days = 2 )
191
207
Notification .objects .filter (id = old_notification .id ).update (added = old_time )
192
208
193
209
# Create recent notification
194
210
recent_notification = Notification .objects .create (
195
- recipient = self .user1 , notification_type = "test_type" , subject = "Recent notification" , channels = ["email" ]
211
+ recipient = self .user1 ,
212
+ notification_type = "test_type" ,
213
+ subject = "Recent notification subject" ,
214
+ text = "Recent notification text" ,
215
+ channels = ["email" ],
196
216
)
197
217
198
218
call_command ("send_digest_emails" , "--frequency" , "daily" )
199
219
200
220
# Should send one email with both notifications (no time window filtering)
201
221
self .assertEqual (len (mail .outbox ), 1 )
202
222
email = mail .outbox [0 ]
203
- self .assertIn ("Recent notification" , email .body )
204
- self .assertIn ("Old notification" , email .body )
223
+ self .assertIn ("Recent notification text " , email .body )
224
+ self .assertIn ("Old notification text " , email .body )
205
225
self .assertIn ("2 new notifications" , email .subject )
206
226
207
227
# Both notifications should be marked as sent
@@ -218,10 +238,18 @@ def test_specific_frequency_filter(self):
218
238
219
239
# Create notifications for both
220
240
Notification .objects .create (
221
- recipient = self .user1 , notification_type = "test_type" , subject = "Daily user notification" , channels = ["email" ]
241
+ recipient = self .user1 ,
242
+ notification_type = "test_type" ,
243
+ subject = "Daily user notification subject" ,
244
+ text = "Daily user notification text" ,
245
+ channels = ["email" ],
222
246
)
223
247
Notification .objects .create (
224
- recipient = self .user2 , notification_type = "test_type" , subject = "Weekly user notification" , channels = ["email" ]
248
+ recipient = self .user2 ,
249
+ notification_type = "test_type" ,
250
+ subject = "Weekly user notification subject" ,
251
+ text = "Weekly user notification text" ,
252
+ channels = ["email" ],
225
253
)
226
254
227
255
call_command ("send_digest_emails" , "--frequency" , "daily" )
@@ -230,7 +258,7 @@ def test_specific_frequency_filter(self):
230
258
self .assertEqual (len (mail .outbox ), 1 )
231
259
email = mail .outbox [0 ]
232
260
self .assertEqual (email .to , [self .user1 .email ])
233
- self .assertIn ("Daily user notification" , email .body )
261
+ self .assertIn ("Daily user notification text " , email .body )
234
262
235
263
# Clear outbox and test weekly frequency
236
264
mail .outbox .clear ()
@@ -240,7 +268,7 @@ def test_specific_frequency_filter(self):
240
268
self .assertEqual (len (mail .outbox ), 1 )
241
269
email = mail .outbox [0 ]
242
270
self .assertEqual (email .to , [self .user2 .email ])
243
- self .assertIn ("Weekly user notification" , email .body )
271
+ self .assertIn ("Weekly user notification text " , email .body )
244
272
245
273
def test_multiple_notification_types_for_user (self ):
246
274
# Set up user with multiple notification types for daily frequency
@@ -249,10 +277,18 @@ def test_multiple_notification_types_for_user(self):
249
277
250
278
# Create notifications of both types
251
279
notification1 = Notification .objects .create (
252
- recipient = self .user1 , notification_type = "test_type" , subject = "Test type notification" , channels = ["email" ]
280
+ recipient = self .user1 ,
281
+ notification_type = "test_type" ,
282
+ subject = "Test type notification subject" ,
283
+ text = "Test type notification text" ,
284
+ channels = ["email" ],
253
285
)
254
286
notification2 = Notification .objects .create (
255
- recipient = self .user1 , notification_type = "other_type" , subject = "Other type notification" , channels = ["email" ]
287
+ recipient = self .user1 ,
288
+ notification_type = "other_type" ,
289
+ subject = "Other type notification subject" ,
290
+ text = "Other type notification text" ,
291
+ channels = ["email" ],
256
292
)
257
293
258
294
call_command ("send_digest_emails" , "--frequency" , "daily" )
@@ -262,8 +298,8 @@ def test_multiple_notification_types_for_user(self):
262
298
email = mail .outbox [0 ]
263
299
self .assertEqual (email .to , [self .user1 .email ])
264
300
self .assertIn ("2 new notifications" , email .subject )
265
- self .assertIn ("Test type notification" , email .body )
266
- self .assertIn ("Other type notification" , email .body )
301
+ self .assertIn ("Test type notification text " , email .body )
302
+ self .assertIn ("Other type notification text " , email .body )
267
303
268
304
# Both notifications should be marked as sent
269
305
notification1 .refresh_from_db ()
@@ -321,8 +357,8 @@ def test_users_with_default_frequencies_get_digest(self):
321
357
self .assertEqual (len (mail .outbox ), 1 )
322
358
email = mail .outbox [0 ]
323
359
self .assertEqual (email .to , [self .user1 .email ])
324
- self .assertIn ("Test notification" , email .body )
325
- self .assertNotIn ("Other notification" , email .body )
360
+ self .assertIn ("This is a test notification" , email .body )
361
+ self .assertNotIn ("This is another type of notification" , email .body )
326
362
327
363
# Verify only test notification was marked as sent
328
364
test_notification .refresh_from_db ()
@@ -338,10 +374,18 @@ def test_mixed_explicit_and_default_preferences(self):
338
374
339
375
# Create notifications
340
376
Notification .objects .create (
341
- recipient = self .user1 , notification_type = "test_type" , subject = "Test notification" , channels = ["email" ]
377
+ recipient = self .user1 ,
378
+ notification_type = "test_type" ,
379
+ subject = "Test notification subject" ,
380
+ text = "Test notification text" ,
381
+ channels = ["email" ],
342
382
)
343
383
Notification .objects .create (
344
- recipient = self .user1 , notification_type = "other_type" , subject = "Other notification" , channels = ["email" ]
384
+ recipient = self .user1 ,
385
+ notification_type = "other_type" ,
386
+ subject = "Other notification subject" ,
387
+ text = "Other notification text" ,
388
+ channels = ["email" ],
345
389
)
346
390
347
391
# Run daily digest - should get nothing (test_type is weekly, other_type is realtime)
@@ -352,8 +396,8 @@ def test_mixed_explicit_and_default_preferences(self):
352
396
call_command ("send_digest_emails" , "--frequency" , "weekly" )
353
397
self .assertEqual (len (mail .outbox ), 1 )
354
398
email = mail .outbox [0 ]
355
- self .assertIn ("Test notification" , email .body )
356
- self .assertNotIn ("Other notification" , email .body )
399
+ self .assertIn ("Test notification text " , email .body )
400
+ self .assertNotIn ("Other notification text " , email .body )
357
401
358
402
def test_multiple_users_default_and_explicit_mix (self ):
359
403
"""Test digest emails work correctly with multiple users having different preference configurations."""
@@ -369,7 +413,8 @@ def test_multiple_users_default_and_explicit_mix(self):
369
413
Notification .objects .create (
370
414
recipient = user ,
371
415
notification_type = "test_type" ,
372
- subject = f"Test notification for user { i } " ,
416
+ subject = f"Test notification for user { i } subject" ,
417
+ text = f"Test notification for user { i } text" ,
373
418
channels = ["email" ],
374
419
)
375
420
@@ -387,4 +432,4 @@ def test_multiple_users_default_and_explicit_mix(self):
387
432
call_command ("send_digest_emails" , "--frequency" , "weekly" )
388
433
self .assertEqual (len (mail .outbox ), 1 )
389
434
self .assertEqual (mail .outbox [0 ].to [0 ], self .user2 .email )
390
- self .assertIn ("Test notification for user 2" , mail .outbox [0 ].body )
435
+ self .assertIn ("Test notification for user 2 text " , mail .outbox [0 ].body )
0 commit comments