diff --git a/okta/api_response.py b/okta/api_response.py index e441794ba..0d1c3d5c8 100644 --- a/okta/api_response.py +++ b/okta/api_response.py @@ -180,7 +180,7 @@ async def get_next(self): if next_request: # create new response and update generator values next_response = OktaAPIResponse( - self._request_executor, req, res_details, resp_body) + self._request_executor, req, res_details, resp_body, self._type) self._next = next_response._next # yield next page yield (next_response.get_body(), None, next_response) diff --git a/tests/unit/test_api_response.py b/tests/unit/test_api_response.py index 4b3e9c3df..73240e401 100644 --- a/tests/unit/test_api_response.py +++ b/tests/unit/test_api_response.py @@ -1,5 +1,6 @@ import tests.mocks as mocks import pytest +import okta.models as models from okta.client import Client from okta.request_executor import RequestExecutor @@ -44,6 +45,33 @@ async def test_response_pagination_with_next(monkeypatch): await result.next() +@ pytest.mark.asyncio +async def test_response_pagination_with_next_include_response(monkeypatch): + ssws_client = Client({ + "orgUrl": ORG_URL, + "token": API_TOKEN + }) + + req, error = await ssws_client.get_request_executor()\ + .create_request("GET", + GET_USERS_CALL + API_LIMIT, + {}, + {}) + + monkeypatch.setattr(RequestExecutor, 'fire_request', + mocks.mock_GET_HTTP_Client_response_valid_with_next) + + resp, error = await ssws_client.get_request_executor().execute(req, models.User) + assert resp._type is models.User + monkeypatch.setattr(RequestExecutor, 'fire_request', + mocks.mock_GET_HTTP_Client_response_valid) + # Check next response has same type as first response and check instance types + n_result, n_error, n_resp = await resp.next(includeResponse=True) + assert n_resp._type is resp._type + assert isinstance(n_result[0], resp._type) + assert error is None and n_error is None + + @ pytest.mark.asyncio async def test_response_pagination_with_next_not_starting_with_api(monkeypatch): ssws_client = Client(CLIENT_CONFIG)