File: test-paths.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 (49 lines) | stat: -rw-r--r-- 1,244 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
47
48
49
context("paths")

test_that("paths work", {
  skip_on_cran()

  cli <- HttpClient$new(url = hb())
  aa <- cli$get(path = 'get')

  expect_is(aa, "HttpResponse")
  urlsp <- strsplit(aa$url, "/")[[1]]
  expect_equal(urlsp[length(urlsp)], "get")
  expect_equal(aa$status_code, 200)
})

test_that("path - multiple route paths work", {
  skip_on_cran()

  cli <- HttpClient$new(url = hb())
  bb <- cli$get('status/200')

  expect_is(bb, "HttpResponse")
  urlsp <- strsplit(bb$url, "/")[[1]]
  expect_equal(urlsp[4:5], c('status', '200'))
  expect_equal(bb$status_code, 200)
})

test_that("path - paths don't work if paths already on URL", {
  skip_on_cran()

  cli <- HttpClient$new(url = hb("/get/adsfasdf"))
  bb <- cli$get('stuff')

  expect_is(bb, "HttpResponse")
  expect_equal(bb$status_code, 404)
  expect_true(grepl("stuff", bb$url))
  expect_false(grepl("adsfasdf", bb$url))
})

test_that("path - work with routes that have spaces", {
  skip_on_cran()
  skip_on_os("windows")

  cli <- HttpClient$new(url = "http://www.marinespecies.org")
  bb <- cli$get('rest/AphiaRecordsByName/Platanista gangetica')

  expect_is(bb, "HttpResponse")
  urlsp <- strsplit(bb$url, "/")[[1]]
  expect_equal(urlsp[length(urlsp)], 'Platanista%20gangetica')
})