1

我正在尝试编写一个测试,在该测试中我必须调用一个接受 **kwargs 的模型函数,这是来自我的模型的函数

def send_message(self, **kwargs):
    from django.core.mail import send_mail
    from django.conf import settings
    send_mail(
            recipient_list=[self.email_from,],
            from_email=settings.INFORMATION_FROM,
            **kwargs
        )

这就是我试图在测试中访问这个提及功能的地方

def test_send_message(self):
    send_message = self.user.send_message()
    print send_message  

并收到此错误TypeError: send_message() 至少需要 4 个参数(给定 2 个)

4

1 回答 1

0

由于这是 Django 的send_email()函数,它至少需要提供 4 个参数:

send_mail(subject, message, from_email, recipient_list, fail_silently=False, auth_user=None, auth_password=None, connection=None, html_message=None)

您没有将subjectand传递messagesend_message函数。修理它:

def test_send_message(self):
    send_message = self.user.send_message(subject="Test subject", message="Test message")
    print send_message  
于 2016-01-10T15:59:04.863 回答