11from datetime import timedelta
2+ from decimal import Decimal
23from unittest .mock import call
34
4- from conferences .models .conference_voucher import ConferenceVoucher
5- from conferences .tests .factories import ConferenceFactory , ConferenceVoucherFactory
6- from grants .tests .factories import GrantFactory
75import pytest
86from django .utils import timezone
97
8+ from conferences .models .conference_voucher import ConferenceVoucher
9+ from conferences .tests .factories import ConferenceFactory , ConferenceVoucherFactory
1010from grants .admin import (
1111 confirm_pending_status ,
1212 create_grant_vouchers ,
13+ mark_rejected_and_send_email ,
1314 reset_pending_status_back_to_status ,
1415 send_reply_emails ,
15- mark_rejected_and_send_email ,
1616)
1717from grants .models import Grant
18-
18+ from grants .tests .factories import (
19+ GrantFactory ,
20+ GrantReimbursementFactory ,
21+ )
1922
2023pytestmark = pytest .mark .django_db
2124
@@ -60,9 +63,11 @@ def test_send_reply_emails_with_grants_from_multiple_conferences_fails(
6063 mock_send_rejected_email .assert_not_called ()
6164
6265
63- def test_send_reply_emails_approved_grant_missing_approved_type (rf , mocker , admin_user ):
66+ def test_send_reply_emails_approved_grant_missing_reimbursements (
67+ rf , mocker , admin_user
68+ ):
6469 mock_messages = mocker .patch ("grants.admin.messages" )
65- grant = GrantFactory (status = Grant .Status .approved , approved_type = None )
70+ grant = GrantFactory (status = Grant .Status .approved )
6671 request = rf .get ("/" )
6772 request .user = admin_user
6873 mock_send_approved_email = mocker .patch (
@@ -73,20 +78,21 @@ def test_send_reply_emails_approved_grant_missing_approved_type(rf, mocker, admi
7378
7479 mock_messages .error .assert_called_once_with (
7580 request ,
76- f"Grant for { grant .name } is missing 'Grant Approved Type' !" ,
81+ f"Grant for { grant .name } is missing reimbursement categories !" ,
7782 )
7883 mock_send_approved_email .assert_not_called ()
7984
8085
8186def test_send_reply_emails_approved_missing_amount (rf , mocker , admin_user ):
8287 mock_messages = mocker .patch ("grants.admin.messages" )
83- grant = GrantFactory (
84- status = Grant .Status .approved ,
85- approved_type = Grant .ApprovedType .ticket_accommodation ,
86- total_amount = None ,
88+ grant = GrantFactory (status = Grant .Status .approved )
89+ # Create reimbursement with 0 amount so total_allocated_amount is 0
90+ GrantReimbursementFactory (
91+ grant = grant ,
92+ category__conference = grant .conference ,
93+ category__ticket = True ,
94+ granted_amount = Decimal ("0" ),
8795 )
88- grant .total_amount = None
89- grant .save ()
9096 request = rf .get ("/" )
9197 request .user = admin_user
9298 mock_send_approved_email = mocker .patch (
@@ -106,10 +112,19 @@ def test_send_reply_emails_approved_set_deadline_in_fourteen_days(
106112 rf , mocker , admin_user
107113):
108114 mock_messages = mocker .patch ("grants.admin.messages" )
109- grant = GrantFactory (
110- status = Grant .Status .approved ,
111- approved_type = Grant .ApprovedType .ticket_accommodation ,
112- total_amount = 800 ,
115+ grant = GrantFactory (status = Grant .Status .approved )
116+ GrantReimbursementFactory (
117+ grant = grant ,
118+ category__conference = grant .conference ,
119+ category__ticket = True ,
120+ granted_amount = Decimal ("100" ),
121+ )
122+ GrantReimbursementFactory (
123+ grant = grant ,
124+ category__conference = grant .conference ,
125+ category__accommodation = True ,
126+ category__max_amount = Decimal ("700" ),
127+ granted_amount = Decimal ("700" ),
113128 )
114129 request = rf .get ("/" )
115130 request .user = admin_user
0 commit comments