Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/api dataset load args #1445

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions kedro/extras/datasets/api/api_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def __init__(
auth: Union[Iterable[str], AuthBase] = None,
json: Union[List, Dict[str, Any]] = None,
timeout: int = 60,
load_args: Dict[str, Any] = None,
credentials: Union[Iterable[str], AuthBase] = None,
) -> None:
"""Creates a new instance of ``APIDataSet`` to fetch data from an API endpoint.
Expand All @@ -65,6 +66,8 @@ def __init__(
https://requests.readthedocs.io/en/master/user/quickstart/#more-complicated-post-requests
timeout: The wait time in seconds for a response, defaults to 1 minute.
https://requests.readthedocs.io/en/master/user/quickstart/#timeouts
load_args: Additional parameters to be fed to requests.request.
https://docs.python-requests.org/en/latest/api/
credentials: same as ``auth``. Allows specifying ``auth`` secrets in
credentials.yml.

Expand All @@ -90,6 +93,7 @@ def __init__(
"auth": auth,
"json": json,
"timeout": timeout,
**load_args
}

def _describe(self) -> Dict[str, Any]:
Expand Down
5 changes: 4 additions & 1 deletion tests/extras/datasets/api/test_api_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

TEST_HEADERS = {"key": "value"}

TEST_LOAD_ARGS = {"allow_redirects": False}


@pytest.mark.parametrize("method", POSSIBLE_METHODS)
class TestAPIDataSet:
Expand All @@ -30,13 +32,14 @@ def requests_mocker(self):

def test_successfully_load_with_response(self, requests_mocker, method):
api_data_set = APIDataSet(
url=TEST_URL, method=method, params=TEST_PARAMS, headers=TEST_HEADERS
url=TEST_URL, method=method, params=TEST_PARAMS, headers=TEST_HEADERS, load_args=TEST_LOAD_ARGS
)
requests_mocker.register_uri(
method,
TEST_URL_WITH_PARAMS,
headers=TEST_HEADERS,
text=TEST_TEXT_RESPONSE_DATA,
**TEST_LOAD_ARGS,
)

response = api_data_set.load()
Expand Down