#27112: django.test.client.Client doesn't support timeouts
-----------------------------------+--------------------------------------
     Reporter:  roboslone          |                    Owner:  nobody
         Type:  New feature        |                   Status:  closed
    Component:  Testing framework  |                  Version:  1.10
     Severity:  Normal             |               Resolution:  wontfix
     Keywords:  testing,timeout    |             Triage Stage:  Unreviewed
    Has patch:  0                  |      Needs documentation:  0
  Needs tests:  0                  |  Patch needs improvement:  0
Easy pickings:  0                  |                    UI/UX:  0
-----------------------------------+--------------------------------------

Comment (by roboslone):

 To anyone with similar use case, I was able to test client timeouts with
 modified {{{LiveServerTestCase}}}. Discussion can be found in this thread:
 https://groups.google.com/forum/#!topic/django-developers/PofmsTQ-YGs

 {{{tl;dr}}}
 Use following code to define {{{ThreadedLiveServerTestCase}}}:
 {{{#!python
 from django.test.testcases import LiveServerThread,
 QuietWSGIRequestHandler
 from django.core.servers.basehttp import WSGIServer
 from socketserver import ThreadingMixIn

 class ThreadedWSGIServer(ThreadingMixIn, WSGIServer):
     pass


 class ThreadedLiveServerThread(LiveServerThread):
     def _create_server(self, port):
         return ThreadedWSGIServer((self.host, port),
 QuietWSGIRequestHandler)


 class ThreadedLiveServerTestCase(LiveServerTestCase):
     @classmethod
     def _create_server_thread(cls, host, possible_ports,
 connections_override):
         return ThreadedLiveServerThread(
             host,
             possible_ports,
             cls.static_handler,
             connections_override=connections_override,
         )
 }}}
 And use {{{requests}}} to query backends:
 {{{#!python
 import requests
 from requests.exceptions import Timeout

 ...

 with self.assertRaises(Timeout):
     requests.get(self.live_server_url + '/something', timeout=1.0)
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27112#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.1c007e3a8aebc7b9d554dc949e926e10%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to