Skip to content

Commit

Permalink
implements using the session argument. Adds integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
willi-mueller committed Sep 19, 2024
1 parent 79ceca5 commit c89c33c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions dlt/sources/rest_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def create_resources(
headers=client_config.get("headers"),
auth=create_auth(client_config.get("auth")),
paginator=create_paginator(client_config.get("paginator")),
session=client_config.get("session")
)

hooks = create_response_hooks(endpoint_config.get("response_actions"))
Expand Down
33 changes: 32 additions & 1 deletion tests/sources/rest_api/integration/test_offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from unittest import mock

import pytest
from requests import Request, Response
from requests import Request, Response, Session

import dlt
from dlt.common import pendulum
Expand Down Expand Up @@ -327,3 +327,34 @@ def test_posts_with_inremental_date_conversion(mock_api_server) -> None:
_, called_kwargs = mock_paginate.call_args_list[0]
assert called_kwargs["params"] == {"since": "1970-01-01", "until": "1970-01-02"}
assert called_kwargs["path"] == "posts"


def test_multiple_response_actions_on_every_response(mock_api_server, mocker):
class CustomSession(Session):
pass

def send_spy(*args, **kwargs):
return original_send(*args, **kwargs)

my_session = CustomSession()
original_send = my_session.send
mocked_send = mocker.patch.object(my_session, "send", side_effect=send_spy)

source = rest_api_source(
{
"client": {
"base_url": "https://api.example.com",
"session": my_session,
},
"resources": [
{
"name": "posts",
},
],
}
)

list(source.with_resources("posts").add_limit(1))

mocked_send.assert_called_once()
assert mocked_send.call_args[0][0].url == 'https://api.example.com/posts'

0 comments on commit c89c33c

Please sign in to comment.