Exemple #1
0
 def test_delete_urls(self):
     url = 'http://httpbin.org/redirect/3'
     r = requests.get(url)
     for i in range(1, 4):
         self.assert_(requests_cache.has_url('http://httpbin.org/redirect/%s' % i))
     requests_cache.delete_url(url)
     self.assert_(not requests_cache.has_url(url))
 def test_delete_urls(self):
     url = httpbin('redirect/3')
     r = requests.get(url)
     for i in range(1, 4):
         self.assert_(requests_cache.has_url(httpbin('redirect/%s' % i)))
     requests_cache.delete_url(url)
     self.assert_(not requests_cache.has_url(url))
 def test_https_support(self):
     n = 10
     delay = 1
     url = 'https://httpbin.org/delay/%s?ar1=value1' % delay
     t = time.time()
     for _ in range(n):
         r = json.loads(requests.get(url, verify=False).text)
         self.assert_(requests_cache.has_url(url))
     self.assertLessEqual(time.time() - t, delay * n / 2)
Exemple #4
0
def search_track(q, page=1):
    q = term_conditioner(q)
    has_tracks = False
    if not _Q_CACHE.has_key(q):
        url = search_track_url(q, page)
        # decide if we need throttle depending on HTTP Cache vs API
        if not requests_cache.has_url(url):
            throttle()
        response = requests.get(url).json
        tracks = response['tracks']
        has_tracks = bool(tracks)
        for track in tracks:
            name = track['name'].lower()
            _Q_CACHE[name] = track
    exact_match = _Q_CACHE.get(q)
    return has_tracks, exact_match
        def do_tests_for(backend):
            requests_cache.configure(CACHE_NAME, backend)
            requests_cache.clear()
            n_threads = 10
            url = 'http://httpbin.org/get'
            def do_requests(url, params):
                for i in range(10):  # for testing write and read from cache
                    requests.get(url, params=params)

            for _ in range(20): # stress test
                threads = [Thread(target=do_requests, args=(url, {'param': i})) for i in range(n_threads)]
                for t in threads:
                    t.start()
                for t in threads:
                    t.join()

                for i in range(n_threads):
                    self.assert_(requests_cache.has_url('%s?param=%s' % (url, i)))
Exemple #6
0
 def test_post(self):
     url = 'http://httpbin.org/post'
     r1 = json.loads(requests.post(url, data={'test1': 'test1'}).text)
     r2 = json.loads(requests.post(url, data={'test2': 'test2'}).text)
     self.assertIn('test2', r2['form'])
     self.assert_(not requests_cache.has_url(url))
 def test_get_params_as_argument(self):
     for _ in range(5):
         p = {'arg1': 'value1'}
         r = json.loads(requests.get(httpbin('get'), params=p).text)
         self.assert_(requests_cache.has_url(httpbin('get?arg1=value1')))