Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix betydb tests #123

Merged
merged 3 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/betydb.R
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ betydb_experiment <- function(id, api_version = NULL, betyurl = NULL, fmt = "jso

betydb_auth <- function(user,pwd,key){
if (is.null(key) && is.null(user)) {
key <- getOption("betydb_key", '9999999999999999999999999999999999999999')
key <- getOption("betydb_key", 'eI6TMmBl3IAb7v4ToWYzR0nZYY07shLiCikvT6Lv')
}
if (!is.null(key)) {
auth <- list(key = key)
Expand Down
34 changes: 8 additions & 26 deletions tests/testthat/test-betydb.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,13 @@ test_that("Broken Function", {
expect_error(betydb_traits(genus = "Miscanthus", author = "Arundale", trait = "yield"))
})

test_that("BETYdb v0 API works", {
test_that("BETYdb v1 API works", {
skip_on_cran()
check_betydb()

## gh-18
betyurl <- "https://www.betydb.org/"
priors_url <- makeurl("priors", fmt = "json", betyurl = betyurl)
expect_equal(priors_url, paste0(betyurl, "priors.json"))

# Priors is a small table
get.out <- GET(paste0(priors_url, "/?key=eI6TMmBl3IAb7v4ToWYzR0nZYY07shLiCikvT6Lv"))
expect_is(get.out, "response")
expect_match(httr::headers(get.out)$status, "OK")
expect_match(get.out$url, betyurl)
})

test_that("BETYdb beta API works", {
skip_on_cran()
check_betydb()

betyurl <- "https://www.betydb.org/"
priors_url <- makeurl("priors", fmt = "json", betyurl = betyurl, api_version = "beta")
expect_equal(priors_url, paste0(betyurl, "api/beta/priors.json"))
priors_url <- makeurl("priors", fmt = "json", betyurl = betyurl, api_version = "v1")
expect_equal(priors_url, paste0(betyurl, "api/v1/priors.json"))

get.out <- GET(paste0(priors_url, "/?key=eI6TMmBl3IAb7v4ToWYzR0nZYY07shLiCikvT6Lv")) # Priors is a small table
expect_is(get.out, "response")
Expand All @@ -42,15 +26,15 @@ test_that("table to property name matching works", {

getprop <- function(name){
txt <- betydb_http(
makeurl(name, fmt = "json", betyurl = "https://www.betydb.org/", api_version = "beta"),
makeurl(name, fmt = "json", betyurl = "https://www.betydb.org/", api_version = "v1"),
args = list(limit = 1),
key = NULL,
user = NULL,
pwd = NULL)
names(jsonlite::fromJSON(txt, simplifyVector = TRUE, flatten = FALSE)$data)[[1]]
}
tablenames <- c("search", "species", "entities", "citations", "pfts")
expected_propnames <- sapply(tablenames, makepropname, api_version = "beta")
expected_propnames <- sapply(tablenames, makepropname, api_version = "v1")
got_propnames <- sapply(tablenames, getprop)

expect_equal(got_propnames, expected_propnames)
Expand All @@ -77,10 +61,8 @@ test_that("Credentials work", {

prevkey <- options(betydb_key = "NOTVALID")
on.exit(options(prevkey))
# FIXME - should use v0 API for symmetry w/ other calls,
# but v0 skips auth for search table
options(betydb_key = 'NOT A KEY')
expect_error(betydb_search("Acer rubrum", api_version = "beta"), "Unauthorized",
expect_error(betydb_search("Acer rubrum", api_version = "v1"), "Unauthorized",
class = "error")
options(betydb_key = "eI6TMmBl3IAb7v4ToWYzR0nZYY07shLiCikvT6Lv")
optkey <- betydb_search('Acer rubrum')
Expand All @@ -104,7 +86,7 @@ test_that("URL & version options work", {
betydb_api_version = "v0")
opt1 <- betydb_query(author = "Arundale", table = "citations")

options(betydb_url = "http://example.com/", betydb_api_version = "beta")
options(betydb_url = "http://example.com/", betydb_api_version = "v1")
expect_error(betydb_query(author = "Arundale", table = "citations"),
"Not Found", class = "error")
opt2 <- betydb_query(author = "Arundale", table = "citations",
Expand Down Expand Up @@ -138,7 +120,7 @@ test_that("paging works with betydb query and search functions",{
on.exit(reset_opts(opts))
options(
betydb_url = "https://www.betydb.org/",
betydb_api_version = "beta",
betydb_api_version = "v1",
betydb_key = "eI6TMmBl3IAb7v4ToWYzR0nZYY07shLiCikvT6Lv",
per_call_limit = 10, # check paging without a 5000-item request
warn=-1 ## suppress warnings that we did not get all data
Expand Down