Python Django测试错误

Python Django测试错误,python,django,testing,Python,Django,Testing,我正试图为我的django应用程序编写测试,但我遇到了一个无法解释的错误。出于某种原因,我得到了这段代码的一个错误 self.client.login(email='example@comcast.net', password='password') resp = self.client.get(reverse('task:accept_bid', kwargs={'task_pk' : 8, 'bid_pk' : 6} )) 但是当我这样做的时候,我得到了一个错误(我只是不

我正试图为我的django应用程序编写测试,但我遇到了一个无法解释的错误。出于某种原因,我得到了这段代码的一个错误

self.client.login(email='example@comcast.net', password='password')
resp = self.client.get(reverse('task:accept_bid', 
    kwargs={'task_pk' : 8, 'bid_pk' : 6}
    ))
但是当我这样做的时候,我得到了一个错误(我只是不登录相同的代码)

这是我得到的回溯

Traceback (most recent call last):
   File "/Users/AdamC/projects/WorkStudy/workstudy/tasks/tests.py", line 37, in test_this
kwargs={'task_pk' : 8, 'bid_pk' : 6}
  File "/Users/AdamC/projects/Environment/WorkStudy-env/lib/python2.7/site-packages/django/test/client.py", line 473, in get
    response = super(Client, self).get(path, data=data, **extra)
   File "/Users/AdamC/projects/Environment/WorkStudy-env/lib/python2.7/site-packages/django/test/client.py", line 280, in get
    return self.request(**r)
  File "/Users/AdamC/projects/Environment/WorkStudy-env/lib/python2.7/site-packages/django/test/client.py", line 444, in request
    six.reraise(*exc_info)
  File "/Users/AdamC/projects/Environment/WorkStudy-env/lib/python2.7/site-packages/django/core/handlers/base.py", line 112, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/AdamC/projects/Environment/WorkStudy-env/lib/python2.7/site-packages/django/contrib/auth/decorators.py", line 22, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/Users/AdamC/projects/WorkStudy/workstudy/tasks/views.py", line 44, in accept_a_bid_view
    """)
TypeError: error() takes at least 2 arguments (1 given)
这是“接受出价”视图代码

@login_required
def accept_a_bid_view(request, **kwargs):
    task=Task.objects.get(pk=kwargs['task_pk'])

    if task.creator == request.user and task.accepted_bid == None:
        bid = Bid.objects.get(pk=kwargs['bid_pk'])
        task.accepted_bid = bid
        task.worker = bid.bidder
        task.accepted = True
        task.accepted_date = datetime.datetime.utcnow().replace(tzinfo=timezone.utc)
        task.save()
        messages.success(request,"Congrats you've accepted a bid I'm proud of you")
    if bid.bidder.email_notifactions:
        send_mail(' Notification',
            "Someone accepted your bid",
            EMAIL_HOST_USER,
            [task.creator.email],
            fail_silently=False)
    return HttpResponseRedirect(reverse('task:task_list'))
    else:
        messages.error("""It looks as if this task has already been accepted
         or maybe you're not the creator, but why would you being clicking 
         buttons then... (The NSA is watchig you)
         """)
    return HttpResponseRedirect(reverse('home'))

您忘记将
请求添加到

messages.error("""It looks as if this task has already been accepted
         or maybe you're not the creator, but why would you being clicking 
         buttons then... (The NSA is watchig you)
         """)
它应该看起来像

messages.error(request, """It looks as if this task has already been accepted
         or maybe you're not the creator, but why would you being clicking 
         buttons then... (The NSA is watchig you)
         """)

我们可以查看
接受投标视图的代码吗?看起来像是一个代码路径,只有当你不登录调用名为
error
且参数无效的函数时才会使用。你真是个圣人,我真不敢相信我错过了我一直在查看测试代码的机会。
messages.error(request, """It looks as if this task has already been accepted
         or maybe you're not the creator, but why would you being clicking 
         buttons then... (The NSA is watchig you)
         """)