1

I need to do the following test:

  • send a GET request to a server (http://remote/...)
  • wait for the server to send a POST request in response (http://local/...)
  • parse the POST data and do some assertions

Selenium does not fit this case: it can't listen to connections, and I can send a GET without Selenium as well.

so, I make a unit test:

class MobiMoneyTestCase(TestCase):
def test_can_send_response(self):
    resp = requests.post('http://url/api/', data={'callback': 'http://localhost:8000'})

    class Handler(SimpleHTTPRequestHandler):
        def do_GET(self):
            assert self.path == '...'

    httpd = SocketServer.ThreadingTCPServer(('localhost', 8000),Handler)

The test has to wait 5 seconds for the POST request and then fail if nothing happened. How can I merge these items in the test? If I put sleep(5) in the test_can..., the httpd handler does not reply until the countdown ends.

culebrón
  • 28,179
  • 18
  • 66
  • 97

1 Answers1

-1

Basically you want to timeout a process if it's too long ? You should check out the signal module in that case.

There is an neat implementation (with decorator) here : Timeout function if it takes too long to finish

Community
  • 1
  • 1
lucasg
  • 9,892
  • 4
  • 31
  • 52