-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added oai fxn tests, made id param in getrecord mandatory
- Loading branch information
Showing
10 changed files
with
207 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,13 @@ | ||
#' List available metadata formats that the DataCite repository can disseminate | ||
#' | ||
#' @export | ||
#' @param id DataCite identifier, e.g., "56225" | ||
#' @param id DataCite identifier, e.g., "oai:oai.datacite.org:6718729". If left | ||
#' blank, get all metadataformats | ||
#' @param ... Curl options passed on to \code{\link[httr]{GET}} | ||
#' @examples \dontrun{ | ||
#' dc_oai_listmetadataformats() | ||
#' dc_oai_listmetadataformats("56225") | ||
#' dc_oai_listmetadataformats("oai:oai.datacite.org:6718729") | ||
#' } | ||
dc_oai_listmetadataformats <- function(id = NULL, ...) { | ||
if (!is.null(id)) { | ||
oaiid <- paste("oai:oai.datacite.org:", id, sep = "") | ||
} else { | ||
oaiid <- NULL | ||
} | ||
oai::list_metadataformats(dc_oai_base(), oaiid, ...) | ||
oai::list_metadataformats(dc_oai_base(), id, ...) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
context("dc_oai_getrecord") | ||
|
||
test_that("dc_oai_getrecord - basic functionality works", { | ||
skip_on_cran() | ||
|
||
aa <- dc_oai_getrecord("oai:oai.datacite.org:32255") | ||
|
||
expect_is(aa, "data.frame") | ||
expect_is(aa, "oai_df") | ||
expect_is(aa$identifier, "character") | ||
expect_is(aa$title, "character") | ||
}) | ||
|
||
test_that("dc_oai_getrecord - many record Ids input works", { | ||
skip_on_cran() | ||
|
||
recs <- c("oai:oai.datacite.org:32255", "oai:oai.datacite.org:32325") | ||
aa <- dc_oai_getrecord(recs) | ||
|
||
expect_is(aa, "data.frame") | ||
expect_is(aa, "oai_df") | ||
expect_is(aa$identifier, "character") | ||
expect_is(aa$title, "character") | ||
expect_equal(NROW(aa), 2) | ||
expect_equal(aa$identifier, recs) | ||
}) | ||
|
||
test_that("dc_oai_getrecord fails well", { | ||
skip_on_cran() | ||
|
||
expect_error(dc_oai_getrecord(), | ||
"argument \"id\" is missing, with no default") | ||
expect_error(dc_oai_getrecord('5000000000000asfaffs'), | ||
"is unknown or illegal in this repository") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
context("dc_oai_identify") | ||
|
||
test_that("dc_oai_identify - default uses datacite", { | ||
skip_on_cran() | ||
|
||
aa <- dc_oai_identify() | ||
|
||
expect_is(aa, "data.frame") | ||
expect_match(aa$repositoryName, "DataCite") | ||
expect_match(aa$baseURL, "oai.datacite.org") | ||
}) | ||
|
||
test_that("dc_oai_identify - httr options work", { | ||
skip_on_cran() | ||
|
||
library("httr") | ||
expect_error(dc_oai_identify(config = timeout(0.01))) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
context("dc_oai_listidentifiers") | ||
|
||
test_that("dc_oai_listidentifiers - from", { | ||
skip_on_cran() | ||
|
||
aa <- dc_oai_listidentifiers(from = "2015-09-03T00:00:00Z", until="2015-09-03T00:30:00Z") | ||
|
||
expect_is(aa, "data.frame") | ||
expect_is(aa, "oai_df") | ||
expect_is(aa$identifier, "character") | ||
expect_is(aa$datestamp, "character") | ||
expect_equal(as.character(as.Date(aa$datestamp[1])), "2015-09-03") | ||
}) | ||
|
||
test_that("dc_oai_listidentifiers - from & until", { | ||
skip_on_cran() | ||
|
||
aa <- dc_oai_listidentifiers(from = '2015-09-03T00:00:00Z', until = '2015-09-03T00:30:00Z') | ||
bb <- dc_oai_listidentifiers(from = '2015-09-03T00:30:00Z', until = '2015-09-03T01:15:00Z') | ||
|
||
expect_is(aa, "oai_df") | ||
expect_is(bb, "oai_df") | ||
|
||
expect_less_than(NROW(aa), NROW(bb)) | ||
}) | ||
|
||
test_that("dc_oai_listidentifiers - set", { | ||
skip_on_cran() | ||
|
||
aa <- dc_oai_listidentifiers(from = '2011-06-01T', until = '2011-11-01T', set = "ANDS") | ||
bb <- dc_oai_listidentifiers(from = '2011-06-01T', until = '2012-11-01T', set = "CDL.OSU") | ||
|
||
expect_is(aa, "oai_df") | ||
expect_is(bb, "oai_df") | ||
|
||
expect_equal(aa$setSpec[1], "ANDS") | ||
expect_equal(bb$setSpec[1], "CDL") | ||
}) | ||
|
||
test_that("dc_oai_listidentifiers fails well", { | ||
skip_on_cran() | ||
|
||
no_msg <- "The combination of the values of the from, until, set, and metadataPrefix arguments results in an empty list" | ||
|
||
expect_error(dc_oai_listidentifiers(from = '2011-06-01T', until = 'adffdsadsf'), | ||
"The request includes illegal arguments") | ||
expect_error(dc_oai_listidentifiers(from = '2011-06-01T', until = 5), | ||
"The request includes illegal arguments") | ||
expect_error(dc_oai_listidentifiers(url = 5), "One or more of your URLs") | ||
expect_error(dc_oai_listidentifiers(from = '2011-06-01T', until = '2011-11-01T', set = "STUFF"), no_msg) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
context("dc_oai_listmetadataformats") | ||
|
||
test_that("dc_oai_listmetadataformats - basic functionality works", { | ||
skip_on_cran() | ||
|
||
aa <- dc_oai_listmetadataformats() | ||
|
||
expect_is(aa, "data.frame") | ||
expect_is(aa$metadataPrefix, "character") | ||
expect_is(aa$schema, "character") | ||
expect_is(aa$metadataNamespace, "character") | ||
|
||
expect_named(aa, c('metadataPrefix', 'schema', 'metadataNamespace')) | ||
}) | ||
|
||
test_that("dc_oai_listmetadataformats - no formats avail. vs. avail", { | ||
skip_on_cran() | ||
|
||
aa <- dc_oai_listmetadataformats(id = "oai:oai.datacite.org:22") | ||
bb <- dc_oai_listmetadataformats(id = "oai:oai.datacite.org:6718729") | ||
|
||
expect_null(aa[[1]]) | ||
expect_is(bb[[1]], "data.frame") | ||
}) | ||
|
||
test_that("dc_oai_listmetadataformats - curl options", { | ||
skip_on_cran() | ||
|
||
library("httr") | ||
|
||
expect_error(dc_oai_listmetadataformats(config = timeout(0.001)), "Timeout was reached") | ||
}) | ||
|
||
test_that("dc_oai_listmetadataformats fails well", { | ||
skip_on_cran() | ||
|
||
expect_null(dc_oai_listmetadataformats(id = "adfadfsdf")[[1]]) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
context("dc_oai_listrecords") | ||
|
||
test_that("dc_oai_listrecords works", { | ||
skip_on_cran() | ||
|
||
a <- dc_oai_listrecords(from = '2011-06-01T', until = '2011-07-01T') | ||
|
||
expect_is(a, "data.frame") | ||
expect_is(a, "oai_df") | ||
expect_is(a$identifier, "character") | ||
}) | ||
|
||
test_that("dc_oai_listrecords fails well", { | ||
skip_on_cran() | ||
|
||
expect_error(dc_oai_listrecords(from = '2011-06-01T', until = 'adffdsadsf'), | ||
"The request includes illegal arguments") | ||
expect_error(dc_oai_listrecords(from = '2011-06-01T', until = 5), | ||
"The request includes illegal arguments") | ||
expect_error(dc_oai_listrecords(url = 5), "One or more of your URLs") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
context("dc_oai_listsets") | ||
|
||
test_that("dc_oai_listsets", { | ||
skip_on_cran() | ||
|
||
aa <- dc_oai_listsets() | ||
|
||
expect_is(aa, "data.frame") | ||
expect_is(aa, "oai_df") | ||
expect_is(aa$setSpec, "character") | ||
expect_is(aa$setName, "character") | ||
}) | ||
|
||
test_that("dc_oai_listsets - curl options", { | ||
skip_on_cran() | ||
|
||
library("httr") | ||
|
||
expect_error(dc_oai_listsets(config = timeout(0.001)), "Timeout was reached") | ||
}) | ||
|
||
test_that("dc_oai_listsets fails well", { | ||
skip_on_cran() | ||
|
||
expect_error(dc_oai_listsets(token = 454), | ||
"The value of the resumptionToken argument is invalid or expired") | ||
expect_error(dc_oai_listsets("stuff"), | ||
"The value of the resumptionToken argument is invalid or expired") | ||
}) |