|
| 1 | +import logging |
1 | 2 | from typing import List |
2 | 3 | from typing import cast |
3 | 4 |
|
@@ -215,6 +216,15 @@ def test_create_duplicate_pre_registration_user( |
215 | 216 | with pytest.raises(PreRegistUserAlreadyExistException): |
216 | 217 | pre_registration_service.create_pre_registration_user(request) |
217 | 218 |
|
| 219 | + users = pre_registration_service.get_pre_registration_users( |
| 220 | + pre_registration_id=created_active_pre_registration.id, |
| 221 | + active_only=False, |
| 222 | + limit=50, |
| 223 | + offset=0, |
| 224 | + ) |
| 225 | + |
| 226 | + assert users == [] |
| 227 | + |
218 | 228 |
|
219 | 229 | def test_get_active_pre_registration_users( |
220 | 230 | db_session: Session, |
@@ -319,6 +329,7 @@ def test_send_email_to_active_pre_registration_users_queues_background_task( |
319 | 329 | assert response.total_count == 1 |
320 | 330 | assert response.queued_count == 1 |
321 | 331 | assert response.recipient_limit == PRE_REGISTRATION_EMAIL_BATCH_LIMIT |
| 332 | + assert response.is_truncated is False |
322 | 333 | assert fake_email_service.sent_emails == [] |
323 | 334 | assert len(background_tasks.tasks) == 1 |
324 | 335 |
|
@@ -361,12 +372,59 @@ def test_send_email_to_pre_registration_users_applies_recipient_cap( |
361 | 372 | ) |
362 | 373 |
|
363 | 374 | assert response.status == "queued" |
364 | | - assert response.total_count == PRE_REGISTRATION_EMAIL_BATCH_LIMIT |
| 375 | + assert response.total_count == user_count |
365 | 376 | assert response.queued_count == PRE_REGISTRATION_EMAIL_BATCH_LIMIT |
366 | 377 | assert response.recipient_limit == PRE_REGISTRATION_EMAIL_BATCH_LIMIT |
| 378 | + assert response.is_truncated is True |
367 | 379 | assert fake_email_service.sent_emails == [] |
368 | 380 |
|
369 | 381 | [background_task] = background_tasks.tasks |
370 | 382 | background_task.func(*background_task.args, **background_task.kwargs) |
371 | 383 |
|
372 | 384 | assert len(fake_email_service.sent_emails) == PRE_REGISTRATION_EMAIL_BATCH_LIMIT |
| 385 | + |
| 386 | + |
| 387 | +def test_send_email_to_recipients_logs_send_failure_and_continues( |
| 388 | + pre_registration_service: PreRegistrationService, |
| 389 | + fake_email_service: FakeEmailService, |
| 390 | + caplog: pytest.LogCaptureFixture, |
| 391 | +): |
| 392 | + fake_email_service.failed_emails.add("failed@example.com") |
| 393 | + |
| 394 | + with caplog.at_level( |
| 395 | + logging.ERROR, logger="wacruit.src.apps.pre_registration.services" |
| 396 | + ): |
| 397 | + pre_registration_service._send_email_to_recipients( |
| 398 | + recipient_emails=["failed@example.com", "success@example.com"], |
| 399 | + subject="subject", |
| 400 | + content="content", |
| 401 | + html_content=None, |
| 402 | + ) |
| 403 | + |
| 404 | + assert fake_email_service.sent_emails == [ |
| 405 | + ("success@example.com", "subject", "content", None) |
| 406 | + ] |
| 407 | + assert "Failed to send pre-registration email" in caplog.text |
| 408 | + assert "failed@example.com" in caplog.text |
| 409 | + |
| 410 | + |
| 411 | +def test_send_email_to_recipients_logs_config_failure_and_stops( |
| 412 | + pre_registration_service: PreRegistrationService, |
| 413 | + fake_email_service: FakeEmailService, |
| 414 | + caplog: pytest.LogCaptureFixture, |
| 415 | +): |
| 416 | + fake_email_service.config_failed_emails.add("config@example.com") |
| 417 | + |
| 418 | + with caplog.at_level( |
| 419 | + logging.ERROR, logger="wacruit.src.apps.pre_registration.services" |
| 420 | + ): |
| 421 | + pre_registration_service._send_email_to_recipients( |
| 422 | + recipient_emails=["config@example.com", "skipped@example.com"], |
| 423 | + subject="subject", |
| 424 | + content="content", |
| 425 | + html_content=None, |
| 426 | + ) |
| 427 | + |
| 428 | + assert fake_email_service.sent_emails == [] |
| 429 | + assert "Pre-registration email configuration failed" in caplog.text |
| 430 | + assert "config@example.com" in caplog.text |
0 commit comments