Ejemplo n.º 1
0
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'
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
def test_cache_get_should_return_none_with_no_cache_file():
    cache = utils.Cache(CACHE_FILE_PATH)
    assert cache.get('mykey') is None
Ejemplo n.º 7
0
def test_cache_init_should_make_parent_dir():
    cache = utils.Cache(CACHE_FILE_PATH)
    assert os.path.isdir(CACHE_DIR) is True