-
Notifications
You must be signed in to change notification settings - Fork 445
Allow httphandler to have auth and other mediatype #811
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
base: main
Are you sure you want to change the base?
Changes from all commits
bb8643a
022aefe
df525ba
3f3e243
9a28376
20d7586
630b373
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -320,6 +320,38 @@ def test_read(self): | |
| self.assertEqual(HttpHandler.read(path), text) | ||
| mock_get.assert_called_once_with(path, headers={'Accept': 'application/json'}) | ||
|
|
||
| def test_read_with_auth(self): | ||
| """ | ||
| Tests that the `read` function performs a request to the giving path | ||
|
||
| with authentication from the environment variables and returns the response. | ||
| """ | ||
| path = 'http://example.com' | ||
| text = 'request test response' | ||
| auth = 'Basic dW5hbWU6cGFzc3dvcmQK' | ||
|
|
||
| with patch.dict(os.environ, clear=True) as env, patch('papermill.iorw.requests.get') as mock_get: | ||
| env['PAPERMILL_HTTP_AUTH_HEADER'] = auth | ||
| mock_get.return_value = Mock(text=text) | ||
|
|
||
| self.assertEqual(HttpHandler.read(path), text) | ||
| mock_get.assert_called_once_with(path, headers={'Accept': 'application/json', 'Authorization': auth}) | ||
|
|
||
| def test_read_with_accept_header(self): | ||
| """ | ||
| Tests that the `read` function performs a request to the giving path | ||
|
||
| with an accept type from env variables and returns the response. | ||
| """ | ||
| path = 'http://example.com' | ||
| text = 'request test response' | ||
| accept_type = 'test accept type' | ||
|
|
||
| with patch.dict(os.environ, clear=True) as env, patch('papermill.iorw.requests.get') as mock_get: | ||
| env['PAPERMILL_HTTP_ACCEPT_HEADER'] = accept_type | ||
| mock_get.return_value = Mock(text=text) | ||
|
|
||
| self.assertEqual(HttpHandler.read(path), text) | ||
| mock_get.assert_called_once_with(path, headers={'Accept': accept_type}) | ||
|
|
||
| def test_write(self): | ||
| """ | ||
| Tests that the `write` function performs a put request to the given | ||
|
|
@@ -332,6 +364,21 @@ def test_write(self): | |
| HttpHandler.write(buf, path) | ||
| mock_put.assert_called_once_with(path, json=json.loads(buf)) | ||
|
|
||
| def test_write_with_auth(self): | ||
| """ | ||
| Tests that the `write` function performs a put request to the given | ||
| path with authentication from env variables. | ||
| """ | ||
| path = 'http://example.com' | ||
| buf = '{"papermill": true}' | ||
| auth = 'token' | ||
|
|
||
| with patch.dict(os.environ, clear=True) as env, patch('papermill.iorw.requests.put') as mock_put: | ||
| env['PAPERMILL_HTTP_AUTH_HEADER'] = auth | ||
|
|
||
| HttpHandler.write(buf, path) | ||
| mock_put.assert_called_once_with(path, json=json.loads(buf), headers={'Authorization': auth}) | ||
|
|
||
| def test_write_failure(self): | ||
| """ | ||
| Tests that the `write` function raises on failure to put the buffer. | ||
|
|
||
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 docstring is missing proper formatting. It should specify that this is a colon (
:) after "value" or include it as part of the example. The current text reads "A valid example value Basic..." but should be "A valid example value: Basic..." or structured using proper docstring format with a Parameters or Example section.