File: test-HttpInteractionList.R

package info (click to toggle)
r-cran-vcr 0.2.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 596 kB
  • sloc: sh: 13; makefile: 2
file content (46 lines) | stat: -rw-r--r-- 1,475 bytes parent folder | download
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
context("HTTPInteractionList")

test_that("HTTPInteractionList", {
  crul::mock(FALSE)

  url <- "https://eu.httpbin.org/post"
  body <- list(foo = "bar")
  cli <- crul::HttpClient$new(url = url)
  res <- cli$post(body = body)

  # request
  request <- Request$new("POST", uri = url,
    body = body, headers = res$response_headers)
  # response
  response <- VcrResponse$new(
     res$status_http(),
     res$response_headers,
     res$parse("UTF-8"),
     res$response_headers$status)

  # make HTTPInteraction object
  inter <- HTTPInteraction$new(request = request, response = response)

  # make HTTPInteractionList object
  x <- suppressMessages(HTTPInteractionList$new(
     interactions = list(inter),
     request_matchers = vcr_configuration()$match_requests_on
  ))

  # objects and methods
  expect_is(x$request_matchers, "character")
  expect_equal(x$request_matchers, c('method', 'uri'))
  ## parent list
  expect_is(x$parent_list, "NullList")
  expect_null(x$parent_list$response_for())
  expect_false(x$parent_list$has_interaction_matching())
  expect_false(x$parent_list$has_used_interaction_matching())
  expect_equal(x$parent_list$remaining_unused_interaction_count(), 0)

  expect_is(x$used_interactions, "list")
  expect_false(x$allow_playback_repeats)
  expect_is(x$interactions, "list")
  expect_is(x$interactions[[1]], "HTTPInteraction")
  expect_is(x$response_for, "function")
  expect_is(suppressWarnings(x$response_for(request)), "VcrResponse")
})