-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a test that we return the correct number of results #112
Comments
I took a pass at this but I'm struggling to get the tests to use my existing Here's my test:
Which should work (it's what you'd do in the console). But the test fails, reporting:
And when I look at the recorded YAML from
What am I doing wrong? |
To be clear, obviously I'll be removing the call to meetup_auth() once I have the recorded yaml, I just need a way to authenticate :) Also, I just tried copying my token to the default path (mycheckout/.httr-oauth) and removing the call to meetup_auth() - still fails. |
I think you are bitten by meetupr/tests/testthat/setup.R Line 1 in c9c5843
To contribute and add tests the best thing is to create a token for tests, now I am wondering what would be the best way to make you add one. I'm looking at ropensci-archive/rtweet#512 |
that said |
Hmm, I added some classic oldschool |
thank you! there's definitely a bug somewhere in our codebase. |
@maelle OK, making progress. So, this is definitely hitting the Lines 208 to 211 in fb84cec
which clearly skips any kind of token loading. So it's no surprise I can't auth. I commented that out, which brings us to: Lines 212 to 213 in fb84cec
And here I get stuck. With some print statements I can see it's trying to load a default token from "~/.local/share/meetupr/meetupr-token.rds" which obviously doesn't exist. I changed it to look like this for debugging:
Which claims to load the token - you can see the verbose output of meetup_auth and token_available:
However, it fails. But differently, now I get a 401 Unauthorized instead of a 400. So, progress I guess? :) Is there a way to record an interactive session with |
Thank you! Where is your token? The location I'll come back to this within the next few days. |
So I've been doing quite a lot of digging. Part of the problem is the code creating (broken) tokens which are then hidden from me because I use "git status" to see what I've touched in the repo, but However, I'm now fairly sure it's VCR that is breaking me. Here's my reproducer:
This passes, which is a relief:
If I now enable VCR:
I go back to getting a 401. I wondered if it's related to this: meetupr/tests/testthat/setup.R Lines 29 to 35 in fb84cec
But I think that's for filtering the record after the call is complete, right? In any case, I'm now stuck - it seems that the call the |
OK, more progress - I figured out how to use
This correctly runs, and creates a YAML recording, but it looks like its not capturing the second page, so then I get:
Note the page=200 and offset=1, this is the second call in the pagination loop. So progress, I can record something, and get the test to read it. But I'm out of time for today, will poke it more tomorrow ;) |
@maelle I think I got it, but I'm certain I'm making this harder than it should be. I've got working tests, and I've added them to #111 To get there, I had to work out how to get vcr to run in my console in record mode. Then once I had the yaml, the tests were trivial. To do that, I used this script at the console: # load meetup
devtools::load_all()
# read my token
meetup_auth(token = '~/.local/share/meetupr/meetupr-token.rds')
# This is copied from setup.R so that VCR deletes sensitive data and writes to the fixtures
library("vcr")
token <- .state$token
invisible(vcr::vcr_configure(
filter_request_headers = list(Authorization = "not my bearer token"),
filter_sensitive_data = list(
"<<<my_refresh_token>>>" = token$credentials$refresh_token %||% "lala"
),
dir = here::here("tests/fixtures")
))
# for some reason i have to run at least one API call outside of vcr, else I get 401s
find_groups('Ansible')
# now I can record the transaction
use_cassette('find_groups_2_pages', record = 'all', {
find_groups('Ansible')
}) With that, I managed to create two passing tests in #111. Is there a better way? |
@GregSutcliffe I'm working on a PR where I change the place of the environment variable that as you correctly pointed out was preventing the addition of new test in the absence of MEETUPR_PWD. I am so sorry and also very thankful that you found this out! |
No problem @maelle I learned a lot about vcr along the way and that's going to be useful at some point. No learning is ever wasted :) |
rewrite PRO functions to query GraphQL
This is a bug that could have been found by having a unit test for this. This ticket is generic, though the bug above is for
find_groups()
specficially.The text was updated successfully, but these errors were encountered: