stravalib icon indicating copy to clipboard operation
stravalib copied to clipboard

Test Refactoring

Open jsamoocha opened this issue 3 years ago • 6 comments

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

jsamoocha avatar Nov 02 '22 10:11 jsamoocha

I think I will do drop python2 work later we can save some codes.

yihong0618 avatar Nov 02 '22 10:11 yihong0618

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.

jsamoocha avatar Nov 07 '22 11:11 jsamoocha

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.

Looks good to me. can this PR be reviewed now or still WIP

yihong0618 avatar Nov 08 '22 01:11 yihong0618

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: @.***>

lwasser avatar Nov 08 '22 10:11 lwasser

Looks good to me. can this PR be 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.

jsamoocha avatar Nov 08 '22 19:11 jsamoocha

if y'all are ok with dropping python 2.x i really think we should! will do this after this PR merge

yihong0618 avatar Nov 09 '22 06:11 yihong0618