def test_make_api_call_partial_url_not_cached(urllib2): """ Test ``make_api_call`` with partial url, not cached. Tests that :py:meth:`~.RallyAccessor.make_api_call`: * makes a call to the API via urllib. * prepends the api_url to the partial url. * makes the url given safe. * stores the new data in the cache. """ MEM_CACHE.clear() my_accessor = RallyAccessor('uname', 'pword', 'base_url') my_accessor.api_url = 'http://dummy_url/' my_accessor.get_from_cache = Mock() my_accessor.set_to_cache = Mock() my_accessor.make_url_safe = Mock() my_accessor._get_json_response = Mock() my_accessor.make_url_safe.return_value = 'safe-url' my_accessor.get_from_cache.return_value = False my_accessor._get_json_response.return_value = 'python_dict' response = my_accessor.make_api_call('some-url', full_url=True) assert_equal(response, 'python_dict') assert_equal(my_accessor.make_url_safe.call_args[0], ('some-url',)) assert_equal(my_accessor._get_json_response.call_args[0], (urllib2.Request.return_value,)) assert_equal(my_accessor.get_from_cache.call_args[0], ('safe-url',)) assert_equal(my_accessor.set_to_cache.call_args[0], ('safe-url', 'python_dict'))
def test_make_api_call_partial_url_not_cached(urllib2): """ Test ``make_api_call`` with partial url, not cached. Tests that :py:meth:`~.RallyAccessor.make_api_call`: * makes a call to the API via urllib. * prepends the api_url to the partial url. * makes the url given safe. * stores the new data in the cache. """ MEM_CACHE.clear() my_accessor = RallyAccessor('uname', 'pword', 'base_url') my_accessor.api_url = 'http://dummy_url/' my_accessor.get_from_cache = Mock() my_accessor.set_to_cache = Mock() my_accessor.make_url_safe = Mock() my_accessor._get_json_response = Mock() my_accessor.make_url_safe.return_value = 'safe-url' my_accessor.get_from_cache.return_value = False my_accessor._get_json_response.return_value = 'python_dict' response = my_accessor.make_api_call('some-url', full_url=True) assert_equal(response, 'python_dict') assert_equal(my_accessor.make_url_safe.call_args[0], ('some-url', )) assert_equal(my_accessor._get_json_response.call_args[0], (urllib2.Request.return_value, )) assert_equal(my_accessor.get_from_cache.call_args[0], ('safe-url', )) assert_equal(my_accessor.set_to_cache.call_args[0], ('safe-url', 'python_dict'))
def test_set_to_cache_adds_correctly(time_import): """ Test ``set_to_cache``. Tests that :py:meth:`~.RallyAccessor.set_to_cache`: * adds the given data to the cache. """ MEM_CACHE.clear() my_accessor = RallyAccessor('uname', 'pword', 'base_url') my_accessor.get_cacheable_info = Mock() my_accessor.get_cacheable_info.return_value = ('cache_key', 'cache_lookup') my_accessor.set_to_cache('url', 'set_to_cache_test') assert_equal(my_accessor.get_cacheable_info.call_args[0], ('url',)) assert_equal(MEM_CACHE, {'cache_key': {'cache_lookup': ('set_to_cache_test', time_import.time.return_value)}})
def test_set_to_cache_adds_correctly(time_import): """ Test ``set_to_cache``. Tests that :py:meth:`~.RallyAccessor.set_to_cache`: * adds the given data to the cache. """ MEM_CACHE.clear() my_accessor = RallyAccessor('uname', 'pword', 'base_url') my_accessor.get_cacheable_info = Mock() my_accessor.get_cacheable_info.return_value = ('cache_key', 'cache_lookup') my_accessor.set_to_cache('url', 'set_to_cache_test') assert_equal(my_accessor.get_cacheable_info.call_args[0], ('url', )) assert_equal( MEM_CACHE, { 'cache_key': { 'cache_lookup': ('set_to_cache_test', time_import.time.return_value) } })