gpt4 book ai didi

python - Django 测试错误

转载 作者:行者123 更新时间:2023-11-28 20:55:30 24 4
gpt4 key购买 nike

我正在尝试为我的 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}
))

但是当我这样做时我得到了一个错误(同样的代码我只是没有登录)

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)

这是 accept_bid_view 代码

@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)
""")

关于python - Django 测试错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24852846/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com