stravalib
stravalib copied to clipboard
Test Refactoring
This adds a new job to the (now renamed) build-docs.yml workflow file that runs flake8 and pytest (and as such replaces the existing nosetest framework by the more modern pytest). Please note that only the unit and integration tests are included in the CI build.
TODO:
- [ ] Review
- [x] Update Contributing documentation
- [x] Create separate actions for lint/test/doc, testing should also run on multiple OS
I think I will do drop python2 work later we can save some codes.
I added minimal working examples of testing client endpoints with a mocked Strava API.
The mocked Strava API can be used as a pytest fixture and is implemented as a thin wrapper around the RequestsMock type from the responses package. Instead of specifying the entire expected JSON response body for every request, the published example responses by Strava (see the swagger.json file in RESOURCES) are used. They can be tweaked by providing a response_update argument to the mock methods.
TODO: dynamically choosing a response from the swagger.json based on the status code in case of non-200 responses.
@yihong0618 @lwasser @hozn, please let me know if this approach works for you. If so, we can continue migrating the other tests.
I added minimal working examples of testing client endpoints with a mocked Strava API.
The mocked Strava API can be used as a pytest fixture and is implemented as a thin wrapper around the
RequestsMocktype from theresponsespackage. Instead of specifying the entire expected JSON response body for every request, the published example responses by Strava (see the swagger.json file in RESOURCES) are used. They can be tweaked by providing aresponse_updateargument to the mock methods.TODO: dynamically choosing a response from the swagger.json based on the status code in case of non-200 responses.
@yihong0618 @lwasser @hozn, please let me know if this approach works for you. If so, we can continue migrating the other tests.
Looks good to me. can this PR be reviewed now or still WIP
You rock! I will look today.
On Mon, Nov 7, 2022, 20:41 yihong @.***> wrote:
I added minimal working examples of testing client endpoints with a mocked Strava API.
The mocked Strava API can be used as a pytest fixture and is implemented as a thin wrapper around the RequestsMock type from the responses package. Instead of specifying the entire expected JSON response body for every request, the published example responses by Strava (see the swagger.json file in RESOURCES) are used. They can be tweaked by providing a response_update argument to the mock methods.
TODO: dynamically choosing a response from the swagger.json based on the status code in case of non-200 responses.
@yihong0618 https://github.com/yihong0618 @lwasser https://github.com/lwasser @hozn https://github.com/hozn, please let me know if this approach works for you. If so, we can continue migrating the other tests.
Looks good to me.
— Reply to this email directly, view it on GitHub https://github.com/stravalib/stravalib/pull/245#issuecomment-1306494978, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB2LPKUQ2BGXB57VTC5SPBLWHGVUVANCNFSM6AAAAAARU6EB5M . You are receiving this because you were mentioned.Message ID: @.***>
Looks good to me. can this
PRbe reviewed now or still WIP
Yes, please review it when you have time. The module tests.integration.test_client has some examples of how to use the mock for different purposes, which may be a good starting point.
if y'all are ok with dropping python 2.x i really think we should! will do this after this
PRmerge