【发布时间】:2020-03-24 13:12:06
【问题描述】:
我想解决这个错误并完成测试:
admin.py
def suit_row_attributes(self, obj, request):
"""Add colours to the rows according to the status"""
type_error = 'notSent'
status_colours = {Transaction.STATUS_REJECTED: 'error', Transaction.STATUS_RECEIVED: 'received',
Transaction.STATUS_PENDING: 'warning', Transaction.STATUS_ACCEPTED: 'success',
type_error: 'notSent'}
try:
tt_status = Transaction.objects.get(txid=obj.numero).last_status
except Transaction.DoesNotExist:
tt_status = type_error
return {'class': status_colours.get(tt_status, 'success')}
在tests.py中
def test_suit_row_attributes(self):
self.assertEqual(self.admin_instance.suit_row_attributes(self.errortr_obj), {'class': 'notSent'})
有人可以帮帮我吗?
【问题讨论】:
-
能否提供实际的错误信息?
-
这是当前的错误消息:test_suit_row_attributes() 缺少 1 个必需的位置参数:'request'
-
我已经解决了。 with this: #Add this in the def setup(self): self.request = mock.Mock() def test_suit_row_attributes(self): self.assertEqual(self.admin_instance.suit_row_attributes(self.errortr_obj, self.request), {'类':'notSent'})
-
非常好!您能否将其添加为下面的答案并提供其工作原理? :)
标签: django testing request django-tests django-suit