Сейчас проверяю страницы на "есть или нет" с помощью Client() в test.py django и не получается пройти ряд страничек, появляется ошибка.
test.py
from django.test import TestCase
class Dynamic_pages(TestCase):
def test_video(self):
response = self.client.get('/video6') # или просто response = self.client.get('/video' ')
self.assertEqual(response.status_code, 200)
ulrs.py
url(r'^video(?P<video_id>[0-9]+)$', views.video, name='video'),
views.py
def video(request, video_id):
videoitem = Video.objects.get(id=video_id)
comview = Video_com.objects.filter(video_link_id=video_id)
comviewcount = comview.count()
form = Video_comForm(request.POST)
videosidebar = Video.objects.all().order_by('?')
arsenalbar = Arsenal.objects.all().order_by('?')[0:3]
videorandom = []
for ars in videosidebar:
if videoitem.id != ars.id:
videorandom.append(ars)
else:
pass
videorandom = videorandom[:6]
context = {
"videoitem": videoitem,
"videorandom": videorandom,
"arsenalbar": arsenalbar,
"comview": comview,
"comviewcount": comviewcount,
"form": form,
}
return render(request, 'faceset/videopage.html', context)
ошибка теста:
Error
Traceback (most recent call last):
File "E:\lieman\faceset\tests.py", line 225, in test_video6
response = self.client.get('/video6')
File "C:\python35\lib\site-packages\django\test\client.py", line 503, in get
**extra)
File "C:\python35\lib\site-packages\django\test\client.py", line 304, in get
return self.generic('GET', path, secure=secure, **r)
File "C:\python35\lib\site-packages\django\test\client.py", line 380, in generic
return self.request(**r)
File "C:\python35\lib\site-packages\django\test\client.py", line 467, in request
six.reraise(*exc_info)
File "C:\python35\lib\site-packages\django\utils\six.py", line 686, in reraise
raise value
File "C:\python35\lib\site-packages\django\core\handlers\base.py", line 149, in get_response
response = self.process_exception_by_middleware(e, request)
File "C:\python35\lib\site-packages\django\core\handlers\base.py", line 147, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "E:\lieman\faceset\views.py", line 763, in video
videoitem = Video.objects.get(id=video_id)
File "C:\python35\lib\site-packages\django\db\models\manager.py", line 122, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\python35\lib\site-packages\django\db\models\query.py", line 387, in get
self.model._meta.object_name
faceset.models.DoesNotExist: Video matching query does not exist.