tests/testthat/test-internals.R

context("test-internals.R")

api_unavailable <- function(){
  resp1 <- httr::GET(url = "https://nrfaapps.ceh.ac.uk/nrfa/ws/time-series", 
                     query = list(format = "json-object", station = 39001,`data-type` = "gdf"), 
                     httr::user_agent("https://github.com/ilapros/rnrfa"))
  resp2 <- httr::GET(url = "https://nrfaapps.ceh.ac.uk/nrfa/ws/time-series", 
                     query = list(format = "json-object", station = 39001,`data-type` = "cmr"), 
                     httr::user_agent("https://github.com/ilapros/rnrfa"))
  # if any of the two streams is not working skip tests 
  (httr::http_error(resp1) | httr::http_error(resp2))
}



test_that("internal fails when it should", {
  skip_if(api_unavailable(), "API not available")
  parameters <- list(format = "json-object", station = "*", fields = "all")
  response <- try(nrfa_api(webservice = "stations-info", parameters),
                  silent = TRUE)
  expect_equal(class(response), "try-error")
})

Try the rnrfa package in your browser

Any scripts or data that you put into this service are public.

rnrfa documentation built on June 22, 2024, 11:14 a.m.