context("Validate functionality in creating urls for get requests")
test_url <- create_url("sources", list())
resp <- httr::GET(test_url)
if (httr::http_error(resp)) {
stop("Newsapi request failed ", httr::status_code(resp))
call. = FALSE
} else {
cat("dowloading...\n")
test_url <- jsonlite::fromJSON(httr::content(resp, "text"))
cat("finished dowloading...\n")
}
test_that("Validate content of GET request for empty list. Would break if content is changing",
{
skip_on_cran()
expect_true(as.character(unique(test_url[[2]][5])) == "c(\"general\", \"business\", \"technology\", \"sports\", \"entertainment\", \"health\", \"science\")")
expect_true(as.character(unique(test_url[[2]][6])) == "c(\"en\", \"no\", \"it\", \"ar\", \"ud\", \"de\", \"pt\", \"es\", \"fr\", \"he\", \"ru\", \"se\", \"nl\", \"zh\")")
expect_true(as.character(unique(test_url[[2]][7])) == "c(\"us\", \"au\", \"no\", \"it\", \"sa\", \"pk\", \"gb\", \"de\", \"br\", \"ca\", \"es\", \"ar\", \"fr\", \"in\", \"is\", \"ru\", \"se\", \"za\", \"ie\", \"nl\", \"zh\")")
})
test_url_general <- create_url("sources", list(category = "general"))
resp <- httr::GET(test_url_general)
if (httr::http_error(resp)) {
stop("Newsapi request failed ", httr::status_code(resp))
call. = FALSE
} else {
cat("dowloading...\n")
test_url_general <- jsonlite::fromJSON(httr::content(resp, "text"))
cat("finished dowloading...\n")
}
test_that("Validate content of GET request for category source", {
skip_on_cran()
expect_true(unique(test_url_general[[2]][5]) == "general")
})
test_url_general_ru <- create_url("sources", list(category = "general", country = "ru"))
resp <- httr::GET(test_url_general_ru)
if (httr::http_error(resp)) {
stop("Newsapi request failed ", httr::status_code(resp))
call. = FALSE
} else {
cat("dowloading...\n")
test_url_general_ru <- jsonlite::fromJSON(httr::content(resp, "text"))
cat("finished dowloading...\n")
}
test_that("Validate content of GET reques for category and country", {
skip_on_cran()
expect_true(unique(test_url_general_ru[[2]][5]) == "general")
expect_true(unique(test_url_general_ru[[2]][5]) %in% "general" && unique(test_url_general_ru[[2]][6]) %in%
c("ru"))
})
test_url_general_ru_ru <- create_url("sources", list(category = "general", country = "ru",
language = "ru"))
resp <- httr::GET(test_url_general_ru_ru)
if (httr::http_error(resp)) {
stop("Newsapi request failed ", httr::status_code(resp))
call. = FALSE
} else {
cat("dowloading...\n")
test_url_general_ru_ru <- jsonlite::fromJSON(httr::content(resp, "text"))
cat("finished dowloading...\n")
}
test_that("Validate content of GET request", {
skip_on_cran()
expect_true(unique(test_url_general_ru_ru[[2]][5]) == "general")
expect_true(unique(test_url_general_ru_ru[[2]][5]) %in% "general" &&
unique(test_url_general_ru_ru[[2]][6]) %in% c("ru"))
expect_true(unique(test_url_general_ru_ru[[2]][5]) %in% "general" &&
unique(test_url_general_ru_ru[[2]][6]) %in% c("ru") && unique(test_url_general_ru_ru[[2]][7]) %in%
c("ru"))
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.