File: test-client-head.R

package info (click to toggle)
r-cran-crul 1.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,620 kB
  • sloc: sh: 13; makefile: 2
file content (55 lines) | stat: -rw-r--r-- 1,383 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
context("HttpClient: head")

test_that("head request works", {
  skip_on_cran()

  cli <- HttpClient$new(url = "https://www.google.com")
  aa <- cli$head()

  expect_is(aa, "HttpResponse")
  expect_is(aa$handle, 'curl_handle')
  expect_is(aa$content, "raw")
  expect_is(aa$method, "character")
  expect_equal(aa$method, "head")
  expect_is(aa$parse, "function")
  expect_is(aa$parse(), "character")
  expect_true(aa$success())

  # content is empty
  expect_equal(aa$content, raw(0))
})


test_that("head - query passed to head doesn't fail", {
  skip_on_cran()

  cli <- HttpClient$new(url = "https://www.google.com")
  aa <- cli$head(query = list(foo = "bar"))

  expect_is(aa, "HttpResponse")
  expect_is(aa$handle, 'curl_handle')
  expect_is(aa$content, "raw")
  expect_is(aa$method, "character")
  expect_equal(aa$method, "head")
  expect_is(aa$parse, "function")
  expect_true(aa$success())
  expect_match(aa$request$url$url, "foo")
  expect_match(aa$request$url$url, "bar")

  # content is empty
  expect_equal(aa$content, raw(0))
})


test_that("with auth works", {
  skip_on_cran()

  cli <- HttpClient$new(url = hb(), auth = auth("foo", "bar"))
  aa <- cli$head("/basic-auth/foo/bar")

  expect_is(aa, "HttpResponse")
  expect_equal(aa$method, "head")
  expect_true(aa$success())
  expect_equal(aa$status_code, 200)
  expect_equal(aa$request$options$userpwd, "foo:bar")
})