@@ -24,12 +24,27 @@ class TestCommunitiesContracts:
2424
2525 def setup_class (self ):
2626 """Set up test fixtures."""
27- self .client = Client (base_url = "https://api.example.com" )
27+ # Provide all authentication types for comprehensive test coverage
28+ # Tests mock the session, so actual HTTP requests won't be made
29+ from xdk .oauth1_auth import OAuth1
30+ oauth1 = OAuth1 (
31+ api_key = "test_api_key" ,
32+ api_secret = "test_api_secret" ,
33+ callback = "http://localhost:8080/callback" ,
34+ access_token = "test_access_token" ,
35+ access_token_secret = "test_access_token_secret" ,
36+ )
37+ self .client = Client (
38+ base_url = "https://api.example.com" ,
39+ bearer_token = "test_bearer_token" ,
40+ access_token = "test_access_token" ,
41+ auth = oauth1 ,
42+ )
2843 self .communities_client = getattr (self .client , "communities" )
2944
3045
31- def test_search_request_structure (self ):
32- """Test search request structure."""
46+ def test_get_by_id_request_structure (self ):
47+ """Test get_by_id request structure."""
3348 # Mock the session to capture request details
3449 with patch .object (self .client , "session" ) as mock_session :
3550 mock_response = Mock ()
@@ -42,11 +57,11 @@ def test_search_request_structure(self):
4257 # Prepare test parameters
4358 kwargs = {}
4459 # Add required parameters
45- kwargs ["query " ] = "test_query "
60+ kwargs ["id " ] = "test_value "
4661 # Add request body if required
4762 # Call the method
4863 try :
49- method = getattr (self .communities_client , "search " )
64+ method = getattr (self .communities_client , "get_by_id " )
5065 # Check if this might be a streaming operation by inspecting return type
5166 import types
5267 import inspect
@@ -109,7 +124,7 @@ def test_search_request_structure(self):
109124 called_url = (
110125 call_args [0 ][0 ] if call_args [0 ] else call_args [1 ].get ("url" , "" )
111126 )
112- expected_path = "/2/communities/search "
127+ expected_path = "/2/communities/{id} "
113128 assert expected_path .replace ("{" , "" ).replace (
114129 "}" , ""
115130 ) in called_url or any (
@@ -125,12 +140,12 @@ def test_search_request_structure(self):
125140 # For regular operations, verify we got a result
126141 assert result is not None , "Method should return a result"
127142 except Exception as e :
128- pytest .fail (f"Contract test failed for search : { e } " )
143+ pytest .fail (f"Contract test failed for get_by_id : { e } " )
129144
130145
131- def test_search_required_parameters (self ):
132- """Test that search handles parameters correctly."""
133- method = getattr (self .communities_client , "search " )
146+ def test_get_by_id_required_parameters (self ):
147+ """Test that get_by_id handles parameters correctly."""
148+ method = getattr (self .communities_client , "get_by_id " )
134149 # Test with missing required parameters - mock the request to avoid network calls
135150 with patch .object (self .client , "session" ) as mock_session :
136151 # Mock a 400 response (typical for missing required parameters)
@@ -150,8 +165,8 @@ def test_search_required_parameters(self):
150165 next (result )
151166
152167
153- def test_search_response_structure (self ):
154- """Test search response structure validation."""
168+ def test_get_by_id_response_structure (self ):
169+ """Test get_by_id response structure validation."""
155170 with patch .object (self .client , "session" ) as mock_session :
156171 # Create mock response with expected structure
157172 mock_response_data = {
@@ -164,10 +179,10 @@ def test_search_response_structure(self):
164179 mock_session .get .return_value = mock_response
165180 # Prepare minimal valid parameters
166181 kwargs = {}
167- kwargs ["query " ] = "test_value "
182+ kwargs ["id " ] = "test "
168183 # Add request body if required
169184 # Call method and verify response structure
170- method = getattr (self .communities_client , "search " )
185+ method = getattr (self .communities_client , "get_by_id " )
171186 result = method (** kwargs )
172187 # Verify response object has expected attributes
173188 # Optional field - just check it doesn't cause errors if accessed
@@ -179,8 +194,8 @@ def test_search_response_structure(self):
179194 )
180195
181196
182- def test_get_by_id_request_structure (self ):
183- """Test get_by_id request structure."""
197+ def test_search_request_structure (self ):
198+ """Test search request structure."""
184199 # Mock the session to capture request details
185200 with patch .object (self .client , "session" ) as mock_session :
186201 mock_response = Mock ()
@@ -193,11 +208,11 @@ def test_get_by_id_request_structure(self):
193208 # Prepare test parameters
194209 kwargs = {}
195210 # Add required parameters
196- kwargs ["id " ] = "test_value "
211+ kwargs ["query " ] = "test_query "
197212 # Add request body if required
198213 # Call the method
199214 try :
200- method = getattr (self .communities_client , "get_by_id " )
215+ method = getattr (self .communities_client , "search " )
201216 # Check if this might be a streaming operation by inspecting return type
202217 import types
203218 import inspect
@@ -260,7 +275,7 @@ def test_get_by_id_request_structure(self):
260275 called_url = (
261276 call_args [0 ][0 ] if call_args [0 ] else call_args [1 ].get ("url" , "" )
262277 )
263- expected_path = "/2/communities/{id} "
278+ expected_path = "/2/communities/search "
264279 assert expected_path .replace ("{" , "" ).replace (
265280 "}" , ""
266281 ) in called_url or any (
@@ -276,12 +291,12 @@ def test_get_by_id_request_structure(self):
276291 # For regular operations, verify we got a result
277292 assert result is not None , "Method should return a result"
278293 except Exception as e :
279- pytest .fail (f"Contract test failed for get_by_id : { e } " )
294+ pytest .fail (f"Contract test failed for search : { e } " )
280295
281296
282- def test_get_by_id_required_parameters (self ):
283- """Test that get_by_id handles parameters correctly."""
284- method = getattr (self .communities_client , "get_by_id " )
297+ def test_search_required_parameters (self ):
298+ """Test that search handles parameters correctly."""
299+ method = getattr (self .communities_client , "search " )
285300 # Test with missing required parameters - mock the request to avoid network calls
286301 with patch .object (self .client , "session" ) as mock_session :
287302 # Mock a 400 response (typical for missing required parameters)
@@ -301,8 +316,8 @@ def test_get_by_id_required_parameters(self):
301316 next (result )
302317
303318
304- def test_get_by_id_response_structure (self ):
305- """Test get_by_id response structure validation."""
319+ def test_search_response_structure (self ):
320+ """Test search response structure validation."""
306321 with patch .object (self .client , "session" ) as mock_session :
307322 # Create mock response with expected structure
308323 mock_response_data = {
@@ -315,10 +330,10 @@ def test_get_by_id_response_structure(self):
315330 mock_session .get .return_value = mock_response
316331 # Prepare minimal valid parameters
317332 kwargs = {}
318- kwargs ["id " ] = "test "
333+ kwargs ["query " ] = "test_value "
319334 # Add request body if required
320335 # Call method and verify response structure
321- method = getattr (self .communities_client , "get_by_id " )
336+ method = getattr (self .communities_client , "search " )
322337 result = method (** kwargs )
323338 # Verify response object has expected attributes
324339 # Optional field - just check it doesn't cause errors if accessed
0 commit comments