44 lines
1.2 KiB
R
44 lines
1.2 KiB
R
test_that("sourced getStationData handles request failure without attached httr", {
|
|
helper_env <- new.env(parent = globalenv())
|
|
sys.source(testthat::test_path("..", "..", "R", "getStationData.R"), envir = helper_env)
|
|
|
|
helper_env$request_api <- function(...) NULL
|
|
|
|
expect_null(
|
|
helper_env$getStationData(
|
|
start_date = "2024-01-01",
|
|
end_date = "2024-01-02",
|
|
station_id = "12345678",
|
|
headers = list(),
|
|
timesleep = 0
|
|
)
|
|
)
|
|
})
|
|
|
|
|
|
test_that("getAllFromCoord returns NULL when every station fetch fails", {
|
|
helper_env <- new.env(parent = globalenv())
|
|
sys.source(testthat::test_path("..", "..", "R", "getAllFromCoord.R"), envir = helper_env)
|
|
|
|
helper_env$getIdFromCoords <- function(...) {
|
|
data.frame(
|
|
Id_station = c("1001", "1002"),
|
|
Nom_usuel = c("Station A", "Station B"),
|
|
stringsAsFactors = FALSE
|
|
)
|
|
}
|
|
|
|
helper_env$getStationData <- function(...) NULL
|
|
|
|
expect_null(
|
|
helper_env$getAllFromCoord(
|
|
coord = c(44.85, 5.84),
|
|
start_date = "2024-01-01",
|
|
end_date = "2024-01-02",
|
|
allstations = data.frame(),
|
|
headers = list(),
|
|
btw_station_sleep = 0,
|
|
within_statio_sleep = 0
|
|
)
|
|
)
|
|
})
|