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_get_cacheable_info(): """ Test ``get_cacheable_info``. Tests that :py:meth:`~.RallyAccessor.get_cacheable_info`: * returns the right cache key and index """ my_accessor = RallyAccessor('uname', 'pword', 'base_url') my_accessor.api_url = 'http://dummy_url/' for url, expected_tuple in [ ('obj.js?query=something', ('obj_query', 'query=something')), ('obj/303923.js', ('obj', '303923')), ]: full_url = "{0}{1}".format(my_accessor.api_url, url) assert_equal(my_accessor.get_cacheable_info(full_url), expected_tuple)