Answer the question
In order to leave comments, you need to log in
Why does Client() in django-test throw an error on page validation?
Now I check the pages for "there or not" using Client () in test.py django and I can not go through a number of pages, an error appears.
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)
url(r'^video(?P<video_id>[0-9]+)$', views.video, name='video'),
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.
Answer the question
In order to leave comments, you need to log in
You have no objects in the database, so it gives an error.
In the test, before the request, you need to create the necessary objects.
Well and in that case it is necessary to give 404.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question