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)
17- from grants .models import Grant
18-
17+ from grants .models import Grant , GrantReimbursement , GrantReimbursementCategory
18+ from grants . tests . factories import GrantFactory
1919
2020pytestmark = pytest .mark .django_db
2121
@@ -60,9 +60,11 @@ def test_send_reply_emails_with_grants_from_multiple_conferences_fails(
6060 mock_send_rejected_email .assert_not_called ()
6161
6262
63- def test_send_reply_emails_approved_grant_missing_approved_type (rf , mocker , admin_user ):
63+ def test_send_reply_emails_approved_grant_missing_reimbursements (
64+ rf , mocker , admin_user
65+ ):
6466 mock_messages = mocker .patch ("grants.admin.messages" )
65- grant = GrantFactory (status = Grant .Status .approved , approved_type = None )
67+ grant = GrantFactory (status = Grant .Status .approved )
6668 request = rf .get ("/" )
6769 request .user = admin_user
6870 mock_send_approved_email = mocker .patch (
@@ -73,20 +75,28 @@ def test_send_reply_emails_approved_grant_missing_approved_type(rf, mocker, admi
7375
7476 mock_messages .error .assert_called_once_with (
7577 request ,
76- f"Grant for { grant .name } is missing 'Grant Approved Type' !" ,
78+ f"Grant for { grant .name } is missing reimbursement categories !" ,
7779 )
7880 mock_send_approved_email .assert_not_called ()
7981
8082
8183def test_send_reply_emails_approved_missing_amount (rf , mocker , admin_user ):
8284 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 ,
85+ grant = GrantFactory (status = Grant .Status .approved )
86+ # Create reimbursement categories and reimbursements with 0 amount
87+ ticket_category = GrantReimbursementCategory .objects .create (
88+ conference = grant .conference ,
89+ category = GrantReimbursementCategory .Category .TICKET ,
90+ name = "Ticket" ,
91+ max_amount = Decimal ("100" ),
92+ included_by_default = True ,
93+ )
94+ # Create reimbursement with 0 amount so total_allocated_amount is 0
95+ GrantReimbursement .objects .create (
96+ grant = grant ,
97+ category = ticket_category ,
98+ granted_amount = Decimal ("0" ),
8799 )
88- grant .total_amount = None
89- grant .save ()
90100 request = rf .get ("/" )
91101 request .user = admin_user
92102 mock_send_approved_email = mocker .patch (
@@ -106,10 +116,31 @@ def test_send_reply_emails_approved_set_deadline_in_fourteen_days(
106116 rf , mocker , admin_user
107117):
108118 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 ,
119+ grant = GrantFactory (status = Grant .Status .approved )
120+ # Create reimbursement categories and reimbursements
121+ ticket_category = GrantReimbursementCategory .objects .create (
122+ conference = grant .conference ,
123+ category = GrantReimbursementCategory .Category .TICKET ,
124+ name = "Ticket" ,
125+ max_amount = Decimal ("100" ),
126+ included_by_default = True ,
127+ )
128+ accommodation_category = GrantReimbursementCategory .objects .create (
129+ conference = grant .conference ,
130+ category = GrantReimbursementCategory .Category .ACCOMMODATION ,
131+ name = "Accommodation" ,
132+ max_amount = Decimal ("700" ),
133+ included_by_default = False ,
134+ )
135+ GrantReimbursement .objects .create (
136+ grant = grant ,
137+ category = ticket_category ,
138+ granted_amount = Decimal ("100" ),
139+ )
140+ GrantReimbursement .objects .create (
141+ grant = grant ,
142+ category = accommodation_category ,
143+ granted_amount = Decimal ("700" ),
113144 )
114145 request = rf .get ("/" )
115146 request .user = admin_user
0 commit comments