Skip to content

Commit b0bb798

Browse files
Remove partial urls (#33)
1 parent b42737a commit b0bb798

5 files changed

Lines changed: 43 additions & 85 deletions

File tree

docs/user_guide/api_calls.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ For the complete overview of available API calls see `4Insight REST API`_.
99
1010
response = session.get("https://api.4insight.io/v1.1/Campaigns")
1111
12-
# or with relative url
13-
14-
response = session.get("/v1.1/Campaigns")
15-
16-
1712
Some API endpoints support OData and have paging, which returns a limited number of responses per page.
1813
For these endpoints, the ``get_pages`` method can be useful:
1914

docs/user_guide/logging.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ For instance, outputing the log to ``stdout`` can be done in the following manne
1818
logger.addHandler(handler)
1919
2020
session = UserSession()
21-
response = session.get("/v1.0/Campaigns")
21+
response = session.get("https://api.4insight.io/v1.1/Campaigns")
2222
2323
2424
If you require even more detailed logging, consider using loggers from

fourinsight/api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
logging.getLogger(__name__).addHandler(logging.NullHandler())
66

7-
__version__ = "0.0.3"
7+
__version__ = "0.0.1"

fourinsight/api/authenticate.py

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -184,32 +184,13 @@ def _prepare_refresh_token_args(self):
184184
@_request_logger
185185
def request(self, *args, **kwargs):
186186
"""
187-
Extend the ``requests_oauthlib.OAuth2Session.request`` method to
188-
allow relative urls and supply default arguments.
187+
Extend the ``requests_oauthlib.OAuth2Session.request`` method
188+
to supply default arguments.
189189
"""
190-
args, kwargs = self._update_args_kwargs(args, kwargs)
191-
response = super().request(*args, **kwargs)
192-
return response
193-
194-
def _update_args_kwargs(self, args, kwargs):
195-
"""
196-
Update args and kwargs before passing on to request.
197-
"""
198-
if not args:
199-
method = kwargs.pop("method")
200-
url = kwargs.pop("url")
201-
elif len(args) == 1:
202-
method = args[0]
203-
url = kwargs.pop("url")
204-
else:
205-
method, url = args[:2]
206-
207-
if not url.startswith("https://"):
208-
url = self._api_base_url + url
209-
210190
for key in self._defaults:
211191
kwargs.setdefault(key, self._defaults[key])
212-
return (method, url, *args[2:]), kwargs
192+
response = super().request(*args, **kwargs)
193+
return response
213194

214195
def get_pages(self, url, **kwargs):
215196
r"""

tests/test_authenticator.py

Lines changed: 37 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -425,77 +425,59 @@ class Test_BaseAuthSession:
425425
provided by BaseAuthSession.
426426
"""
427427

428-
def test_update_args_kwargs_error(self, mock_fetch, mock_refresh):
429-
auth = authenticate.ClientSession("my_client_id", "my_client_secret")
430-
431-
args = ()
432-
kwargs = {"something": 1}
433-
434-
with pytest.raises(KeyError):
435-
auth._update_args_kwargs(args, kwargs)
436-
437-
def test_update_args_kwargs_args_none(self, mock_fetch, mock_refresh):
428+
@patch("fourinsight.api.authenticate.OAuth2Session.request")
429+
def test_request_check_default(self, mock_request, mock_fetch, mock_refresh):
438430
auth = authenticate.ClientSession("my_client_id", "my_client_secret")
431+
args = ("https://api.4insight.io/v1.0/Campaigns",)
432+
kwargs = {
433+
"other": "thing",
434+
}
439435

440-
args = ()
441-
kwargs = {"method": "GET", "url": "/v1.0/ding/dong", "other": "thing"}
442-
443-
args_out, kwargs_out = auth._update_args_kwargs(args, kwargs)
436+
auth.get(*args, **kwargs)
444437

445-
assert (
446-
args
447-
+ (
448-
"GET",
449-
auth._api_base_url + "/v1.0/ding/dong",
450-
)
451-
== args_out
438+
mock_request.assert_called_with(
439+
"GET",
440+
"https://api.4insight.io/v1.0/Campaigns",
441+
other="thing",
442+
allow_redirects=True,
443+
timeout=auth._defaults["timeout"],
452444
)
453-
assert {"timeout": auth._defaults["timeout"], "other": "thing"} == kwargs_out
454-
455-
def test_update_args_kwargs_args_len_1(self, mock_fetch, mock_refresh):
456-
auth = authenticate.ClientSession("my_client_id", "my_client_secret")
457-
458-
args = ("get",)
459-
kwargs = {"url": "/v1.0/ding/dong", "other": "thing"}
460445

461-
args_out, kwargs_out = auth._update_args_kwargs(args, kwargs)
462-
463-
assert args + (auth._api_base_url + "/v1.0/ding/dong",) == args_out
464-
assert {"timeout": auth._defaults["timeout"], "other": "thing"} == kwargs_out
465-
466-
def test_update_args_kwargs_args(self, mock_fetch, mock_refresh):
467-
auth = authenticate.ClientSession("my_client_id", "my_client_secret")
468-
469-
args = ("get", "/v1.0/ding/dong")
470-
kwargs = {"other": "thing"}
471-
472-
args_out, kwargs_out = auth._update_args_kwargs(args, kwargs)
473-
474-
assert args[:1] + (auth._api_base_url + "/v1.0/ding/dong",) == args_out
475-
assert {"timeout": auth._defaults["timeout"], "other": "thing"} == kwargs_out
476-
477-
def test_update_args_kwargs_args_long(self, mock_fetch, mock_refresh):
446+
@patch("fourinsight.api.authenticate.OAuth2Session.request")
447+
def test_request_args(self, mock_request, mock_fetch, mock_refresh):
478448
auth = authenticate.ClientSession("my_client_id", "my_client_secret")
479-
480-
args = ("get", "/v1.0/ding/dong", "something")
449+
args = ("https://api.4insight.io/v1.0/Campaigns",)
481450
kwargs = {"other": "thing"}
482451

483-
args_out, kwargs_out = auth._update_args_kwargs(args, kwargs)
452+
auth.get(*args, **kwargs)
484453

485-
assert (
486-
args[:1] + (auth._api_base_url + "/v1.0/ding/dong",) + args[2:] == args_out
454+
mock_request.assert_called_with(
455+
"GET",
456+
"https://api.4insight.io/v1.0/Campaigns",
457+
other="thing",
458+
allow_redirects=True,
459+
**auth._defaults,
487460
)
488-
assert {"timeout": auth._defaults["timeout"], "other": "thing"} == kwargs_out
489461

490462
@patch("fourinsight.api.authenticate.OAuth2Session.request")
491-
def test_request_relative_path(self, mock_request, mock_fetch, mock_refresh):
463+
def test_request_args_none(self, mock_request, mock_fetch, mock_refresh):
492464
auth = authenticate.ClientSession("my_client_id", "my_client_secret")
493-
args = ("/v1.0/ding/dong",)
465+
args = ()
466+
kwargs = {
467+
"url": "https://api.4insight.io/v1.0/Campaigns",
468+
"other": "thing",
469+
"another": "one",
470+
}
494471

495-
auth.get(*args)
472+
auth.get(*args, **kwargs)
496473

497474
mock_request.assert_called_with(
498-
"GET", auth._api_base_url + args[0], allow_redirects=True, **auth._defaults
475+
"GET",
476+
"https://api.4insight.io/v1.0/Campaigns",
477+
other="thing",
478+
another="one",
479+
allow_redirects=True,
480+
**auth._defaults,
499481
)
500482

501483
@patch("fourinsight.api.authenticate.OAuth2Session.request")

0 commit comments

Comments
 (0)