def test_get_next_for_response_with_a_next_link_stops_iterating_after_first_call(self, mock_client_get): """ Assert that call to get_next with a response that has a 'next' links stops iteration on second iteration """ initial_response = self.build_response_mock({'next': {'url': 'http://next/url/1'}}) second_response = self.build_response_mock() mock_client_get.return_value = second_response result = next(utils.get_next(self.req_ctx, initial_response)) with self.assertRaises(StopIteration): next(utils.get_next(self.req_ctx, result))
def test_get_next_for_response_without_a_next_link_yields_nothing(self, mock_client_get): """ Assert that call to get_next with a response that doesn't have any 'next' links doesn't iterate. """ initial_response = self.build_response_mock() with self.assertRaises(StopIteration): next(utils.get_next(self.req_ctx, initial_response)) self.assertTrue(not mock_client_get.called)
def test_get_next_for_response_with_a_next_link_calls_client_get_with_request_context(self, mock_client_get): """ Assert that call to get_next with a response that has 'next' links (in this case one additional page) calls the client "get" method with the request context. """ initial_response = self.build_response_mock({'next': {'url': 'http://next-url'}}) next(utils.get_next(self.req_ctx, initial_response)) mock_client_get.assert_called_once_with(self.req_ctx, mock.ANY)
def test_get_next_for_response_with_a_next_link_calls_client_get_with_url(self, mock_client_get): """ Assert that call to get_next with a response that has 'next' links (in this case one additional page) calls the client "get" method with the next url. """ next_url = "http://next-url" initial_response = self.build_response_mock({"next": {"url": next_url}}) next(utils.get_next(self.req_ctx, initial_response)) mock_client_get.assert_called_once_with(mock.ANY, next_url)
def test_get_next_for_response_with_a_next_link_returns_next_response(self, mock_client_get): """ Assert that call to get_next with a response that has a 'next' links returns the next response on first yield. """ initial_response = self.build_response_mock({"next": {"url": "http://next/url/1"}}) second_response = self.build_response_mock() mock_client_get.return_value = second_response result = next(utils.get_next(self.req_ctx, initial_response)) self.assertEqual(result, second_response, "Result of get_next should be return value of client.get")
def test_get_next_for_response_with_a_next_link_returns_next_response(self, mock_client_get): """ Assert that call to get_next with a response that has a 'next' links returns the next response on first yield. """ initial_response = self.build_response_mock({'next': {'url': 'http://next/url/1'}}) second_response = self.build_response_mock() mock_client_get.return_value = second_response result = next(utils.get_next(self.req_ctx, initial_response)) self.assertEqual( result, second_response, "Result of get_next should be return value of client.get")