-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c91d96f
commit 8d21675
Showing
5 changed files
with
168 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,78 @@ | ||
import pytest | ||
import requests | ||
import responses | ||
|
||
from api_to_dataframe.models.get_data import GetData | ||
from api_to_dataframe.controller.client_builder import ClientBuilder | ||
from api_to_dataframe.common.utils.retry_strategies import RetryStrategies | ||
|
||
|
||
def test_get_response(): | ||
assert True | ||
|
||
|
||
def test_to_dataframe(): | ||
with pytest.raises(TypeError): | ||
GetData.to_dataframe("") | ||
|
||
|
||
@responses.activate | ||
def test_to_emp_dataframe(): | ||
endpoint = "https://api.exemplo.com" | ||
expected_response = {} | ||
|
||
responses.add(responses.GET, endpoint, | ||
json=expected_response, status=200) | ||
|
||
client = ClientBuilder(endpoint=endpoint) | ||
response = client.get_api_data() | ||
|
||
with pytest.raises(ValueError): | ||
GetData.to_dataframe(response) | ||
|
||
|
||
@responses.activate | ||
def test_http_error(): | ||
endpoint = "https://api.exemplo.com" | ||
expected_response = {} | ||
|
||
responses.add(responses.GET, endpoint, | ||
json=expected_response, status=400) | ||
|
||
with ((pytest.raises(requests.exceptions.HTTPError))): | ||
GetData.get_response( | ||
endpoint=endpoint, | ||
retry_strategies=RetryStrategies.NoRetryStrategy, | ||
headers={}, | ||
timeout=10) | ||
|
||
|
||
@responses.activate | ||
def test_timeout_error(): | ||
endpoint = "https://api.exemplo.com" | ||
|
||
responses.add(responses.GET, endpoint, body=requests.exceptions.Timeout()) | ||
|
||
with pytest.raises(requests.exceptions.Timeout): | ||
GetData.get_response( | ||
endpoint=endpoint, | ||
retry_strategies=RetryStrategies.NoRetryStrategy, | ||
headers={}, | ||
timeout=10) | ||
|
||
|
||
@responses.activate | ||
def test_request_exception(): | ||
endpoint = "https://api.exemplo.com" | ||
|
||
expected_response = {} | ||
|
||
responses.add(responses.GET, endpoint, | ||
json=expected_response, status=500) | ||
|
||
with pytest.raises(requests.exceptions.RequestException): | ||
GetData.get_response( | ||
endpoint=endpoint, | ||
retry_strategies=RetryStrategies.NoRetryStrategy, | ||
headers={}, | ||
timeout=10) |