beaumontmeteo/tests/testthat/test-getStationData.R

37 lines
889 B
R

testthat::skip_if_not(
identical(tolower(Sys.getenv("BEAUMONT_RUN_LIVE_API_TESTS", "false")), "true"),
"Set BEAUMONT_RUN_LIVE_API_TESTS=true to run live Meteo France API tests."
)
testthat::skip_if_not(
file.exists(file.path("data", "secrets")),
"Live API tests require data/secrets."
)
library(httr)
source(file.path("R", "request.R"))
source(file.path("R", "getStationData.R"))
secret_env <- new.env(parent = baseenv())
sys.source(file.path("data", "secrets"), envir = secret_env)
headers.default <- add_headers(
accept = "*/*",
apikey = secret_env$token2
)
test_that("get station return something right", {
test <- getStationData(
start_date = "2024-06-24",
end_date = "2024-08-14",
station_id = "38269004",
headers = headers.default
)
if (!is.null(test)) {
testthat::expect_length(test, 3)
} else {
testthat::expect_null(test)
}
})