More APIclient testing

This commit is contained in:
simonwt 2026-04-07 22:38:34 +01:00
parent 590fae1407
commit c646e7ddbc
2 changed files with 17 additions and 5 deletions

View file

@ -31,7 +31,6 @@ class APIClient(BaseModel):
client_id: SecretStr
client_secret: SecretStr
_access_token: str = PrivateAttr(default="")
_access_token_timeout: int = PrivateAttr(default=0)

View file

@ -65,11 +65,24 @@ class TestAPIClient(unittest.TestCase):
debug=False,
environment="invalid_env"
)
def test_set_environment_method(self):
self.api_client.set_environment("production")
self.assertEqual(self.api_client.environment, "production")
def test_make_non_supported_request_type(self):
with self.assertRaises(ValueError):
self.api_client.make_request("PATCH", "content", "test")
def test_make_request_with_bad_endpoint(self):
with self.assertRaises(ValueError):
self.api_client.make_request("GET", "invalid_endpoint", "test")
@patch('trustcafeapiwrapper.apiclient.requests.request')
def test_make_request(self, mock_request):
# This is a placeholder test. In a real test, you'd mock the HTTP request and response.
response = self.api_client.make_request("GET", "content", "https://api.example.com/test")
# This test should be expanded
# Or the the functions should be broken up more to be more easily testable
response = self.api_client.make_request("GET", "content", "test")
#
mock_request.assert_called_once()