Exemplo n.º 1
0
    def test_hooks(self):
        result = {}

        def hook(r, **kwargs):
            result[r.url] = True

        hooks = dict(response=[hook])
        reqs = [requests.get(url, hooks=hooks) for url in URLS]
        resp = list(requests.map(reqs, concurrency=N))
        self.assertEqual(sorted(result.keys()), sorted(URLS))
Exemplo n.º 2
0
 def get(self, url, **kwargs):
     return list(requests.map([requests.get(url, **kwargs)]))[0]
Exemplo n.º 3
0
 def test_concurrency_with_delayed_url(self):
     t = time.time()
     n = 10
     reqs = [requests.get(httpbin('delay/1')) for _ in range(n)]
     resp = list(requests.map(reqs, concurrency=n))
     self.assertLess((time.time() - t), n)
Exemplo n.º 4
0
 def test_stream_enabled(self):
     r = list(requests.map([requests.get(httpbin('stream/10'), stream=True)], concurrency=2))[0]
     self.assertFalse(r._content_consumed)
Exemplo n.º 5
0
 def test_calling_request(self):
     reqs = [requests.request('POST', httpbin('post'), data={'p': i})
             for i in range(N)]
     resp = requests.map(reqs, concurrency=N)
     self.assertEqual([int(r.json()['form']['p']) for r in resp], list(range(N)))
Exemplo n.º 6
0
 def test_map(self):
     reqs = [requests.get(url) for url in URLS]
     resp = requests.map(reqs, concurrency=N)
     self.assertEqual([r.url for r in resp], URLS)