我是 Django 测试的新手。如何为此视图功能创建单元测试?我的单元测试功能应该从视图中导入功能吗?请举个例子。这将帮助我了解它是如何工作的
@maintainance_job
def time_to_end(request):
today = datetime.date.today()
datas = Data.objects.filter(start__lte=today,
other_date__gte=today)
for data in datas:
subject = _(u'Send email')
body = render_to_string('mail.txt',
{'data': data})
email = EmailMessage(subject, body,
'admin@admin.com',
[data.user.email])
email.send()
return HttpResponse('Done')
网址:
(r'^maintainance/jobs/time_to_end/$', 'content.views.time_to_end'),