Задать вопрос

Тел: +7 965 3737 888

637

Просмотров

0

Ответов

Monkey-patch Django's test client to return WSGIRequest objects

<p>Testing low-level functionality sometimes requires a WSGIRequest object.  An example of this is testing template tags.
</p>
<p>This will monkey-patch the test Client object to return WSGIRequest objects
</p>
<p>Normal Django behavior:
</p>
&gt;&gt;&gt; client.get('/')
&lt;HttpResponse &gt;
<p>With this code, get the request object:
</p>
&gt;&gt;&gt; client.request_from.get('/')
&lt;WSGIRequest &gt;
<p>Installation:
</p>
<p>For this to work, you simply need to import the contents of this file.
</p>
<p>If you name this file clientrequestpatch.py, do this inside your Django tests.
</p>
from django.test.testcases import TestCase
from myproject.test import clientrequestpatch

Вопрос полезен? Да0/Нет0
file_5112.py(5.4Кб)
None