def test_cache_get_should_return_value(): os.mkdir(CACHE_DIR) with open(CACHE_FILE_PATH, 'w') as fout: data = fixture_cache_data() payload = yaml.dump(data, default_flow_style=False) fout.write(payload) cache = utils.Cache(CACHE_FILE_PATH) assert cache.get('mykey') == 'myvalue'
def test_cache_get_should_return_none_if_entry_is_expired(): os.mkdir(CACHE_DIR) with open(CACHE_FILE_PATH, 'w') as fout: data = fixture_cache_data() data['mykey']['expires'] -= timedelta(seconds=120) payload = yaml.dump(data, default_flow_style=False) fout.write(payload) cache = utils.Cache(CACHE_FILE_PATH) assert cache.get('mykey') is None
def test_cache_set_should_work_with_existing_cache_file(): cache = utils.Cache(CACHE_FILE_PATH) with open(CACHE_FILE_PATH, 'w') as fout: data = fixture_cache_data() payload = yaml.dump(data, default_flow_style=False) fout.write(payload) cache.set('mykey2', False) with open(CACHE_FILE_PATH) as fin: data = yaml.load(fin.read()) assert data['mykey2']['value'] is False
def test_cache_set_should_make_entry_in_cache_file(): cache = utils.Cache(CACHE_FILE_PATH) cache.set('mykey', True) with open(CACHE_FILE_PATH) as fin: data = yaml.load(fin.read()) assert data['mykey']['value'] is True
def test_cache_set_should_make_cache_file(): cache = utils.Cache(CACHE_FILE_PATH) cache.set('mykey', True) assert os.path.isfile(CACHE_FILE_PATH)
def test_cache_get_should_return_none_with_no_cache_file(): cache = utils.Cache(CACHE_FILE_PATH) assert cache.get('mykey') is None
def test_cache_init_should_make_parent_dir(): cache = utils.Cache(CACHE_FILE_PATH) assert os.path.isdir(CACHE_DIR) is True