|
| 1 | +test_that("Request to MPC using httr2", { |
| 2 | + # get the URL |
| 3 | + url <- .source_url(source = "MPC") |
| 4 | + resp <- .try( |
| 5 | + { |
| 6 | + .get_request(url) |
| 7 | + }, |
| 8 | + .default = NULL |
| 9 | + ) |
| 10 | + testthat::expect_s3_class( |
| 11 | + resp, "httr2_response" |
| 12 | + ) |
| 13 | + testthat::expect_equal( |
| 14 | + .response_is_error(resp), FALSE |
| 15 | + ) |
| 16 | + testthat::expect_equal( |
| 17 | + .response_status(resp), 200 |
| 18 | + ) |
| 19 | + testthat::expect_s3_class( |
| 20 | + .response_check_status(resp), "httr2_response" |
| 21 | + ) |
| 22 | + testthat::expect_equal( |
| 23 | + class(.response_content(resp)), "list" |
| 24 | + ) |
| 25 | + testthat::expect_equal( |
| 26 | + .response_content_type(resp), "application/json" |
| 27 | + ) |
| 28 | +}) |
| 29 | + |
| 30 | +test_that("Request with RETRY to MPC using httr2", { |
| 31 | + # get the URL |
| 32 | + url <- .source_url(source = "MPC") |
| 33 | + resp <- .try( |
| 34 | + { |
| 35 | + .retry_request(url) |
| 36 | + }, |
| 37 | + .default = NULL |
| 38 | + ) |
| 39 | + testthat::expect_s3_class( |
| 40 | + resp, "httr2_response" |
| 41 | + ) |
| 42 | + testthat::expect_equal( |
| 43 | + .response_is_error(resp), FALSE |
| 44 | + ) |
| 45 | + testthat::expect_equal( |
| 46 | + .response_status(resp), 200 |
| 47 | + ) |
| 48 | + testthat::expect_s3_class( |
| 49 | + .response_check_status(resp), "httr2_response" |
| 50 | + ) |
| 51 | + |
| 52 | + testthat::expect_error( |
| 53 | + .retry_request(paste0(url, "/error")) |
| 54 | + ) |
| 55 | +}) |
| 56 | + |
| 57 | +test_that("URL utilities", { |
| 58 | + # get the URL |
| 59 | + url <- .source_url(source = "MPC") |
| 60 | + parsed_url <- .url_parse(url) |
| 61 | + |
| 62 | + testthat::expect_s3_class( |
| 63 | + parsed_url, "httr2_url" |
| 64 | + ) |
| 65 | + |
| 66 | + parsed_url$query <- list(a = 1, b = 2) |
| 67 | + url_new <- .url_build(parsed_url) |
| 68 | + testthat::expect_equal( |
| 69 | + class(url_new), "character" |
| 70 | + ) |
| 71 | + testthat::expect_equal( |
| 72 | + grepl("?a=1&b=2", url_new), TRUE |
| 73 | + ) |
| 74 | +}) |
0 commit comments