S
S
Sergey Nizhny Novgorod2016-07-29 16:50:54
Django
Sergey Nizhny Novgorod, 2016-07-29 16:50:54

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)

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)

test error:
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

2 answer(s)
U
un1t, 2016-07-29
@un1t

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.

T
TheML9I, 2016-07-30
@khaletskiy

Mokai managers (Video, Arsenal).
In tests, you can check for ok, which will return 200, the second for 404

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question