-
Notifications
You must be signed in to change notification settings - Fork 90
add AuthorizedSession #22
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
Open
runawaycoast
wants to merge
8
commits into
main
Choose a base branch
from
auth-session-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7fb9f10
add AuthorizedSession support
runawaycoast 784a11f
add test for api_config
runawaycoast bfaa3b0
fix session object not getting through
runawaycoast b7dca2b
clean request payload
runawaycoast 01e4a11
fix get api_config before params assignment
runawaycoast 1a990da
add test and fix lint
runawaycoast 78cacae
add strip function to remove property in option
runawaycoast e87eee2
fix lint, add doc for AuthorizedSession
runawaycoast File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
add test and fix lint
- Loading branch information
commit 1a990da91aca7aa89ecb72da114367cbf67ae33f
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| NotFoundError, ServiceUnavailableError) | ||
| from test.test_retries import ModifyRetrySettingsTestCase | ||
| from test.helpers.httpretty_extension import httpretty | ||
| import requests | ||
| import json | ||
| from mock import patch, call | ||
| from nasdaqdatalink.version import VERSION | ||
|
|
@@ -59,8 +60,8 @@ def test_non_data_link_error(self, request_method): | |
| httpretty.register_uri(getattr(httpretty, request_method), | ||
| "https://data.nasdaq.com/api/v3/databases", | ||
| body=json.dumps( | ||
| {'foobar': | ||
| {'code': 'blah', 'message': 'something went wrong'}}), status=500) | ||
| {'foobar': | ||
|
||
| {'code': 'blah', 'message': 'something went wrong'}}), status=500) | ||
| self.assertRaises( | ||
| DataLinkError, lambda: Connection.request(request_method, 'databases')) | ||
|
|
||
|
|
@@ -81,3 +82,48 @@ def test_build_request(self, request_method, mock): | |
| 'request-source-version': VERSION}, | ||
| params={'per_page': 10, 'page': 2}) | ||
| self.assertEqual(mock.call_args, expected) | ||
|
|
||
| @parameterized.expand(['GET', 'POST']) | ||
| @patch('nasdaqdatalink.connection.Connection.execute_request') | ||
| def test_build_request_with_custom_api_config(self, request_method, mock): | ||
| ApiConfig.api_key = 'api_token' | ||
| ApiConfig.api_version = '2015-04-09' | ||
| api_config = ApiConfig() | ||
| api_config.api_key = 'custom_api_token' | ||
| api_config.api_version = '2022-06-09' | ||
| session = requests.session() | ||
| params = {'per_page': 10, 'page': 2, 'api_config': api_config, 'session': session} | ||
| headers = {'x-custom-header': 'header value'} | ||
| Connection.request(request_method, 'databases', headers=headers, params=params) | ||
| expected = call(request_method, 'https://data.nasdaq.com/api/v3/databases', | ||
| headers={'x-custom-header': 'header value', | ||
| 'x-api-token': 'custom_api_token', | ||
| 'accept': ('application/json, ' | ||
| 'application/vnd.data.nasdaq+json;version=2022-06-09'), | ||
| 'request-source': 'python', | ||
| 'request-source-version': VERSION}, | ||
| params={'per_page': 10, 'page': 2, | ||
| 'session': session, 'api_config': api_config}) | ||
| self.assertEqual(mock.call_args, expected) | ||
|
|
||
| def test_remove_session_and_api_config_param(self): | ||
| ApiConfig.api_key = 'api_token' | ||
| ApiConfig.api_version = '2015-04-09' | ||
| ApiConfig.verify_ssl = True | ||
| api_config = ApiConfig() | ||
| api_config.api_key = 'custom_api_token' | ||
| api_config.api_version = '2022-06-09' | ||
| api_config.verify_ssl = False | ||
| session = requests.Session() | ||
| params = {'per_page': 10, 'page': 2, 'api_config': api_config, 'session': session} | ||
| headers = {'x-custom-header': 'header value'} | ||
| dummy_response = requests.Response() | ||
| dummy_response.status_code = 200 | ||
| with patch.object(session, 'request', return_value=dummy_response) as mock: | ||
| Connection.execute_request( | ||
| 'GET', 'https://data.nasdaq.com/api/v3/databases', headers=headers, params=params) | ||
| mock.assert_called_once_with(method='GET', | ||
| url='https://data.nasdaq.com/api/v3/databases', | ||
| verify=False, | ||
| headers=headers, | ||
| params={'per_page': 10, 'page': 2}) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Outside of this tickets scope, but I would like to see us passing connection details (session, api_config) as explicit arguments, and leave kwargs to params we should send to the API call. This would allow us to avoid all the kwarg popping down the line