Skip to content

Commit

Permalink
use similar tests to python requests
Browse files Browse the repository at this point in the history
  • Loading branch information
s-block committed Dec 2, 2014
1 parent 34c171c commit 6537136
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions tests/resource.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import sys
import mock
import requests
import slumber
import slumber.serialize
import unittest2 as unittest
import SimpleHTTPServer
import SocketServer
import threading

from slumber import exceptions

Expand Down Expand Up @@ -367,20 +365,18 @@ def test_api(self):
def test_url(self):
self.assertEqual(self.base_resource.url(), "http://example/api/v1/test")

def test_timeout(self):
handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = TestTCPServer(("", 8001), handler)
httpd_thread = threading.Thread(target=httpd.serve_forever)
httpd_thread.setDaemon(True)
httpd_thread.start()
def test_connect_timeout(self):

client = slumber.API(base_url="http://localhost:8001", timeout=(0.000000000000001, 0.000000000000001))
client = slumber.API(base_url='http://httpbin.org/delay/10', timeout=(0.00000000001, None))

with self.assertRaises(requests.exceptions.ConnectTimeout):
client.test.get()
assert False, "The connect() request should time out."

httpd.shutdown()
def test_read_timeout(self):

client = slumber.API(base_url='http://httpbin.org/delay/10', timeout=(None, 0.01))

class TestTCPServer(SocketServer.TCPServer):
allow_reuse_address = True
with self.assertRaises(requests.exceptions.ReadTimeout):
client.test.get()
assert False, "The recv() request should time out."

0 comments on commit 6537136

Please sign in to comment.