In a Django unit test drive开发者_C百科r how do you test if an email is sent?
I'm not a Django guru (to put it mildly) but it looks like there is some documentation on testing email here: Testing Django Applications | E-mail services. Note that the demonstrated approach is for Django 1.0 and newer.
Here is some code for a forgot password api call
def test_forgot_password(self):
"""
This test makes sure the forgot password api call is working ...
"""
data = {
'username' : self.user.email,
}
self.assertTrue(self.user.forgot_pw_hash is None)
response = self.c.post(reverse('api_forgot_password'), data, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
# make sure there is an email in the out box and make sure
# the subject is correct
self.assertEquals(mail.outbox[0].subject,'Reset Password')
self.assertTrue(User.objects.get(email=self.user.email).forgot_pw_hash is not None)
精彩评论