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

mocking iterative requests #45

Open
asadow opened this issue Jul 10, 2024 · 1 comment
Open

mocking iterative requests #45

asadow opened this issue Jul 10, 2024 · 1 comment

Comments

@asadow
Copy link

asadow commented Jul 10, 2024

This is more for a discussion, and is a copy of an issue I thought might belong in httr2.

My function my_perform() uses httr2::req_perform_iterative() which has a max_reqs argument (default to 20). I'd like to test that my_perform() performs an infinite or very large number of iterative requests.

For now I am testing the argument:

test_that("my_perform() performs Inf requests by default", {
  expect_equal(formals(my_perform)$max_reqs, Inf)
})

Is this ideal or is it instead better to mock a large request? I created a fake response with data removed which allows for

with_mock_api({
  test_that("my_perform() returns API page_count responses", {
    responses<- my_req("my_endpoint") |> my_perform()
    expect_length(responses, 21)
  })
})

(And I don't understand why the above requires 2 mock files, endpoint.R and endpoint-6fdf2d.R.)

@nealrichardson nealrichardson transferred this issue from nealrichardson/httptest Jul 23, 2024
@nealrichardson
Copy link
Owner

(Moved this from httptest to httptest2)

I don't think you want to test that it actually makes an infinite number of requests. I would do what I gather you're doing with the fake responses, and test that your function does the iteration as expected, and you get the right results that would only get if it correctly paged through the API as you expect.

(And I don't understand why the above requires 2 mock files, endpoint.R and endpoint-6fdf2d.R.)

I can't say without seeing your code, but my guess is that the iterative next_req function you have is adding a query parameter to fetch the next page of results or whatever, and 6fdf2d is the hash of that added query string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants