66from src .thecompaniesapi import Client , HttpClient , ApiError
77
88
9+ @pytest .mark .unit
910class TestHttpClient :
1011 """Test the HttpClient class functionality."""
1112
@@ -172,6 +173,7 @@ def test_non_json_response(self):
172173 assert result == {"data" : "Plain text response" , "status" : 200 }
173174
174175
176+ @pytest .mark .unit
175177class TestClient :
176178 """Test the main Client class."""
177179
@@ -202,17 +204,17 @@ def test_init_with_custom_params(self):
202204 assert client .http .timeout == 60
203205
204206 @responses .activate
205- def test_fetch_api_health (self ):
206- """Test the example fetch_api_health method."""
207+ def test_fetchApiHealth (self ):
208+ """Test the dynamically generated fetchApiHealth method."""
207209 responses .add (
208210 responses .GET ,
209- "https://api.thecompaniesapi.com/v2/health " ,
211+ "https://api.thecompaniesapi.com/" ,
210212 json = {"status" : "healthy" },
211213 status = 200
212214 )
213215
214216 client = Client (api_token = "test-token" )
215- result = client .fetch_api_health ()
217+ result = client .fetchApiHealth ()
216218
217219 assert result == {"status" : "healthy" }
218220
@@ -222,12 +224,28 @@ def test_http_client_delegation(self):
222224
223225 # Mock the HttpClient's get method
224226 with patch .object (client .http , 'get' , return_value = {"mocked" : True }) as mock_get :
225- result = client .fetch_api_health ()
227+ result = client .fetchApiHealth ()
226228
227- mock_get .assert_called_once_with ('/v2/health' )
229+ mock_get .assert_called_once_with ('/' , params = {} )
228230 assert result == {"mocked" : True }
231+
232+ def test_dynamic_operations_loading (self ):
233+ """Test that operations are loaded dynamically from the generated schema."""
234+ client = Client (api_token = "test-token" )
235+
236+ # Should have loaded operations from generated schema
237+ assert len (client ._operations_map ) > 0
238+ assert "fetchApiHealth" in client ._operations_map
239+
240+ # Test dynamic attribute access
241+ assert hasattr (client , "fetchApiHealth" )
242+
243+ # Test that non-existent methods raise AttributeError
244+ with pytest .raises (AttributeError ):
245+ client .non_existent_method
229246
230247
248+ @pytest .mark .unit
231249class TestApiError :
232250 """Test the ApiError exception class."""
233251
0 commit comments