Closed Bug 1358312 Opened 7 years ago Closed 7 years ago

Support testing of GitHub API requests

Categories

(Developer Services :: Servo VCS Sync, enhancement)

enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: gps, Assigned: gps)

References

(Blocks 1 open bug)

Details

Attachments

(4 files)

We currently don't have good testing of functionality that touches the GitHub API. I have a trick up my sleeve to facilitate testing of GitHub API requests.
Comment on attachment 8860224 [details]
vcssync: stop defining GitHub username (bug 1358312);

https://reviewboard.mozilla.org/r/132224/#review135588
Attachment #8860224 - Flags: review?(glob) → review+
Comment on attachment 8860225 [details]
vcssync: add utility function for obtaining a github3 client (bug 1358312);

https://reviewboard.mozilla.org/r/132226/#review135590
Attachment #8860225 - Flags: review?(glob) → review+
Comment on attachment 8860226 [details]
vcssync: don't write tailing JSON (bug 1358312);

https://reviewboard.mozilla.org/r/132228/#review135592
Attachment #8860226 - Flags: review?(glob) → review+
Comment on attachment 8860227 [details]
vcssync: use betamax for testing GitHub API interactions (bug 1358312);

https://reviewboard.mozilla.org/r/132230/#review135596

::: vcssync/mozvcssync/util.py:57
(Diff revision 1)
> +            config.cassette_library_dir = betamax_library_dir
> +
> +            # We don't want requests hitting the network at all.
> +            config.default_cassette_options['record_mode'] = 'none'
> +
> +        recorder = betamax.Betamax(gh._session)

not a fan of accessing the private _session var, however until github3 1.0.0 is released we're stuck with it i guess.

::: vcssync/tests/record_cassettes.py:52
(Diff revision 1)
> +    with recorder.use_cassette('linearize-github-pull-request-messages'):
> +        # This test simply looks up a pull request and resolves more info about
> +        # the user who created it.
> +        client.login(token=args.token)
> +        client.pull_request('servo', 'servo', 16549)
> +        client.user('bholley')

in its current form it isn't obvious which file needs to be touched if a cassette needs to be updated due to the code performing additional requests.

the cassette recording actions for each test should be in their own file which shares the same name as the test/cassette (eg. tests/cassettes/linearize-github-pull-request-messages.py)

record_cassettes.py then becomes a wrapping harness for setting up betamax (and the github client?), then runs each cassette generator.
Attachment #8860227 - Flags: review?(glob) → review-
Comment on attachment 8860227 [details]
vcssync: use betamax for testing GitHub API interactions (bug 1358312);

https://reviewboard.mozilla.org/r/132230/#review135596

> not a fan of accessing the private _session var, however until github3 1.0.0 is released we're stuck with it i guess.

I was going to upgrade to github3 1.0.0. I wanted to have some testing in place before I did to prove certain things didn't break.

> in its current form it isn't obvious which file needs to be touched if a cassette needs to be updated due to the code performing additional requests.
> 
> the cassette recording actions for each test should be in their own file which shares the same name as the test/cassette (eg. tests/cassettes/linearize-github-pull-request-messages.py)
> 
> record_cassettes.py then becomes a wrapping harness for setting up betamax (and the github client?), then runs each cassette generator.

Yeah, this is how many projects do it. I figured it wasn't worth the initial complexity to stand up the infrastructure: I was very much going for MVP here.

Another alternative which I considered is not having a dedicated cassette recorder at all - at least for simple cases. We could have environment variables trigger a "recording mode" and then when you run a test in recording mode, it will write a cassette. This would prevent us from having to explicitly maintain cassette recordings that are shallow copies of functionality exercised in tests. Again, I thought it would be too difficult to initially implement.
Comment on attachment 8860227 [details]
vcssync: use betamax for testing GitHub API interactions (bug 1358312);

https://reviewboard.mozilla.org/r/132230/#review135596

> Yeah, this is how many projects do it. I figured it wasn't worth the initial complexity to stand up the infrastructure: I was very much going for MVP here.
> 
> Another alternative which I considered is not having a dedicated cassette recorder at all - at least for simple cases. We could have environment variables trigger a "recording mode" and then when you run a test in recording mode, it will write a cassette. This would prevent us from having to explicitly maintain cassette recordings that are shallow copies of functionality exercised in tests. Again, I thought it would be too difficult to initially implement.

fair enough; i'll drop this issue with a MVP in mind.
once we have more than one test and/or project using betamax we should revisit.
Comment on attachment 8860227 [details]
vcssync: use betamax for testing GitHub API interactions (bug 1358312);

https://reviewboard.mozilla.org/r/132230/#review137126
Attachment #8860227 - Flags: review- → review+
Pushed by gszorc@mozilla.com:
https://hg.mozilla.org/hgcustom/version-control-tools/rev/1c31dc81d838
vcssync: stop defining GitHub username ; r=glob
https://hg.mozilla.org/hgcustom/version-control-tools/rev/ff21afb2cbe6
vcssync: add utility function for obtaining a github3 client ; r=glob
https://hg.mozilla.org/hgcustom/version-control-tools/rev/862b38792a69
vcssync: don't write tailing JSON ; r=glob
https://hg.mozilla.org/hgcustom/version-control-tools/rev/f7f0fb021395
vcssync: use betamax for testing GitHub API interactions ; r=glob
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: