2

Django 単体テスト ドライバーでは、電子メールが送信されたかどうかをどのようにテストしますか?

4

2 に答える 2

5

私は Django の第一人者ではありませんが (控えめに言っても)、電子メールのテストに関するドキュメントがいくつかあるようです: Django アプリケーションのテスト | 電子メール サービス。示されているアプローチは、Django 1.0 以降用であることに注意してください。

于 2010-01-29T02:07:41.703 に答える
1

パスワードを忘れた場合の API 呼び出しのコードを次に示します。

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)
于 2012-11-20T15:06:08.213 に答える