File: test-req.R

package info (click to toggle)
r-cran-httr2 1.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,604 kB
  • sloc: sh: 21; makefile: 2
file content (31 lines) | stat: -rw-r--r-- 1,044 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
test_that("req has basic print method", {
  expect_snapshot({
    req <- request("https://example.com")
    req
    req %>% req_body_raw("Test")
    req %>% req_body_multipart("Test" = 1)
  })
})

test_that("printing headers works with {}", {
  expect_snapshot(req_headers(request("http://test"), x  = "{z}", `{z}` = "x"))
})

test_that("individually prints repeated headers", {
  expect_snapshot(request("https://example.com") %>% req_headers(A = 1:3))
})

test_that("print method obfuscates Authorization header unless requested", {
  req <- request("https://example.com") %>%
    req_auth_basic("user", "SECRET")
  output <- testthat::capture_messages(print(req))
  expect_false(any(grepl("SECRET", output, fixed = TRUE)))

  output <- testthat::capture_messages(print(req, redact_headers = FALSE))
  expect_true(any(grepl("Authorization: \"Basic", output, fixed = TRUE)))
  expect_false(any(grepl("REDACTED", output, fixed = TRUE)))
})

test_that("check_request() gives useful error", {
  expect_snapshot(check_request(1), error = TRUE)
})