| | @@ -17,51 +17,60 @@ |
| 17 | 17 | |
| 18 | 18 | |
| 19 | 19 | @pytest.mark.django_db |
| 20 | 20 | class TestNotificationTemplateRendering: |
| 21 | 21 | def test_notification_template_renders(self): |
| 22 | | - html = render_to_string("email/notification.html", { |
| 23 | | - "event_type": "checkin", |
| 24 | | - "project_name": "My Project", |
| 25 | | - "message": "Added new feature", |
| 26 | | - "action_url": "/projects/my-project/fossil/checkin/abc123/", |
| 27 | | - "project_url": "/projects/my-project/", |
| 28 | | - "unsubscribe_url": "/projects/my-project/fossil/watch/", |
| 29 | | - "preferences_url": "/auth/notifications/", |
| 30 | | - }) |
| 31 | | - assert "fossilrepo" in html |
| 22 | + html = render_to_string( |
| 23 | + "email/notification.html", |
| 24 | + { |
| 25 | + "event_type": "checkin", |
| 26 | + "project_name": "My Project", |
| 27 | + "message": "Added new feature", |
| 28 | + "action_url": "/projects/my-project/fossil/checkin/abc123/", |
| 29 | + "project_url": "/projects/my-project/", |
| 30 | + "unsubscribe_url": "/projects/my-project/fossil/watch/", |
| 31 | + "preferences_url": "/auth/notifications/", |
| 32 | + }, |
| 33 | + ) |
| 34 | + assert "fossil<span>repo</span>" in html |
| 32 | 35 | assert "My Project" in html |
| 33 | 36 | assert "Added new feature" in html |
| 34 | 37 | assert "checkin" in html |
| 35 | 38 | assert "View Details" in html |
| 36 | 39 | assert "/projects/my-project/fossil/checkin/abc123/" in html |
| 37 | 40 | assert "Unsubscribe" in html |
| 38 | 41 | |
| 39 | 42 | def test_notification_template_without_action_url(self): |
| 40 | | - html = render_to_string("email/notification.html", { |
| 41 | | - "event_type": "ticket", |
| 42 | | - "project_name": "My Project", |
| 43 | | - "message": "New ticket filed", |
| 44 | | - "action_url": "", |
| 45 | | - "project_url": "/projects/my-project/", |
| 46 | | - "unsubscribe_url": "/projects/my-project/fossil/watch/", |
| 47 | | - "preferences_url": "/auth/notifications/", |
| 48 | | - }) |
| 43 | + html = render_to_string( |
| 44 | + "email/notification.html", |
| 45 | + { |
| 46 | + "event_type": "ticket", |
| 47 | + "project_name": "My Project", |
| 48 | + "message": "New ticket filed", |
| 49 | + "action_url": "", |
| 50 | + "project_url": "/projects/my-project/", |
| 51 | + "unsubscribe_url": "/projects/my-project/fossil/watch/", |
| 52 | + "preferences_url": "/auth/notifications/", |
| 53 | + }, |
| 54 | + ) |
| 49 | 55 | assert "View Details" not in html |
| 50 | 56 | assert "New ticket filed" in html |
| 51 | 57 | |
| 52 | 58 | def test_notification_template_event_types(self): |
| 53 | 59 | for event_type in ["checkin", "ticket", "wiki", "release", "forum"]: |
| 54 | | - html = render_to_string("email/notification.html", { |
| 55 | | - "event_type": event_type, |
| 56 | | - "project_name": "Test", |
| 57 | | - "message": "Test message", |
| 58 | | - "action_url": "", |
| 59 | | - "project_url": "/projects/test/", |
| 60 | | - "unsubscribe_url": "/projects/test/fossil/watch/", |
| 61 | | - "preferences_url": "/auth/notifications/", |
| 62 | | - }) |
| 60 | + html = render_to_string( |
| 61 | + "email/notification.html", |
| 62 | + { |
| 63 | + "event_type": event_type, |
| 64 | + "project_name": "Test", |
| 65 | + "message": "Test message", |
| 66 | + "action_url": "", |
| 67 | + "project_url": "/projects/test/", |
| 68 | + "unsubscribe_url": "/projects/test/fossil/watch/", |
| 69 | + "preferences_url": "/auth/notifications/", |
| 70 | + }, |
| 71 | + ) |
| 63 | 72 | assert event_type in html |
| 64 | 73 | |
| 65 | 74 | def test_digest_template_renders(self): |
| 66 | 75 | class MockNotif: |
| 67 | 76 | def __init__(self, event_type, title, project_name): |
| | @@ -76,35 +85,41 @@ |
| 76 | 85 | notifications = [ |
| 77 | 86 | MockNotif("checkin", "Added login page", "Frontend"), |
| 78 | 87 | MockNotif("ticket", "Bug: 404 on settings", "Backend"), |
| 79 | 88 | MockNotif("wiki", "Updated README", "Docs"), |
| 80 | 89 | ] |
| 81 | | - html = render_to_string("email/digest.html", { |
| 82 | | - "digest_type": "daily", |
| 83 | | - "count": 3, |
| 84 | | - "notifications": notifications, |
| 85 | | - "overflow_count": 0, |
| 86 | | - "dashboard_url": "/", |
| 87 | | - "preferences_url": "/auth/notifications/", |
| 88 | | - }) |
| 90 | + html = render_to_string( |
| 91 | + "email/digest.html", |
| 92 | + { |
| 93 | + "digest_type": "daily", |
| 94 | + "count": 3, |
| 95 | + "notifications": notifications, |
| 96 | + "overflow_count": 0, |
| 97 | + "dashboard_url": "/", |
| 98 | + "preferences_url": "/auth/notifications/", |
| 99 | + }, |
| 100 | + ) |
| 89 | 101 | assert "Daily Digest" in html |
| 90 | 102 | assert "3 update" in html |
| 91 | 103 | assert "Frontend" in html |
| 92 | 104 | assert "Backend" in html |
| 93 | 105 | assert "Docs" in html |
| 94 | 106 | assert "Added login page" in html |
| 95 | 107 | assert "View All Notifications" in html |
| 96 | 108 | |
| 97 | 109 | def test_digest_template_overflow(self): |
| 98 | | - html = render_to_string("email/digest.html", { |
| 99 | | - "digest_type": "weekly", |
| 100 | | - "count": 75, |
| 101 | | - "notifications": [], |
| 102 | | - "overflow_count": 25, |
| 103 | | - "dashboard_url": "/", |
| 104 | | - "preferences_url": "/auth/notifications/", |
| 105 | | - }) |
| 110 | + html = render_to_string( |
| 111 | + "email/digest.html", |
| 112 | + { |
| 113 | + "digest_type": "weekly", |
| 114 | + "count": 75, |
| 115 | + "notifications": [], |
| 116 | + "overflow_count": 25, |
| 117 | + "dashboard_url": "/", |
| 118 | + "preferences_url": "/auth/notifications/", |
| 119 | + }, |
| 120 | + ) |
| 106 | 121 | assert "Weekly Digest" in html |
| 107 | 122 | assert "75 update" in html |
| 108 | 123 | assert "25 more" in html |
| 109 | 124 | |
| 110 | 125 | |
| | @@ -137,11 +152,11 @@ |
| 137 | 152 | ) |
| 138 | 153 | |
| 139 | 154 | mock_send.assert_called_once() |
| 140 | 155 | call_kwargs = mock_send.call_args.kwargs |
| 141 | 156 | assert "html_message" in call_kwargs |
| 142 | | - assert "fossilrepo" in call_kwargs["html_message"] |
| 157 | + assert "fossil<span>repo</span>" in call_kwargs["html_message"] |
| 143 | 158 | assert "checkin" in call_kwargs["html_message"] |
| 144 | 159 | assert "Added login feature" in call_kwargs["html_message"] |
| 145 | 160 | # Plain text fallback is also present |
| 146 | 161 | assert call_kwargs["message"] != "" |
| 147 | 162 | |
| | @@ -206,19 +221,19 @@ |
| 206 | 221 | title=f"Commit #{i}", |
| 207 | 222 | ) |
| 208 | 223 | |
| 209 | 224 | from fossil.tasks import send_digest |
| 210 | 225 | |
| 211 | | - with patch("fossil.tasks.send_mail") as mock_send: |
| 226 | + with patch("django.core.mail.send_mail") as mock_send: |
| 212 | 227 | send_digest.apply(kwargs={"mode": "daily"}) |
| 213 | 228 | |
| 214 | 229 | mock_send.assert_called_once() |
| 215 | 230 | call_kwargs = mock_send.call_args.kwargs |
| 216 | 231 | assert "html_message" in call_kwargs |
| 217 | 232 | assert "Daily Digest" in call_kwargs["html_message"] |
| 218 | 233 | assert "3 update" in call_kwargs["html_message"] |
| 219 | | - assert "fossilrepo" in call_kwargs["html_message"] |
| 234 | + assert 'fossil<span style="color: #DC394C;">repo</span>' in call_kwargs["html_message"] |
| 220 | 235 | # Plain text fallback |
| 221 | 236 | assert "3 new notifications" in call_kwargs["message"] |
| 222 | 237 | |
| 223 | 238 | def test_digest_html_includes_project_names(self, daily_user, sample_project): |
| 224 | 239 | Notification.objects.create( |
| | @@ -228,11 +243,11 @@ |
| 228 | 243 | title="Bug filed", |
| 229 | 244 | ) |
| 230 | 245 | |
| 231 | 246 | from fossil.tasks import send_digest |
| 232 | 247 | |
| 233 | | - with patch("fossil.tasks.send_mail") as mock_send: |
| 248 | + with patch("django.core.mail.send_mail") as mock_send: |
| 234 | 249 | send_digest.apply(kwargs={"mode": "daily"}) |
| 235 | 250 | |
| 236 | 251 | call_kwargs = mock_send.call_args.kwargs |
| 237 | 252 | assert sample_project.name in call_kwargs["html_message"] |
| 238 | 253 | |
| | @@ -245,11 +260,11 @@ |
| 245 | 260 | title=f"Commit #{i}", |
| 246 | 261 | ) |
| 247 | 262 | |
| 248 | 263 | from fossil.tasks import send_digest |
| 249 | 264 | |
| 250 | | - with patch("fossil.tasks.send_mail") as mock_send: |
| 265 | + with patch("django.core.mail.send_mail") as mock_send: |
| 251 | 266 | send_digest.apply(kwargs={"mode": "daily"}) |
| 252 | 267 | |
| 253 | 268 | call_kwargs = mock_send.call_args.kwargs |
| 254 | 269 | assert "5 more" in call_kwargs["html_message"] |
| 255 | 270 | |
| | @@ -265,11 +280,11 @@ |
| 265 | 280 | |
| 266 | 281 | Notification.objects.create(user=user, project=project, event_type="wiki", title="Wiki edit") |
| 267 | 282 | |
| 268 | 283 | from fossil.tasks import send_digest |
| 269 | 284 | |
| 270 | | - with patch("fossil.tasks.send_mail") as mock_send: |
| 285 | + with patch("django.core.mail.send_mail") as mock_send: |
| 271 | 286 | send_digest.apply(kwargs={"mode": "weekly"}) |
| 272 | 287 | |
| 273 | 288 | mock_send.assert_called_once() |
| 274 | 289 | call_kwargs = mock_send.call_args.kwargs |
| 275 | 290 | assert "Weekly Digest" in call_kwargs["html_message"] |
| 276 | 291 | |