Skip to content

Commit

Permalink
Merge branch 'feature/requests_exceptions' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
man-c committed Apr 7, 2021
2 parents 9193c00 + 74df2a2 commit f3296b5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pycoingecko/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def __request(self, url):
# print(url)
try:
response = self.session.get(url, timeout=self.request_timeout)
except requests.exceptions.RequestException:
raise

try:
response.raise_for_status()
content = json.loads(response.content.decode('utf-8'))
return content
Expand All @@ -33,8 +37,7 @@ def __request(self, url):
# if no json
except json.decoder.JSONDecodeError:
pass
# except UnboundLocalError as e:
# pass

raise

def __api_url_params(self, api_url, params, api_url_has_params=False):
Expand Down
7 changes: 7 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import pytest
import requests.exceptions
import responses
import unittest
import unittest.mock as mock

from pycoingecko import CoinGeckoAPI
from requests.exceptions import HTTPError


class TestWrapper(unittest.TestCase):

@responses.activate
def test_connection_error(self):
with pytest.raises(requests.exceptions.ConnectionError):
CoinGeckoAPI().ping()

@responses.activate
def test_failed_ping(self):
# Arrange
Expand Down

0 comments on commit f3296b5

Please sign in to comment.