【发布时间】:2018-10-03 13:49:52
【问题描述】:
使用覆盖率来查看必须测试的内容,覆盖率表明接下来必须测试:
send_alert.apply_async()
我知道这是芹菜任务,但是有什么方法可以测试代码行吗?
了解测试逻辑的其余代码:
class SomeView(GenericAPIView)
def post(self, request, *args, **kwargs):
#some code
if not value:
send_alert.apply_async()
# response
# not if Response
由于第一个答案而写的测试
@patch('event.views.send_alert')
def test_send_alert(self, mock_send):
data = {some data for post}
response = self.client.post('/api/{0}/mettings/'.format(self.user), data)
print(response.json())
self.assertTrue(mock_send.called)
我还检查了在任务print('Tasks Passed') 之后的视图,我看到任务通过的消息,但测试失败并出现错误AssertionError: False is not true
【问题讨论】:
标签: python celery python-unittest django-testing django-tests