def test_can_fetch(self): otto = TornadoOctopus(cache=False, auto_start=True) otto.response_cache.put('http://www.google.com', Mock()) http_client_mock = Mock() otto.http_client = http_client_mock otto.fetch('http://www.google.com', None, 'GET') expect(otto.running_urls).to_equal(1) expect(http_client_mock.fetch.called).to_be_true()
def test_fetch_gets_the_response_from_cache_if_available(self): otto = TornadoOctopus(cache=True, auto_start=True) response_mock = Mock() otto.response_cache.put('http://www.google.com', response_mock) http_client_mock = Mock() otto.http_client = http_client_mock callback = Mock() otto.fetch('http://www.google.com', callback, 'GET') expect(otto.running_urls).to_equal(0) expect(http_client_mock.fetch.called).to_be_false() callback.assert_called_once_with('http://www.google.com', response_mock)