Skip to content

Commit 93ae13f

Browse files
Test coverage
1 parent 9d96d4a commit 93ae13f

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

tests.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
import requests
88

99
from src.iracingdataapi.client import irDataClient
10+
from src.iracingdataapi.exceptions import AccessTokenInvalid
1011

1112

1213
class TestIrDataClient(unittest.TestCase):
1314
def setUp(self):
1415
self.client = irDataClient(username="test_user", password="test_password")
16+
self.access_token_client = irDataClient(access_token="some-mock-token")
1517

1618
def test_encode_password(self):
1719
expected_password = base64.b64encode(
@@ -579,8 +581,8 @@ def test_parse_csv_response_mismatch(self, mock_print):
579581
result = self.client._parse_csv_response(csv_text)
580582
self.assertEqual(result, expected_output)
581583
self.assertTrue(mock_print.called)
582-
self.assertTrue(
583-
mock_print.called_with("Warning: Row length does not match headers length")
584+
mock_print.assert_called_with(
585+
"Warning: Row length does not match headers length"
584586
)
585587

586588
@patch.object(irDataClient, "get_cars")
@@ -1592,6 +1594,31 @@ def test_series_seasons(self, mock_get_resource):
15921594
)
15931595
self.assertEqual(result, mock_get_resource.return_value)
15941596

1597+
def test_access_token_or_credentials(self):
1598+
"""
1599+
It should not be possible to supply both credentials and an access token
1600+
"""
1601+
with self.assertRaises(AttributeError):
1602+
irDataClient(
1603+
username="[email protected]",
1604+
password="somepassword",
1605+
access_token="an-access-token",
1606+
)
1607+
1608+
@patch("requests.Session.get")
1609+
def test_access_token_invalid_raises(self, mock_requests_get):
1610+
"""
1611+
When an access token is no longer valid, it should raise a specific exception for consumers to build around
1612+
"""
1613+
1614+
mock_requests_get.return_value = MagicMock(status_code=401)
1615+
with self.assertRaises(AccessTokenInvalid):
1616+
subsession_id = 12345
1617+
include_licenses = True
1618+
response = self.access_token_client.result(
1619+
subsession_id=subsession_id, include_licenses=include_licenses
1620+
)
1621+
15951622

15961623
if __name__ == "__main__":
15971624
unittest.main()

0 commit comments

Comments
 (0)