Skip to content
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

Testing GET Rest API with http://{domain}/ #1

Closed
byapparov opened this issue Feb 5, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@byapparov
Copy link
Contributor

commented Feb 5, 2017

Hi,

I am not sure how to use with_mock_API against the full URL that contains http(s)://{domain}.
Where the json files should be located in this case?

For example if I want to do something like this in my package:

    response <- GET(url  = "https://mydomain.zendesk.com",
                    path = "api/v2/incremental/tickets.json?update_date=3423423",
                    add_headers("Content-Type" = "application/json"),
                    authenticate(user = Sys.getenv("ZENDESK_USER"),
                                 password = Sys.getenv("ZENDESK_PASSWORD"))

Can I mock the response?

nealrichardson added a commit that referenced this issue Feb 5, 2017

@nealrichardson

This comment has been minimized.

Copy link
Owner

commented Feb 5, 2017

Thanks! I see that with_mock_API did not work with real URLs (those starting with http:// or any other protocol), only mock files paths. The commit linked above addresses that. Can you pull that branch and see if it meets your needs? If not, could you please add a failing test or two to test-mock-api.R and make a pull request back?

With the new commit, your mock for that request would go in tests/testthat/mydomain.zendesk.com/api/v2/incremental/tickets.json plus some hash of the querystring, I think. If you write the test, the with_mock_API context will tell you where it looked for the file if it doesn't find one.

@byapparov

This comment has been minimized.

Copy link
Contributor Author

commented Feb 6, 2017

Thank you @nealrichardson, it works fine. Very useful package!

@nealrichardson

This comment has been minimized.

Copy link
Owner

commented Feb 9, 2017

Ok, merged that branch in and tagged a release: https://github.com/nealrichardson/httptest/releases/tag/1.1.2

Can't put it on CRAN just yet because the previous release was only a few days ago, but you can devtools::install_github that tag. Thanks for your feedback!

nealrichardson pushed a commit that referenced this issue Mar 21, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.