@@ -195,27 +195,81 @@ All resource mocks are in the root [conftest.py](tests/conftest.py).
195195
196196### Response Mocking
197197
198- The test suite uses the ` mock_response_factory ` fixture to create consistent,
199- configurable mock responses:
198+ The test suite uses the ` mock_response_factory ` fixture from ` tests/conftest.py `
199+ to create consistent, configurable mock responses. This is the required pattern
200+ for all tests that need to mock HTTP responses.
201+
202+ #### Standard Mock Response Pattern
203+
204+ ``` python
205+ def test_some_endpoint (resource , mock_oauth_session , mock_response_factory ):
206+ """ Test description."""
207+ # Define expected data first
208+ expected_data = {" data" : " test" }
209+
210+ # Create mock response using the factory
211+ mock_response = mock_response_factory(200 , expected_data)
212+
213+ # Assign to oauth.request.return_value
214+ resource.oauth.request.return_value = mock_response
215+
216+ # Call the method under test
217+ result = resource.some_method()
218+
219+ # Assert against expected_data, not mock_response.json.return_value
220+ assert result == expected_data
221+ ```
222+
223+ #### Response Factory Examples
200224
201225``` python
202- # Creating a mock response with status code and data
226+ # Success response with data
203227mock_response = mock_response_factory(200 , {" data" : " test" })
204228
205- # Creating a mock response with additional headers
229+ # Response with custom headers
206230mock_response = mock_response_factory(
207231 status_code = 200 ,
208232 json_data = {" data" : " test" },
209233 headers = {" custom-header" : " value" }
210234)
211235
212- # Creating a delete response with no content (204)
236+ # Delete/ no content response (204)
213237mock_response = mock_response_factory(204 )
238+
239+ # Error response
240+ mock_response = mock_response_factory(
241+ 400 ,
242+ {" errors" : [{" errorType" : " validation" , " message" : " Error message" }]}
243+ )
244+
245+ # Non-JSON response (XML)
246+ mock_response = mock_response_factory(
247+ 200 ,
248+ headers = {" content-type" : " application/vnd.garmin.tcx+xml" },
249+ content_type = " application/vnd.garmin.tcx+xml"
250+ )
251+ mock_response.text = " <xml>content</xml>"
252+ ```
253+
254+ #### Parameter Validation Pattern
255+
256+ For tests that only need to verify parameter validation or endpoint construction
257+ (not response handling), it's acceptable to use the following alternative
258+ pattern:
259+
260+ ``` python
261+ def test_validation (resource ):
262+ """ Test parameter validation."""
263+ resource._make_request = Mock()
264+ resource.some_method(param = " value" )
265+ resource._make_request.assert_called_once_with(
266+ " endpoint/path" , params = {" param" : " value" }, user_id = " -" , debug = False
267+ )
214268```
215269
216270This approach provides a clean, standardized way to create mock responses with
217- the desired status code, data, and headers. All test files should use this
218- factory method rather than manually configuring mock responses .
271+ the desired status code, data, and headers. All test files must use one of these
272+ patterns .
219273
220274## OAuth Callback Implementation
221275
0 commit comments