def test_redirects(): d = rq.get('http://httpbin.org/redirect/2') @d.addCallback def ok(response): assert len(response.redirects)==2 return d
def test_not_found(): d = rq.get('http://httpbin.org/status/404') @d.addCallback def ok(response): assert response.code==404 return d
def test_permanent_redirect(): url = 'http://httpbin.org/status/301' assert url not in rq._permanent_redirects d = rq.get(url) @d.addCallback def ok(response): assert url in rq._permanent_redirects del rq._permanent_redirects[url] return d
def test_get(): d = rq.get('http://httpbin.org/get?test=passed') @d.addCallback def ok(response): assert response.code==200 assert response.headers['Content-Type']== ['application/json'] body = json.loads(response.body) assert body['args']['test']=='passed' return d
def test_cache(): url = 'http://httpbin.org/cache' assert url not in rq._cache d = rq.get(url) @d.addCallback def ok(response): assert 'Last-Modified' in response.headers assert url in rq._cache assert rq._cache[url][0] == response.headers['Last-Modified'][0] assert rq._cache[url][1] == response.body del rq._cache[url] return d
def test_from_cache(): url = 'http://httpbin.org/cache' assert url not in rq._cache d = rq.get(url) @d.addCallback def ok(response): original_body = response.body deferLater(reactor, 2, rq.get, url).addCallback(ok2, original_body) def ok2(response, original_body): assert response.code == 304 assert response.body == original_body del rq._cache[url] return d
def test_invalid_url(): return rq.get('a')
def test_dns_handle(): return rq.get('http://httpbinsss.org/get?test=passed')