Skip to content

Commit

Permalink
Multipart can also contain raw data
Browse files Browse the repository at this point in the history
  • Loading branch information
jmaspons committed Jun 17, 2024
1 parent 66e2195 commit d68b18e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# httptest2 1.1.0.9000

* `build_mock_url()` now works with multipart body request containing strings (#40, @jmaspons)
* `build_mock_url()` now works with multipart body request containing character strings or raw data (#40, @jmaspons)

# httptest2 1.1.0

Expand Down Expand Up @@ -40,4 +40,4 @@ Changes to function signatures:

* The `path` argument to `capture_requests()` and `start_capturing()` has been removed; instead set the mock path explicitly with `.mockPaths()` or use `with_mock_dir()`.
* Internal function `save_response()` requires a `file` path argument because `httr2_response` objects do not contain their `request`, which is needed to construct the mock file path
* Internal function `build_mock_url()` no longer accepts a string URL as an input; it only accepts `request` objects
* Internal function `build_mock_url()` no longer accepts a string URL as an input; it only accepts `request` objects
2 changes: 1 addition & 1 deletion R/build-mock-url.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ get_string_request_body <- function(req) {
} else if (inherits(x, "form_data")) {
rawToChar(x$value)
} else {
# assume string
# assume character string or raw
x
}
})
Expand Down
8 changes: 5 additions & 3 deletions tests/testthat/test-capture-requests.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ test_that("We can record a series of requests (a few ways)", {
req_body_multipart(
file = curl::form_file(file_path),
string = "some text",
form_data = curl::form_data("form data")
form_data = curl::form_data("form data"),
raw_data = charToRaw("raw data")
) %>%
req_method("POST") %>%
req_perform()
Expand All @@ -51,7 +52,7 @@ test_that("We can record a series of requests (a few ways)", {
"httpbin.org/get.json",
"httpbin.org/image/webp.R", # Not a simplifiable format, so .R
"httpbin.org/image/webp.R-FILE", # The `write_disk` location
"httpbin.org/post-40b03d-POST.json",
"httpbin.org/post-4f024d-POST.json",
"httpbin.org/put-PUT.json", # Not a GET, but returns 200
"httpbin.org/response-headers-ac4928.json",
"httpbin.org/status/200.txt", # empty 200 response "text/plain", so .txt
Expand Down Expand Up @@ -109,7 +110,8 @@ test_that("We can then load the mocks it stores", {
req_body_multipart(
file = curl::form_file(file_path),
string = "some text",
form_data = curl::form_data("form data")
form_data = curl::form_data("form data"),
raw_data = charToRaw("raw data")
) %>%
req_method("POST") %>%
req_perform()
Expand Down

0 comments on commit d68b18e

Please sign in to comment.