@@ -66,13 +66,14 @@ def test_send_with_sendgrid_success(self, mock_mail: MagicMock):
6666 mock_mail .return_value .add_personalization .assert_called_once ()
6767
6868 # Capture the categories added via add_category
69- mock_mail .return_value .add_category .assert_called_once ()
70- added_categories = mock_mail .return_value .add_category .call_args .args [0 ]
69+ # mock_mail.return_value.add_category.assert_called_once()
70+ assert mock_mail .return_value .add_category .call_count == 2
71+ added_categories = mock_mail .return_value .add_category .call_args_list
7172 assert len (added_categories ) == 2
72- assert isinstance (added_categories [0 ], Category )
73- assert isinstance (added_categories [1 ], Category )
74- assert added_categories [0 ].get () == category1
75- assert added_categories [1 ].get () == category2
73+ assert isinstance (added_categories [0 ]. args [ 0 ] , Category )
74+ assert isinstance (added_categories [1 ]. args [ 0 ] , Category )
75+ assert added_categories [0 ].args [ 0 ]. get () == category1
76+ assert added_categories [1 ].args [ 0 ]. get () == category2
7677
7778 mock_client .send .assert_called_once_with (mock_mail .return_value )
7879
@@ -103,6 +104,18 @@ def test_send_with_sendgrid_failure_returns_false(self, mock_mail, sentry_mock):
103104
104105 mock_client .send .assert_called_once_with (mock_mail .return_value )
105106
107+ mock_client .send .return_value = mock .Mock (status_code = 200 , body = 'correct' )
108+ to_addr = 'not-an-email'
109+ ret = _send_with_sendgrid (
110+ from_addr = from_addr ,
111+ to_addr = to_addr ,
112+ subject = subject ,
113+ message = message ,
114+ client = mock_client
115+ )
116+ assert not ret
117+ sentry_mock .assert_called ()
118+
106119
107120if __name__ == '__main__' :
108121 unittest .main ()
0 commit comments