def test_get_from_cache_retrieves_correctly():
    """
    Test ``get_from_cache``.

    Tests that :py:meth:`~.RallyAccessor.get_from_cache`:
        * returns the data at the specified cache location if present
        * returns False if not present
    """
    MEM_CACHE.clear()
    MEM_CACHE['cache_key']['cache_lookup'] = ('data', time.time())

    my_accessor = RallyAccessor('uname', 'pword', 'base_url')
    my_accessor.get_cacheable_info = Mock()
    my_accessor.cache_timeouts = Mock()
    my_accessor.cache_timeouts.get.return_value = 10

    for (key, index), expected_result in [
                                    (('cache_key', 'cache_lookup'), 'data'),
                                    (('another_key', 'another_lookup'), False),
                                    ]:
        my_accessor.get_cacheable_info.reset_mock()
        my_accessor.get_cacheable_info.return_value = (key, index)

        assert_equal(my_accessor.get_from_cache('url'), expected_result)

        assert_equal(my_accessor.get_cacheable_info.call_args[0], ('url',))
        assert_equal(my_accessor.cache_timeouts.get.call_args[0],
                           (key, my_accessor.default_cache_timeout))
Beispiel #2
0
def test_get_from_cache_retrieves_correctly():
    """
    Test ``get_from_cache``.

    Tests that :py:meth:`~.RallyAccessor.get_from_cache`:
        * returns the data at the specified cache location if present
        * returns False if not present
    """
    MEM_CACHE.clear()
    MEM_CACHE['cache_key']['cache_lookup'] = ('data', time.time())

    my_accessor = RallyAccessor('uname', 'pword', 'base_url')
    my_accessor.get_cacheable_info = Mock()
    my_accessor.cache_timeouts = Mock()
    my_accessor.cache_timeouts.get.return_value = 10

    for (key, index), expected_result in [
        (('cache_key', 'cache_lookup'), 'data'),
        (('another_key', 'another_lookup'), False),
    ]:
        my_accessor.get_cacheable_info.reset_mock()
        my_accessor.get_cacheable_info.return_value = (key, index)

        assert_equal(my_accessor.get_from_cache('url'), expected_result)

        assert_equal(my_accessor.get_cacheable_info.call_args[0], ('url', ))
        assert_equal(my_accessor.cache_timeouts.get.call_args[0],
                     (key, my_accessor.default_cache_timeout))
def test_get_from_cache_returns_false_if_out_of_date():
    """
    Test ``get_from_cache``.

    Tests that :py:meth:`~.RallyAccessor.get_from_cache`:
        * returns False if data is out of date
    """
    MEM_CACHE.clear()
    MEM_CACHE['cache_key']['cache_lookup'] = ('data', 0)

    my_accessor = RallyAccessor('uname', 'pword', 'base_url')
    my_accessor.get_cacheable_info = Mock()
    my_accessor.cache_timeouts = Mock()
    my_accessor.cache_timeouts.get.return_value = 0

    my_accessor.get_cacheable_info.return_value = ('cache_key', 'cache_lookup')

    assert_equal(my_accessor.get_from_cache('url'), False)
Beispiel #4
0
def test_get_from_cache_returns_false_if_out_of_date():
    """
    Test ``get_from_cache``.

    Tests that :py:meth:`~.RallyAccessor.get_from_cache`:
        * returns False if data is out of date
    """
    MEM_CACHE.clear()
    MEM_CACHE['cache_key']['cache_lookup'] = ('data', 0)

    my_accessor = RallyAccessor('uname', 'pword', 'base_url')
    my_accessor.get_cacheable_info = Mock()
    my_accessor.cache_timeouts = Mock()
    my_accessor.cache_timeouts.get.return_value = 0

    my_accessor.get_cacheable_info.return_value = ('cache_key', 'cache_lookup')

    assert_equal(my_accessor.get_from_cache('url'), False)