with_mock_dir("Correct-structure-aimsdata", {
test_that("Correct structure", {
# default to 1000 returns next_page link
check_wa <- aims_data("weather", filters = valid_weather_filters(),
api_key = null_api_key())
check_sa <- aims_data("temp_loggers", filters = valid_tlogger_filters(),
api_key = null_api_key())
expect_is(check_wa, "data.frame")
expect_true(all(c("metadata", "citation", "parameters") %in%
names(attributes(check_wa))))
expect_s3_class(check_wa, "aimsdf")
# larger size removed links from output
check_wb <- aims_data("weather", filters = valid_weather_filters(),
api_key = null_api_key())
check_sb <- aims_data("temp_loggers", filters = tlogger_filters_no_size(),
api_key = null_api_key())
expect_is(check_sa, "data.frame")
expect_true(all(c("metadata", "citation", "parameters") %in%
names(attributes(check_sa))))
expect_is(check_wb, "data.frame")
expect_true(all(c("metadata", "citation", "parameters") %in%
names(attributes(check_wb))))
expect_is(check_sb, "data.frame")
expect_true(all(c("metadata", "citation", "parameters") %in%
names(attributes(check_sb))))
expect_s3_class(check_sa, "aimsdf")
expect_s3_class(check_wb, "aimsdf")
expect_s3_class(check_sb, "aimsdf")
})
})
with_mock_dir("Wrong-filters-aimsdata", {
test_that("Wrong filters", {
check_wc <- aims_data("weather", filters = invalid_weather_filters_series(),
api_key = null_api_key())
check_wd <- aims_data("weather", filters = invalid_weather_filters_dates(),
api_key = null_api_key())
check_tc <- aims_data(
"temp_loggers", filters = invalid_weather_filters_series(),
api_key = null_api_key()
)
check_td <- aims_data(
"temp_loggers", filters = invalid_weather_filters_dates(),
api_key = null_api_key()
)
expect_null(check_wc)
expect_null(check_wd)
expect_null(check_tc)
expect_null(check_td)
})
})
with_mock_dir("summary-requests-aimsdata", {
test_that("summary requests", {
expect_message(aims_data("temp_loggers", filters = valid_tlogger_filters(),
api_key = null_api_key(), summary = "daily"))
expect_error(expect_message(aims_data(
"weather", api_key = null_api_key(), summary = "summary-by-series"
)))
expect_error(expect_message(aims_data(
"weather", api_key = null_api_key(), summary = "summary-by-deployment"
)))
expect_message(expect_is(aims_data(
"temp_loggers", api_key = null_api_key(), summary = "summary-by-series"
), "data.frame"))
expect_message(expect_is(aims_data(
"temp_loggers", api_key = null_api_key(),
summary = "summary-by-deployment"
), "data.frame"))
})
})
with_mock_dir("Fake-bad-connection-aimsdata", {
test_that("Fake bad connection", {
Sys.setenv("NETWORK_UP" = FALSE)
expect_message(aims_data("weather", api_key = null_api_key(),
summary = "summary-by-deployment"),
"internet connection")
Sys.setenv("NETWORK_UP" = TRUE)
})
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.