Skip to content

Commit

Permalink
fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
John Waller committed Jan 4, 2024
1 parent 910ef6c commit 1051a72
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 30 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export(dataset_comment)
export(dataset_constituents)
export(dataset_contact)
export(dataset_doi)
export(dataset_duplicate)
export(dataset_endpoint)
export(dataset_export)
export(dataset_get)
Expand All @@ -39,6 +40,7 @@ export(dataset_identifier)
export(dataset_machinetag)
export(dataset_metrics)
export(dataset_networks)
export(dataset_noendpoint)
export(dataset_process)
export(dataset_search)
export(dataset_suggest)
Expand Down
2 changes: 1 addition & 1 deletion R/dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#'
#' @export
#'
#' @examples \dontrun {
#' @examples \dontrun{
#' dataset(limit=3)
#' dataset(country="US",limit=3)
#' dataset(type="CHECKLIST",limit=3)
Expand Down
16 changes: 7 additions & 9 deletions R/dataset_list_funs.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#' List datasets that are deleted or have no endpoint.
#'
#' @name dataset_list_funs.R
#'
#' @param limit Controls the number of results in the page.
#' @param start Determines the start for the search results.
Expand All @@ -12,28 +11,27 @@
#' Get a list of deleted datasets or datasets with no endpoint. You get the full
#' and no parameters aside from `limit` and `start` are accepted.
#'
#' @export
#'
#' @examples \dontrun {
#'
#' @examples \dontrun{
#' dataset_noendpoint(limit=3)
#' }

#' @name dataset_list_funs.R
#' @name dataset_list_funs
#' @export
dataset_duplicate <- function(limit=20,start=NULL,curlopts=list()) {
dataset_list_get_(endpoint="duplicate",limit=limit,start=start,
dataset_list_get_(endpoint="duplicate/",limit=limit,start=start,
curlopts=curlopts,meta=TRUE)

Check warning on line 23 in R/dataset_list_funs.R

View check run for this annotation

Codecov / codecov/patch

R/dataset_list_funs.R#L22-L23

Added lines #L22 - L23 were not covered by tests
}

#' @name dataset_list_funs.R
#' @name dataset_list_funs
#' @export
dataset_noendpoint <- function(limit=20,start=NULL,curlopts=list()) {
dataset_list_get_(endpoint="withNoEndpoint",limit=limit,start=start,
dataset_list_get_(endpoint="withNoEndpoint/",limit=limit,start=start,
curlopts=curlopts,meta=TRUE)
}

dataset_list_get_ <- function(endpoint,limit=NULL,start=NULL,curlopts,meta) {
url <- paste0(gbif_base(),"/dataset/",endpoint,"/")
url <- paste0(gbif_base(),"/dataset/",endpoint)
if(!is.null(limit)) {
args <- rgbif_compact(c(limit=limit,offset=start))
tt <- gbif_GET(url, args, TRUE, curlopts)
Expand Down
3 changes: 1 addition & 2 deletions R/dataset_uuid_funs.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#' Get dataset metadata using a datasetkey
#'
#' @name dataset_uuid_funs
#' @param uuid A GBIF datasetkey uuid.
#' @param limit Number of records to return.
#' @param start Record number to start at.
Expand Down Expand Up @@ -96,7 +95,7 @@ dataset_tag <- function(uuid = NULL, curlopts = list()) {
#' @name dataset_uuid_funs
#' @export
dataset_metrics <- function(uuid = NULL, curlopts = list()) {
if(!is_uuid(uuid)) warn("'uuid' should be a GBIF datasetkey uuid.")
if(!is_uuid(uuid)) stop("'uuid' should be a GBIF datasetkey uuid.")

Check warning on line 98 in R/dataset_uuid_funs.R

View check run for this annotation

Codecov / codecov/patch

R/dataset_uuid_funs.R#L98

Added line #L98 was not covered by tests
if(!dataset_get(uuid)$type == "CHECKLIST") stop("Dataset should be a checklist.")
url <- paste0(gbif_base(),"/dataset/",uuid,"/metrics")
res <- rgbif_compact(gbif_GET(url, args = NULL, TRUE, curlopts))
Expand Down
65 changes: 49 additions & 16 deletions man/dataset.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions man/dataset_list_funs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/test-dataset_list_funs.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ test_that("dataset_list_funs work as expected.", {
e <- dataset_noendpoint(limit=3)
})

expect_is(e,"tbl_df")
expect_is(e,"list")
expect_named(e,c("meta","data"))
expect_is(e$data$key,"character")
expect_lte(nrow(e), 3)
expect_lte(nrow(e$data), 3)

})

0 comments on commit 1051a72

Please sign in to comment.