-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Move tests to tests/ dir (#60)
* Move tests to tests/ directory * Rename test files to test_ prefix * Install before running tests in ci * Here too * Rework coverage workflow
- Loading branch information
1 parent
08bb033
commit ec19c93
Showing
14 changed files
with
85 additions
and
95 deletions.
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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
src/posit/connect/auth_test.py → tests/posit/connect/test_auth.py
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
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
2 changes: 1 addition & 1 deletion
2
src/posit/connect/content_test.py → tests/posit/connect/test_content.py
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,6 @@ | ||
import responses | ||
|
||
from .client import Client | ||
from posit.connect.client import Client | ||
|
||
|
||
class TestContents: | ||
|
2 changes: 1 addition & 1 deletion
2
src/posit/connect/errors_test.py → tests/posit/connect/test_errors.py
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import io | ||
|
||
import pytest | ||
|
||
from requests import HTTPError, Response | ||
from unittest.mock import Mock, patch | ||
|
||
from posit.connect.errors import ClientError | ||
from posit.connect.hooks import handle_errors | ||
|
||
|
||
def test_success(): | ||
response = Mock() | ||
response.status_code = 200 | ||
assert handle_errors(response) == response | ||
|
||
|
||
def test_client_error(): | ||
response = Mock() | ||
response.status_code = 400 | ||
response.json = Mock(return_value={"code": 0, "error": "foobar"}) | ||
with pytest.raises(ClientError): | ||
handle_errors(response) | ||
|
||
|
||
@patch("posit.connect.hooks.JSONDecodeError") | ||
def test_client_error_without_payload(JSONDecodeError): | ||
response = Mock() | ||
response.status_code = 404 | ||
response.json = Mock(side_effect=JSONDecodeError()) | ||
response.raise_for_status = Mock(side_effect=Exception()) | ||
with pytest.raises(Exception): | ||
handle_errors(response) | ||
|
||
|
||
def test_200(): | ||
response = Response() | ||
response.status_code = 200 | ||
assert handle_errors(response) == response | ||
|
||
|
||
def test_response_client_error_with_plaintext_payload(): | ||
response = Response() | ||
response.status_code = 404 | ||
response.raw = io.BytesIO(b"Plain text 404 Not Found") | ||
with pytest.raises(HTTPError): | ||
handle_errors(response) | ||
|
||
|
||
def test_response_client_error_with_json_payload(): | ||
response = Response() | ||
response.status_code = 400 | ||
response.raw = io.BytesIO(b'{"code":0,"error":"foobar"}') | ||
with pytest.raises( | ||
ClientError, match=r"foobar \(Error Code: 0, HTTP Status: 400 Bad Request\)" | ||
): | ||
handle_errors(response) | ||
|
||
|
||
def test_response_client_error_without_payload(): | ||
response = Response() | ||
response.status_code = 404 | ||
response.raw = io.BytesIO(b"Plain text 404 Not Found") | ||
with pytest.raises(HTTPError): | ||
handle_errors(response) |
2 changes: 1 addition & 1 deletion
2
src/posit/connect/oauth_test.py → tests/posit/connect/test_oauth.py
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,6 @@ | ||
import responses | ||
|
||
from .client import Client | ||
from posit.connect import Client | ||
|
||
|
||
class TestOAuthIntegrations: | ||
|
2 changes: 1 addition & 1 deletion
2
src/posit/connect/urls_test.py → tests/posit/connect/test_urls.py
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
2 changes: 1 addition & 1 deletion
2
src/posit/connect/users_test.py → tests/posit/connect/test_users.py
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