Beispiel #1
0
def test_remove_api_key():
    key = qs.rand_str()
    val = qs.rand_str()
    api_keys.set(key, val)
    assert_in(key, api_keys._get_db())
    api_keys.remove(key)
    assert_not_in(key, api_keys._get_db())
Beispiel #2
0
def test_api_key_path_order():
    key_path = ['1', '2', '3']
    val = qs.rand_str()
    api_keys.set(key_path, val)
    assert_equals(api_keys.get(key_path), val)
    with assert_raises(KeyError):
        api_keys.get(['2', '1', '3'])
Beispiel #3
0
def test_rest_cache_class():
    cache = qs.RestCache()
    some_string = qs.rand_str()

    cache.add(some_string)
    assert_equals(cache.get(), some_string)

    cache.invalidate()
    assert_is_none(cache.get())
Beispiel #4
0
def test_rand_str_randomness():
    assert_not_equal(qs.rand_str(), qs.rand_str())
Beispiel #5
0
def test_rand_str_chars():
    filtered = [i for i in qs.rand_str() if i.isalnum()]
    assert_equals(len(filtered), len(qs.rand_str()))
Beispiel #6
0
def test_rand_str_length():
    length = random.randint(5, 10)
    rand_str = qs.rand_str(length)
    assert_equals(len(rand_str), length)
Beispiel #7
0
def test_api_key_with_str_key():
    key = qs.rand_str()
    val = qs.rand_str()
    api_keys.set(key, val)
    assert_equals(api_keys.get(key), val)
Beispiel #8
0
def test_api_key_with_key_path():
    key_path = [qs.rand_str(), qs.rand_str(), qs.rand_str()]
    val = qs.rand_str()
    api_keys.set(key_path, val)
    assert_equals(api_keys.get(key_path), val)
Beispiel #9
0
def test_set_api_key():
    key = qs.rand_str()
    val = qs.rand_str()
    api_keys.set(key, val)
    with open(api_keys._get_path()) as f:
        assert_equals(json.load(f)[key], val)
Beispiel #10
0
def test_get_api_key_with_bad_key():
    with assert_raises(KeyError):
        api_keys.get(qs.rand_str())
Beispiel #11
0
def test_remove_nonexistent_key():
    with assert_raises(KeyError):
        api_keys.remove(qs.rand_str())