-
Notifications
You must be signed in to change notification settings - Fork 144
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
Support customized HTTP Request Headers #337
Merged
justinabrokwah-okta
merged 3 commits into
master
from
jabro-okta-525379-fix-request-headers
Feb 1, 2023
Merged
Changes from 2 commits
Commits
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
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -17,4 +17,7 @@ __pycache__/ | |
|
||
# JS files | ||
*/node_modules/ | ||
*package-lock.json | ||
*package-lock.json | ||
|
||
# Build files | ||
build/ |
This file contains 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 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import aiohttp | ||
import asyncio | ||
import datetime | ||
import pytest | ||
import time | ||
|
||
from http import HTTPStatus | ||
|
@@ -29,11 +30,13 @@ class MockHTTPRequest(): | |
|
||
def __call__(self, **params): | ||
self.request_info = params | ||
self.headers = MultiDict({'Date': datetime.datetime.now(tz=datetime.timezone.utc).strftime('%a, %d %b %Y %H:%M:%S %Z'), | ||
'Content-Type': 'application/json', | ||
'X-Rate-Limit-Limit': 600, | ||
'X-Rate-Limit-Remaining': 599, | ||
'X-Rate-Limit-Reset': str(time.time())}) | ||
self.headers = MultiDict( | ||
{'Date': datetime.datetime.now(tz=datetime.timezone.utc).strftime('%a, %d %b %Y %H:%M:%S %Z'), | ||
'Content-Type': 'application/json', | ||
'X-Rate-Limit-Limit': 600, | ||
'X-Rate-Limit-Remaining': 599, | ||
'X-Rate-Limit-Reset': str(time.time())} | ||
) | ||
self.url = params['url'] | ||
self.content_type = 'application/json' | ||
self.links = '' | ||
|
@@ -95,17 +98,46 @@ def test_clear_empty_params(): | |
body = {'int_value': 0, | ||
'str_value': '0', | ||
'empty_str_value': '', | ||
'list_value': [1,2,3], | ||
'list_value': [1, 2, 3], | ||
'empty_list_value': [], | ||
'dict_value': {'int_value': 0}, | ||
'empty_dict_value': {}, | ||
'nested_empty_dict_value': {'list_value': [1,2,3], 'empty_list_value': []}, | ||
'nested_empty_dict_value': {'list_value': [1, 2, 3], 'empty_list_value': []}, | ||
'nested_empty_list_value': {'empty_list_value': []}} | ||
|
||
cleared_body = {'int_value': 0, | ||
'str_value': '0', | ||
'list_value': [1,2,3], | ||
'list_value': [1, 2, 3], | ||
'dict_value': {'int_value': 0}, | ||
'nested_empty_dict_value': {'list_value': [1,2,3]}} | ||
'nested_empty_dict_value': {'list_value': [1, 2, 3]}} | ||
|
||
assert req_exec.clear_empty_params(body) == cleared_body | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"accept_header", | ||
["", "application/xml", "application/json", | ||
"text/html", "application/xhtml+xml", "image/jpeg"] | ||
) | ||
@pytest.mark.asyncio | ||
async def test_overwrite_default_request_executor_headers(accept_header): | ||
Comment on lines
+117
to
+123
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Parametrized test added to test out various Accept headers |
||
org_url = "https://test.okta.com" | ||
token = "TOKEN" | ||
config = {'client': {'orgUrl': org_url, | ||
'token': token, | ||
'rateLimit': {}, | ||
'authorizationMode': None}} | ||
req_exec = RequestExecutor(config=config, cache=None) | ||
|
||
# overwrite headers if parameter present | ||
header_overwrite = {'Accept': accept_header} if accept_header else {} | ||
request, error = await req_exec.create_request( | ||
'GET', | ||
f'{org_url}/api/v1/users', | ||
{}, | ||
header_overwrite, | ||
{} | ||
) | ||
assert request is not None | ||
assert request["headers"]["Accept"] ==\ | ||
accept_header if accept_header else "application/json" |
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.
The **syntax destructures the dictionaries and prioritizes entries in the
headers
parameter set by the user