Skip to content

Commit

Permalink
Merge pull request #53 from iDigBio/update-docs
Browse files Browse the repository at this point in the history
Resume testing on MacOS and specify HTTP/2
  • Loading branch information
jbennettufl authored Sep 3, 2024
2 parents 62db0d5 + f723390 commit 0399e26
Show file tree
Hide file tree
Showing 26 changed files with 366 additions and 80 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
^docs$
^pkgdown$
^\.github$
^doc$
^Meta$
22 changes: 21 additions & 1 deletion .github/workflows/R-Git-Check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
Expand All @@ -35,6 +36,12 @@ jobs:
R_KEEP_PKG_SOURCE: yes

steps:
- name: Install specific version of curl (macOS)
if: runner.os == 'macOS'
run: |
brew reinstall curl # Adjust version as needed
brew link --force curl
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2
Expand All @@ -44,11 +51,24 @@ jobs:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check
cache-version: "no-cache"

# Install remotes package to handle versioned installations
- name: Install remotes package
if: runner.os == 'macOS'
run: |
R -e "install.packages('remotes')"
# Install r-curl 5.2.2 from CRAN Archive using remotes
- name: Install r-curl 5.2.2 from CRAN Archive
if: runner.os == 'macOS'
run: |
R -e "remotes::install_version('curl', '5.2.2')"
- uses: r-lib/actions/check-r-package@v2
with:
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
ridigbio.Rproj
.DS_Store
inst/doc
docs
docs
/doc/
/Meta/
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: ridigbio
Title: Interface to the iDigBio Data API
Version: 0.3.9
Date: 2024-8-19
Version: 0.4.0
Date: 2024-9-3
Encoding: UTF-8
Authors@R: c(person("Francois", "Michonneau", comment="Original Author", role=c("aut", "cph"),
email="[email protected]"),
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
ridigbio 0.4.0
===========
### Enhancements
* Offline build capability added

ridigbio 0.3.9
===========

Expand Down
30 changes: 21 additions & 9 deletions R/base.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,27 @@ idig_parse <- function(req) {
##' @return nothing. Stops if HTTP code is >= 400
##' @author Francois Michonneau
idig_check <- function(req) {
if (req$status_code >= 400) {
msg <- substr(req, 1, 200)
stop("HTTP failure: ", req$status_code, "\n",
"Error message from API server: ", msg,
call. = FALSE
)
}
idig_check_error(req)
tryCatch(
{
if (req$status_code >= 400) {
msg <- substr(req, 1, 200)
stop("HTTP failure: ", req$status_code, "\n",
"Error message from API server: ", msg,
call. = FALSE
)
}
idig_check_error(req)
},
error = function(e) {
warning("Error during API request: ", e$message)
msg <- substr(req, 1, 200)
stop("HTTP failure: ", req$status_code, "\n",
"Error message from API server: ", msg,
call. = FALSE
)
idig_check_error(req)
}
)
}

##' Checks for error messages that can be returned by the API in JSON.
Expand Down Expand Up @@ -110,7 +123,6 @@ idig_POST <- function(path, body, ...) {
httr::content_type_json(), ...
)
idig_check(req)

req
}

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ library("ridigbio")
idig_search_records(rq=list(genus="galax"))
idig_search_records(rq=list(family="diapensiaceae"), limit=1000)
```

# Meta

* [Please report any bugs or issues.](https://github.com/iDigBio/ridigbio/issues)
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-base.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ context("test GET")

test_that("list of all top-level fields returned in JSON", {
testthat::skip_on_cran()
testthat::skip_if_offline()
getReq <- list(rq = jsonlite::toJSON(list(family = "holothuriidae")))
r <- idig_GET("search/records", query = getReq)

Expand All @@ -16,6 +17,7 @@ context("test POST")

test_that("list of all top-level fields returned in JSON", {
testthat::skip_on_cran()
testthat::skip_if_offline()
fm <- list(rq = list(family = "holothuriidae"))
r <- idig_POST("search/records", body = fm)

Expand All @@ -25,6 +27,7 @@ test_that("list of all top-level fields returned in JSON", {

test_that("400 errors print messages", {
testthat::skip_on_cran()
testthat::skip_if_offline()

expect_error(
idig_search_records(rq = list("asdf" = "asdf")),
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-idig_build_attrib.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ context("test idig_build_attrib")

test_that("attribution dataframe built from results dataframe and item counts match", {
testthat::skip_on_cran()
testthat::skip_if_offline()

testQuery <- idig_search_records(rq = list(family = "holothuriidae"))
df <- idig_build_attrib(testQuery)
Expand All @@ -11,6 +12,7 @@ test_that("attribution dataframe built from results dataframe and item counts ma

test_that("limited results, attribution counts match limit and result counts", {
testthat::skip_on_cran()
testthat::skip_if_offline()

df <- idig_search_records(rq = list(genus = "acer"), limit = 10)
tt <- idig_build_attrib(df)
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-idig_count_media.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ dqs <- 0

test_that("all media records is a large number", {
testthat::skip_on_cran()
testthat::skip_if_offline()

num <- idig_count_media()

expect_that(num, is_a("integer"))
Expand All @@ -14,6 +16,8 @@ test_that("all media records is a large number", {

test_that("rq searches on the endpoint is a small number", {
testthat::skip_on_cran()
testthat::skip_if_offline()

num <- idig_count_media(rq = list("recordset" = recordset))

expect_that(num, is_a("integer"))
Expand All @@ -22,6 +26,8 @@ test_that("rq searches on the endpoint is a small number", {

test_that("mq searches on the endpoint is a small number", {
testthat::skip_on_cran()
testthat::skip_if_offline()

num <- idig_count_media(mq = list("dqs" = dqs))

expect_that(num, is_a("integer"))
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-idig_count_records.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ recordset <- "7450a9e3-ef95-4f9e-8260-09b498d2c5e6"

test_that("all records is a large number", {
testthat::skip_on_cran()
testthat::skip_if_offline()

num <- idig_count_records()

expect_that(num, is_a("integer"))
Expand All @@ -13,6 +15,8 @@ test_that("all records is a large number", {

test_that("rq searches on the endpoint is a small number", {
testthat::skip_on_cran()
testthat::skip_if_offline()

num <- idig_count_records(rq = list("recordset" = recordset))

expect_that(num, is_a("integer"))
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-idig_meta_fields.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ context("test idig_meta_fields")

test_that("records field list returns", {
testthat::skip_on_cran()
testthat::skip_if_offline()

f <- idig_meta_fields()

expect_that(f, is_a("list"))
Expand All @@ -12,6 +14,8 @@ test_that("records field list returns", {

test_that("records indexed subset returns", {
testthat::skip_on_cran()
testthat::skip_if_offline()

f <- idig_meta_fields(subset = "indexed")

expect_null(f[["data"]])
Expand All @@ -21,6 +25,8 @@ test_that("records indexed subset returns", {

test_that("records raw subset returns", {
testthat::skip_on_cran()
testthat::skip_if_offline()

f <- idig_meta_fields(subset = "raw")

expect_null(f[["uuid"]])
Expand All @@ -29,6 +35,8 @@ test_that("records raw subset returns", {

test_that("media list returns", {
testthat::skip_on_cran()
testthat::skip_if_offline()

f <- idig_meta_fields(type = "media")

expect_that(f, is_a("list"))
Expand All @@ -39,6 +47,8 @@ test_that("media list returns", {

test_that("media indexed subset returns", {
testthat::skip_on_cran()
testthat::skip_if_offline()

f <- idig_meta_fields(type = "media", subset = "indexed")

expect_null(f[["data"]])
Expand All @@ -48,6 +58,8 @@ test_that("media indexed subset returns", {

test_that("media raw subset returns", {
testthat::skip_on_cran()
testthat::skip_if_offline()

f <- idig_meta_fields(type = "media", subset = "raw")

expect_null(f[["uuid"]])
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-idig_search_media.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ u <- "00d96710-77dd-492c-9d5c-095a8cf9ee5a"

test_that("full results for rq searches return", {
testthat::skip_on_cran()
testthat::skip_if_offline()

df <- idig_search_media(rq = rq, limit = 6000)

expect_that(df, is_a("data.frame"))
Expand All @@ -20,6 +22,8 @@ test_that("full results for rq searches return", {

test_that("full results for rq & mq queries together return", {
testthat::skip_on_cran()
testthat::skip_if_offline()

df <- idig_search_media(rq = rq, mq = mq, limit = 6000)

expect_that(df, is_a("data.frame"))
Expand All @@ -29,6 +33,8 @@ test_that("full results for rq & mq queries together return", {

test_that("full results for mq queries return", {
testthat::skip_on_cran()
testthat::skip_if_offline()

df <- idig_search_media(mq = mq, limit = 6000)
u <- "00003b7d-07fb-4c36-a81a-18f7cde49203"

Expand All @@ -41,6 +47,8 @@ test_that("full results for mq queries return", {

test_that("limits and custom fields return", {
testthat::skip_on_cran()
testthat::skip_if_offline()

df <- idig_search_media(mq = mq, fields = fields, limit = 10)

expect_true(nrow(df) == 10)
Expand Down
16 changes: 16 additions & 0 deletions tests/testthat/test-idig_search_records.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ fields <- c("uuid", "genus", "specificepithet", "data.dwc:occurrenceID")

test_that("basic search, full results works", {
testthat::skip_on_cran()
testthat::skip_if_offline()

df <- idig_search_records(rq = rq, limit = 6000)

expect_that(df, is_a("data.frame"))
Expand All @@ -18,6 +20,8 @@ test_that("basic search, full results works", {

test_that("limited results, custom fields works", {
testthat::skip_on_cran()
testthat::skip_if_offline()

df <- idig_search_records(rq = rq, fields = fields, limit = 10)

expect_true(nrow(df) == 10)
Expand All @@ -29,6 +33,7 @@ test_that("limited results, custom fields works", {

test_that("offset works", {
testthat::skip_on_cran()
testthat::skip_if_offline()

df <- idig_search_records(rq = rq, fields = fields, limit = 2, offset = 0)
second_uuid <- df[["uuid"]][[2]]
Expand All @@ -40,6 +45,8 @@ test_that("offset works", {

test_that("sorting works", {
testthat::skip_on_cran()
testthat::skip_if_offline()

df <- idig_search_records(rq = rq, fields = fields, limit = 1)

expect_true(substr(df[["uuid"]], 1, 2) == "00")
Expand All @@ -56,6 +63,7 @@ test_that("sorting works", {

test_that("max items disabled is thrown for large queries", {
testthat::skip_on_cran()
testthat::skip_if_offline()

expect_that(
df <- idig_search_records(rq = list("country" = "united states")),
Expand All @@ -65,6 +73,7 @@ test_that("max items disabled is thrown for large queries", {

test_that("max items disabled is thrown for windows past 100k", {
testthat::skip_on_cran()
testthat::skip_if_offline()

expect_that(
df <- idig_search_records(
Expand All @@ -77,6 +86,7 @@ test_that("max items disabled is thrown for windows past 100k", {

test_that("can get the 100000th result", {
testthat::skip_on_cran()
testthat::skip_if_offline()

df <- idig_search_records(
rq = list("country" = "united states"),
Expand All @@ -87,13 +97,17 @@ test_that("can get the 100000th result", {

test_that("all fields returns a lot of fields", {
testthat::skip_on_cran()
testthat::skip_if_offline()

df <- idig_search_records(rq = rq, fields = "all", limit = 10)

expect_true(ncol(df) > 50)
})

test_that("empty results return empty df with correct columns", {
testthat::skip_on_cran()
testthat::skip_if_offline()

df <- idig_search_records(rq = list("uuid" = "nobodyhome"), fields = fields)

expect_true(nrow(df) == 0)
Expand All @@ -102,6 +116,8 @@ test_that("empty results return empty df with correct columns", {

test_that("geopoint and special fields are expanded or excluded as appropriate", {
testthat::skip_on_cran()
testthat::skip_if_offline()

fields_special <- c("uuid", "geopoint", "mediarecords", "flags", "recordids")
df <- idig_search_records(
rq = list("uuid" = "f84faea8-82ac-4f71-b256-6b2be5d1b59d"),
Expand Down
Loading

0 comments on commit 0399e26

Please sign in to comment.