-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #176 from eht16/support_message_log_without_data
Support message log without message data
- Loading branch information
Showing
5 changed files
with
85 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/mailer/migrations/0007_alter_messagelog_message_data.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 5.0.4 on 2024-04-13 09:37 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("mailer", "0006_message_retry_count"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="messagelog", | ||
name="message_data", | ||
field=models.TextField(null=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import datetime | ||
import pickle | ||
import time | ||
from unittest.mock import Mock, patch | ||
from unittest.mock import Mock, PropertyMock, patch | ||
|
||
import django | ||
import lockfile | ||
|
@@ -634,8 +634,34 @@ def test_message_log(self): | |
# Fake a log entry without email | ||
log.message_data = "" | ||
|
||
self.assertEqual(log.to_addresses, []) | ||
self.assertEqual(log.subject, "") | ||
self.assertEqual(log.to_addresses, None) | ||
self.assertEqual(log.subject, None) | ||
|
||
def test_message_log_without_log_message_data(self): | ||
with self.settings( | ||
MAILER_EMAIL_BACKEND="django.core.mail.backends.locmem.EmailBackend", | ||
MAILER_EMAIL_LOG_MESSAGE_DATA=False, | ||
): # noqa | ||
mailer.send_mail("Subject Log", "Body", "[email protected]", ["[email protected]"]) | ||
|
||
self.assertEqual(Message.objects.count(), 1) | ||
self.assertEqual(Message.objects.deferred().count(), 0) | ||
self.assertEqual(MessageLog.objects.count(), 0) | ||
when_added = Message.objects.first().when_added | ||
|
||
engine.send_all() | ||
|
||
self.assertEqual(Message.objects.count(), 0) | ||
self.assertEqual(Message.objects.deferred().count(), 0) | ||
self.assertEqual(MessageLog.objects.count(), 1) | ||
|
||
log = MessageLog.objects.all()[0] | ||
|
||
self.assertEqual(log.email, None) | ||
self.assertEqual(log.message_data, None) | ||
self.assertEqual(log.to_addresses, None) | ||
self.assertEqual(log.subject, None) | ||
self.assertEqual(log.when_added, when_added) | ||
|
||
def test_message_str(self): | ||
with self.settings(MAILER_EMAIL_BACKEND="django.core.mail.backends.locmem.EmailBackend"): | ||
|
@@ -664,8 +690,12 @@ def test_message_log_str(self): | |
f'On {log.when_attempted}, "Subject Log 中" to [email protected]', | ||
) | ||
|
||
with patch.object(MessageLog, "when_attempted", new_callable=PropertyMock) as log_mock: | ||
log_mock.side_effect = ValueError | ||
self.assertEqual(str(log), "<MessageLog repr unavailable>") | ||
|
||
log.message_data = None | ||
self.assertEqual(str(log), "<MessageLog repr unavailable>") | ||
self.assertEqual(str(log), f'On {log.when_attempted}, "{log.message_id}"') | ||
|
||
|
||
class DbToEmailTest(TestCase): | ||
|