22from notifications .tests .factories import EmailTemplateFactory
33from conferences .tests .factories import ConferenceVoucherFactory
44from datetime import datetime , timezone
5- from unittest .mock import patch
65
76import time_machine
87from conferences .models .conference_voucher import ConferenceVoucher
2221 ConferenceVoucher .VoucherType .GRANT ,
2322 ],
2423)
25- def test_send_conference_voucher_email (voucher_type ):
24+ def test_send_conference_voucher_email (voucher_type , sent_emails ):
2625 user = UserFactory (
2726 full_name = "Marco Acierno" ,
2827 email = "marco@placeholder.it" ,
@@ -41,19 +40,21 @@ def test_send_conference_voucher_email(voucher_type):
4140 identifier = EmailTemplateIdentifier .voucher_code ,
4241 )
4342
44- with patch (
45- "conferences.tasks.EmailTemplate"
46- ) as mock_email_template , time_machine .travel ("2020-10-10 10:00:00Z" , tick = False ):
43+ with time_machine .travel ("2020-10-10 10:00:00Z" , tick = False ):
4744 send_conference_voucher_email (conference_voucher_id = conference_voucher .id )
4845
49- mock_email_template .objects .for_conference ().get_by_identifier ().send_email .assert_called_once_with (
50- recipient = user ,
51- placeholders = {
52- "voucher_code" : "ABC123" ,
53- "voucher_type" : voucher_type ,
54- "user_name" : "Marco Acierno" ,
55- },
56- )
46+ emails_sent = sent_emails ()
47+ assert emails_sent .count () == 1
48+
49+ sent_email = emails_sent .first ()
50+ assert sent_email .email_template .identifier == EmailTemplateIdentifier .voucher_code
51+ assert sent_email .email_template .conference == conference_voucher .conference
52+ assert sent_email .recipient == user
53+ assert sent_email .placeholders == {
54+ "voucher_code" : "ABC123" ,
55+ "voucher_type" : voucher_type ,
56+ "user_name" : "Marco Acierno" ,
57+ }
5758
5859 conference_voucher .refresh_from_db ()
5960 assert conference_voucher .voucher_email_sent_at == datetime (
0 commit comments