|
10 | 10 | send_grant_reply_waiting_list_email, |
11 | 11 | send_grant_reply_waiting_list_update_email, |
12 | 12 | ) |
13 | | -from grants.tests.factories import ( |
14 | | - GrantFactory, |
15 | | - GrantReimbursementFactory, |
16 | | -) |
| 13 | +from grants.tests.factories import GrantFactory, GrantReimbursementFactory |
17 | 14 | from users.tests.factories import UserFactory |
18 | 15 |
|
19 | 16 | pytestmark = pytest.mark.django_db |
@@ -166,8 +163,8 @@ def test_handle_grant_reply_sent_reminder(settings, sent_emails): |
166 | 163 | assert sent_email.placeholders["deadline_date"] == "1 February 2023" |
167 | 164 | assert sent_email.placeholders["reply_url"] == "https://pycon.it/grants/reply/" |
168 | 165 | assert sent_email.placeholders["visa_page_link"] == "https://pycon.it/visa" |
169 | | - assert not sent_email.placeholders["has_approved_travel"] |
170 | | - assert not sent_email.placeholders["has_approved_accommodation"] |
| 166 | + assert sent_email.placeholders["ticket_only"] |
| 167 | + assert sent_email.placeholders["total_amount"] is None |
171 | 168 | assert sent_email.placeholders["is_reminder"] |
172 | 169 |
|
173 | 170 |
|
@@ -240,51 +237,16 @@ def test_handle_grant_approved_ticket_travel_accommodation_reply_sent( |
240 | 237 | ) |
241 | 238 | assert sent_email.placeholders["start_date"] == "2 May" |
242 | 239 | assert sent_email.placeholders["end_date"] == "6 May" |
243 | | - assert sent_email.placeholders["travel_amount"] == "680" |
| 240 | + # Total amount is 680 (travel) + 200 (accommodation) = 880, excluding ticket |
| 241 | + assert sent_email.placeholders["total_amount"] == "880" |
244 | 242 | assert sent_email.placeholders["deadline_date_time"] == "1 February 2023 23:59 UTC" |
245 | 243 | assert sent_email.placeholders["deadline_date"] == "1 February 2023" |
246 | 244 | assert sent_email.placeholders["reply_url"] == "https://pycon.it/grants/reply/" |
247 | 245 | assert sent_email.placeholders["visa_page_link"] == "https://pycon.it/visa" |
248 | | - assert sent_email.placeholders["has_approved_travel"] |
249 | | - assert sent_email.placeholders["has_approved_accommodation"] |
| 246 | + assert not sent_email.placeholders["ticket_only"] |
250 | 247 | assert not sent_email.placeholders["is_reminder"] |
251 | 248 |
|
252 | 249 |
|
253 | | -def test_handle_grant_approved_ticket_travel_accommodation_fails_with_no_amount( |
254 | | - settings, |
255 | | -): |
256 | | - settings.FRONTEND_URL = "https://pycon.it" |
257 | | - |
258 | | - conference = ConferenceFactory( |
259 | | - start=datetime(2023, 5, 2, tzinfo=timezone.utc), |
260 | | - end=datetime(2023, 5, 5, tzinfo=timezone.utc), |
261 | | - ) |
262 | | - user = UserFactory( |
263 | | - full_name="Marco Acierno", |
264 | | - |
265 | | - name="Marco", |
266 | | - username="marco", |
267 | | - ) |
268 | | - |
269 | | - grant = GrantFactory( |
270 | | - conference=conference, |
271 | | - applicant_reply_deadline=datetime(2023, 2, 1, 23, 59, tzinfo=timezone.utc), |
272 | | - user=user, |
273 | | - ) |
274 | | - GrantReimbursementFactory( |
275 | | - grant=grant, |
276 | | - category__conference=conference, |
277 | | - category__travel=True, |
278 | | - category__max_amount=Decimal("680"), |
279 | | - granted_amount=Decimal("0"), |
280 | | - ) |
281 | | - |
282 | | - with pytest.raises( |
283 | | - ValueError, match="Grant travel amount is set to Zero, can't send the email!" |
284 | | - ): |
285 | | - send_grant_reply_approved_email(grant_id=grant.id, is_reminder=False) |
286 | | - |
287 | | - |
288 | 250 | def test_handle_grant_approved_ticket_only_reply_sent(settings, sent_emails): |
289 | 251 | from notifications.models import EmailTemplateIdentifier |
290 | 252 | from notifications.tests.factories import EmailTemplateFactory |
@@ -344,8 +306,8 @@ def test_handle_grant_approved_ticket_only_reply_sent(settings, sent_emails): |
344 | 306 | assert sent_email.placeholders["deadline_date"] == "1 February 2023" |
345 | 307 | assert sent_email.placeholders["reply_url"] == "https://pycon.it/grants/reply/" |
346 | 308 | assert sent_email.placeholders["visa_page_link"] == "https://pycon.it/visa" |
347 | | - assert not sent_email.placeholders["has_approved_travel"] |
348 | | - assert not sent_email.placeholders["has_approved_accommodation"] |
| 309 | + assert sent_email.placeholders["ticket_only"] |
| 310 | + assert sent_email.placeholders["total_amount"] is None |
349 | 311 | assert not sent_email.placeholders["is_reminder"] |
350 | 312 |
|
351 | 313 |
|
@@ -415,12 +377,46 @@ def test_handle_grant_approved_travel_reply_sent(settings, sent_emails): |
415 | 377 | assert sent_email.placeholders["deadline_date"] == "1 February 2023" |
416 | 378 | assert sent_email.placeholders["reply_url"] == "https://pycon.it/grants/reply/" |
417 | 379 | assert sent_email.placeholders["visa_page_link"] == "https://pycon.it/visa" |
418 | | - assert sent_email.placeholders["has_approved_travel"] |
419 | | - assert not sent_email.placeholders["has_approved_accommodation"] |
420 | | - assert sent_email.placeholders["travel_amount"] == "400" |
| 380 | + # Total amount is 400 (travel only), excluding ticket |
| 381 | + assert sent_email.placeholders["total_amount"] == "400" |
| 382 | + assert not sent_email.placeholders["ticket_only"] |
421 | 383 | assert not sent_email.placeholders["is_reminder"] |
422 | 384 |
|
423 | 385 |
|
| 386 | +def test_send_grant_approved_email_raises_for_no_reimbursements(settings) -> None: |
| 387 | + """Verify error is raised when grant has no valid reimbursements.""" |
| 388 | + from notifications.models import EmailTemplateIdentifier |
| 389 | + from notifications.tests.factories import EmailTemplateFactory |
| 390 | + |
| 391 | + settings.FRONTEND_URL = "https://pycon.it" |
| 392 | + |
| 393 | + conference = ConferenceFactory( |
| 394 | + start=datetime(2023, 5, 2, tzinfo=timezone.utc), |
| 395 | + end=datetime(2023, 5, 5, tzinfo=timezone.utc), |
| 396 | + ) |
| 397 | + user = UserFactory( |
| 398 | + full_name="Marco Acierno", |
| 399 | + |
| 400 | + ) |
| 401 | + |
| 402 | + grant = GrantFactory( |
| 403 | + conference=conference, |
| 404 | + applicant_reply_deadline=datetime(2023, 2, 1, 23, 59, tzinfo=timezone.utc), |
| 405 | + user=user, |
| 406 | + ) |
| 407 | + # No reimbursements - this is an invalid state |
| 408 | + |
| 409 | + EmailTemplateFactory( |
| 410 | + conference=grant.conference, |
| 411 | + identifier=EmailTemplateIdentifier.grant_approved, |
| 412 | + ) |
| 413 | + |
| 414 | + with pytest.raises( |
| 415 | + ValueError, match="has no reimbursement amount and is not ticket-only" |
| 416 | + ): |
| 417 | + send_grant_reply_approved_email(grant_id=grant.id, is_reminder=False) |
| 418 | + |
| 419 | + |
424 | 420 | def test_send_grant_reply_waiting_list_update_email(settings, sent_emails): |
425 | 421 | from notifications.models import EmailTemplateIdentifier |
426 | 422 | from notifications.tests.factories import EmailTemplateFactory |
|
0 commit comments