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'))
Exemple #2
0
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'))