-
-
Notifications
You must be signed in to change notification settings - Fork 160
100% Coverage 🥳 #168
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
Merged
Merged
100% Coverage 🥳 #168
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0e8ed9b
introduced tests for errors and 100% coverage
826f0ef
Merge branch 'ramnes:main' into main
mutt0-ds 1218ec3
fixed last tests to run even with token = None
7fe4f2c
fixed test case with valid URL but invalid token
cd94a96
fixed minor issues following code review (closed clients, removed unn…
94e4f59
simulated test timeout with monkeypatch
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 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[report] | ||
exclude_lines = | ||
pragma: no cover | ||
@abstract | ||
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
24 changes: 24 additions & 0 deletions
24
tests/cassettes/test_api_async_request_bad_request_error.yaml
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
interactions: | ||
- request: | ||
body: '' | ||
headers: | ||
accept: | ||
- '*/*' | ||
accept-encoding: | ||
- gzip, deflate | ||
authorization: | ||
- secret_... | ||
connection: | ||
- keep-alive | ||
host: | ||
- httpstat.us | ||
notion-version: | ||
- '2022-06-28' | ||
method: GET | ||
uri: https://httpstat.us/400 | ||
response: | ||
content: 400 Bad Request | ||
headers: {} | ||
http_version: HTTP/1.1 | ||
status_code: 400 | ||
version: 1 |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
interactions: | ||
- request: | ||
body: '' | ||
headers: | ||
accept: | ||
- '*/*' | ||
accept-encoding: | ||
- gzip, deflate | ||
authorization: | ||
- secret_... | ||
connection: | ||
- keep-alive | ||
host: | ||
- httpstat.us | ||
notion-version: | ||
- '2022-06-28' | ||
method: GET | ||
uri: https://httpstat.us/400 | ||
response: | ||
content: 400 Bad Request | ||
headers: {} | ||
http_version: HTTP/1.1 | ||
status_code: 400 | ||
version: 1 |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
interactions: | ||
- request: | ||
body: '' | ||
headers: | ||
accept: | ||
- '*/*' | ||
accept-encoding: | ||
- gzip, deflate | ||
connection: | ||
- keep-alive | ||
host: | ||
- api.notion.com | ||
notion-version: | ||
- '2022-06-28' | ||
method: GET | ||
uri: https://api.notion.com/v1/invalid | ||
response: | ||
content: '{"object":"error","status":400,"code":"invalid_request_url","message":"Invalid | ||
request URL."}' | ||
headers: {} | ||
http_version: HTTP/1.1 | ||
status_code: 400 | ||
- request: | ||
body: '' | ||
headers: | ||
accept: | ||
- '*/*' | ||
accept-encoding: | ||
- gzip, deflate | ||
authorization: | ||
- secret_... | ||
connection: | ||
- keep-alive | ||
host: | ||
- api.notion.com | ||
notion-version: | ||
- '2022-06-28' | ||
method: GET | ||
uri: https://api.notion.com/v1/users | ||
response: | ||
content: '{"object":"error","status":401,"code":"unauthorized","message":"API | ||
token is invalid."}' | ||
headers: {} | ||
http_version: HTTP/1.1 | ||
status_code: 401 | ||
version: 1 |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
interactions: | ||
- request: | ||
body: '' | ||
headers: | ||
accept: | ||
- '*/*' | ||
accept-encoding: | ||
- gzip, deflate | ||
connection: | ||
- keep-alive | ||
host: | ||
- api.notion.com | ||
notion-version: | ||
- '2022-06-28' | ||
method: GET | ||
uri: https://api.notion.com/v1/invalid | ||
response: | ||
content: '{"object":"error","status":400,"code":"invalid_request_url","message":"Invalid | ||
request URL."}' | ||
headers: {} | ||
http_version: HTTP/1.1 | ||
status_code: 400 | ||
- request: | ||
body: '' | ||
headers: | ||
accept: | ||
- '*/*' | ||
accept-encoding: | ||
- gzip, deflate | ||
authorization: | ||
- secret_... | ||
connection: | ||
- keep-alive | ||
host: | ||
- api.notion.com | ||
notion-version: | ||
- '2022-06-28' | ||
method: GET | ||
uri: https://api.notion.com/v1/users | ||
response: | ||
content: '{"object":"error","status":401,"code":"unauthorized","message":"API | ||
token is invalid."}' | ||
headers: {} | ||
http_version: HTTP/1.1 | ||
status_code: 401 | ||
version: 1 |
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 |
---|---|---|
|
@@ -40,8 +40,9 @@ interactions: | |
method: GET | ||
uri: https://api.notion.com/v1/users | ||
response: | ||
content: '{"object":"list","results":[{"object":"user","id":"a4f789cc-7bc8-4cf0-82b9-a8ba7d985ecf","name":"Guillaume | ||
Gelin","avatar_url":"https://s3-us-west-2.amazonaws.com/public.notion-static.com/1cddf30d-ef25-4372-a8bd-b510a11e26e8/avatar.jpeg","type":"person","person":{"email":"[email protected]"}},{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78","name":"notion-sdk-py","avatar_url":null,"type":"bot","bot":{"owner":{"type":"workspace","workspace":true}}}],"next_cursor":null,"has_more":false,"type":"user","user":{}}' | ||
content: '{"object":"list","results":[{"object":"user","id":"04db0808-966a-4668-9a27-8be05465b9c9","name":"Notion | ||
Testing Account","avatar_url":null,"type":"person","person":{}},{"object":"user","id":"823cf07b-34df-4ae6-9fbc-dbc600a815c6","name":"Testing","avatar_url":null,"type":"bot","bot":{"owner":{"type":"workspace","workspace":true},"workspace_name":"Notion | ||
Testing Account''s Notion"}}],"next_cursor":null,"has_more":false,"type":"user","user":{}}' | ||
headers: {} | ||
http_version: HTTP/1.1 | ||
status_code: 200 | ||
|
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,8 @@ interactions: | |
- '*/*' | ||
accept-encoding: | ||
- gzip, deflate | ||
authorization: | ||
- secret_... | ||
connection: | ||
- keep-alive | ||
host: | ||
|
@@ -38,8 +40,9 @@ interactions: | |
method: GET | ||
uri: https://api.notion.com/v1/users | ||
response: | ||
content: '{"object":"list","results":[{"object":"user","id":"a4f789cc-7bc8-4cf0-82b9-a8ba7d985ecf","name":"Guillaume | ||
Gelin","avatar_url":"https://s3-us-west-2.amazonaws.com/public.notion-static.com/1cddf30d-ef25-4372-a8bd-b510a11e26e8/avatar.jpeg","type":"person","person":{"email":"[email protected]"}},{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78","name":"notion-sdk-py","avatar_url":null,"type":"bot","bot":{"owner":{"type":"workspace","workspace":true}}}],"next_cursor":null,"has_more":false,"type":"user","user":{}}' | ||
content: '{"object":"list","results":[{"object":"user","id":"04db0808-966a-4668-9a27-8be05465b9c9","name":"Notion | ||
Testing Account","avatar_url":null,"type":"person","person":{}},{"object":"user","id":"823cf07b-34df-4ae6-9fbc-dbc600a815c6","name":"Testing","avatar_url":null,"type":"bot","bot":{"owner":{"type":"workspace","workspace":true},"workspace_name":"Notion | ||
Testing Account''s Notion"}}],"next_cursor":null,"has_more":false,"type":"user","user":{}}' | ||
headers: {} | ||
http_version: HTTP/1.1 | ||
status_code: 200 | ||
|
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 |
---|---|---|
|
@@ -40,8 +40,9 @@ interactions: | |
method: GET | ||
uri: https://api.notion.com/v1/users | ||
response: | ||
content: '{"object":"list","results":[{"object":"user","id":"a4f789cc-7bc8-4cf0-82b9-a8ba7d985ecf","name":"Guillaume | ||
Gelin","avatar_url":"https://s3-us-west-2.amazonaws.com/public.notion-static.com/1cddf30d-ef25-4372-a8bd-b510a11e26e8/avatar.jpeg","type":"person","person":{"email":"[email protected]"}},{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78","name":"notion-sdk-py","avatar_url":null,"type":"bot","bot":{"owner":{"type":"workspace","workspace":true}}}],"next_cursor":null,"has_more":false,"type":"user","user":{}}' | ||
content: '{"object":"list","results":[{"object":"user","id":"04db0808-966a-4668-9a27-8be05465b9c9","name":"Notion | ||
Testing Account","avatar_url":null,"type":"person","person":{}},{"object":"user","id":"823cf07b-34df-4ae6-9fbc-dbc600a815c6","name":"Testing","avatar_url":null,"type":"bot","bot":{"owner":{"type":"workspace","workspace":true},"workspace_name":"Notion | ||
Testing Account''s Notion"}}],"next_cursor":null,"has_more":false,"type":"user","user":{}}' | ||
headers: {} | ||
http_version: HTTP/1.1 | ||
status_code: 200 | ||
|
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,8 @@ interactions: | |
- '*/*' | ||
accept-encoding: | ||
- gzip, deflate | ||
authorization: | ||
- secret_... | ||
connection: | ||
- keep-alive | ||
host: | ||
|
@@ -38,8 +40,9 @@ interactions: | |
method: GET | ||
uri: https://api.notion.com/v1/users | ||
response: | ||
content: '{"object":"list","results":[{"object":"user","id":"a4f789cc-7bc8-4cf0-82b9-a8ba7d985ecf","name":"Guillaume | ||
Gelin","avatar_url":"https://s3-us-west-2.amazonaws.com/public.notion-static.com/1cddf30d-ef25-4372-a8bd-b510a11e26e8/avatar.jpeg","type":"person","person":{"email":"[email protected]"}},{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78","name":"notion-sdk-py","avatar_url":null,"type":"bot","bot":{"owner":{"type":"workspace","workspace":true}}}],"next_cursor":null,"has_more":false,"type":"user","user":{}}' | ||
content: '{"object":"list","results":[{"object":"user","id":"04db0808-966a-4668-9a27-8be05465b9c9","name":"Notion | ||
Testing Account","avatar_url":null,"type":"person","person":{}},{"object":"user","id":"823cf07b-34df-4ae6-9fbc-dbc600a815c6","name":"Testing","avatar_url":null,"type":"bot","bot":{"owner":{"type":"workspace","workspace":true},"workspace_name":"Notion | ||
Testing Account''s Notion"}}],"next_cursor":null,"has_more":false,"type":"user","user":{}}' | ||
headers: {} | ||
http_version: HTTP/1.1 | ||
status_code: 200 | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import pytest | ||
from httpx import TimeoutException | ||
|
||
from notion_client.errors import ( | ||
APIResponseError, | ||
HTTPResponseError, | ||
RequestTimeoutError, | ||
is_api_error_code, | ||
) | ||
|
||
STATUS_PAGE_BAD_REQUEST = "https://httpstat.us/400" | ||
|
||
|
||
@pytest.mark.vcr() | ||
def test_api_response_error(client): | ||
with pytest.raises(APIResponseError): | ||
client.request("/invalid", "GET") | ||
with pytest.raises(APIResponseError): | ||
client.request("/users", "GET", auth="Invalid") | ||
|
||
|
||
def test_api_request_timeout_error(monkeypatch, client): | ||
def mock_timeout_request(*args): | ||
raise TimeoutException("Mock Timeout") | ||
|
||
monkeypatch.setattr(client.client, "send", mock_timeout_request) | ||
|
||
with pytest.raises(RequestTimeoutError): | ||
client.request("/users", "GET") | ||
|
||
|
||
@pytest.mark.vcr() | ||
def test_api_http_response_error(client): | ||
with pytest.raises(HTTPResponseError): | ||
client.request(STATUS_PAGE_BAD_REQUEST, "GET") | ||
|
||
|
||
@pytest.mark.vcr() | ||
async def test_async_api_response_error(async_client): | ||
with pytest.raises(APIResponseError): | ||
await async_client.request("/invalid", "GET") | ||
with pytest.raises(APIResponseError): | ||
await async_client.request("/users", "GET", auth="Invalid") | ||
|
||
|
||
async def test_async_api_request_timeout_error(monkeypatch, async_client): | ||
def mock_timeout_request(*args): | ||
raise TimeoutException("Mock Timeout") | ||
|
||
monkeypatch.setattr(async_client.client, "send", mock_timeout_request) | ||
|
||
with pytest.raises(RequestTimeoutError): | ||
await async_client.request("/users", "GET") | ||
|
||
|
||
@pytest.mark.vcr() | ||
async def test_api_async_request_bad_request_error(async_client): | ||
with pytest.raises(HTTPResponseError): | ||
await async_client.request(STATUS_PAGE_BAD_REQUEST, "GET") | ||
|
||
|
||
async def test_is_api_error_code(): | ||
error_code = "unauthorized" | ||
assert is_api_error_code(error_code) | ||
assert not is_api_error_code(None) | ||
assert not is_api_error_code(404) |
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
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.
Uh oh!
There was an error while loading. Please reload this page.