def test_replay_disabled(): cache = RequestCache( Extensions(), Config( record_file='tests/res/tape_read.json', replay=False, )) assert len(cache.cache) == 2 assert not cache.has_cached_response(request1)
def test_clear_cache_but_disabled(): cache = RequestCache( Extensions(), Config( record_file='tests/res/tape_read.json', replay_clear_cache=False, replay_clear_cache_seconds=10, verbose=2, )) assert len(cache.cache) == 2 cache.clear_old() assert len(cache.cache) == 2
def override_config(config: Config): """Overrides default parameters in config.""" # config.listen_port = 8080 # config.listen_ssl = True # config.dst_url = 'http://127.0.0.1:8000' # config.record = False # config.record_file = 'tape.json' # config.replay = False # config.replay_throttle = False # config.replay_clear_cache = False # config.replay_clear_cache_seconds = 60 # config.allow_chunking = True # config.proxy_timeout = 10 config.verbose = 0
def test_save_new(): Path('tests/res/tape_save.json').unlink() cache = RequestCache( Extensions(), Config( record_file='tests/res/tape_save.json', record=True, verbose=1, )) assert len(cache.cache) == 0 assert cache.saving_enabled(request1, response1) cache.save_response(request1, response1) assert cache.saving_enabled(request2, response2) cache.save_response(request2, response2) saved = Path('tests/res/tape_save.json').read_text() expected = Path('tests/res/tape_read.json').read_text() assert saved == expected
def test_loading_cache(): cache = RequestCache( Extensions(), Config( record_file='tests/res/tape_read.json', replay=True, )) assert len(cache.cache) == 2 assert cache.has_cached_response(request1) assert cache.has_cached_response(request2) assert cache.replay_response(request1) == response1 assert cache.replay_response(request2) == response2 request_no = HttpRequest(method='GET', path='/', content=b'', headers={}, requestline='', client_addr='', client_port=0, timestamp=0) assert not cache.has_cached_response(request_no)
def test_read_from_non_existing(): cache = RequestCache( Extensions(), Config(record_file='tests/res/tape_not_existing.json', )) assert len(cache.cache) == 0
def test_read_from_empty(): cache = RequestCache(Extensions(), Config(record_file='tests/res/tape_empty.json', )) assert len(cache.cache) == 0