Skip to content

Commit

Permalink
pass along errors from GeoCDL and start testing #22
Browse files Browse the repository at this point in the history
  • Loading branch information
HeatherSavoy-USDA committed Mar 6, 2023
1 parent 6c2b546 commit 0bad7dd
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 8 deletions.
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ Imports:
RoxygenNote: 7.2.0
Suggests:
knitr,
rmarkdown
rmarkdown,
testthat (>= 3.0.0)
VignetteBuilder: knitr
Config/testthat/edition: 3
4 changes: 2 additions & 2 deletions R/upload_geometry.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ upload_geometry <- function(geom, tmp_dir = tempdir()) {
# Check for error status code
if(httr::http_error(guid_r)){
stop(paste('GeoCDL returned an error:',
httr::http_status(guid_r)$message,
httr::content(guid_r)))
httr::http_status(guid_r)$message, '\n',
httr::content(guid_r)$detail))
}

# Extract geometry upload ID
Expand Down
6 changes: 3 additions & 3 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,14 @@ submit_subset_query <- function(query_str, dsn, req_name){
subset_response <- httr::GET(query_str[q],
httr::write_disk(subset_zip,
overwrite=TRUE))

# Check for bad request / errors
if(httr::http_error(subset_response)){
stop(paste('GeoCDL returned an error:',
httr::http_status(subset_response)$message,
httr::content(subset_response)))
httr::http_status(subset_response)$message, '\n',
httr::content(subset_response)$detail))
}


# Unzip results to temporary file
utils::unzip(subset_zip,
exdir = subset_dir)
Expand Down
9 changes: 7 additions & 2 deletions R/view_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ view_metadata <- function(ds) {
# Get response from REST API
md_response <- httr::GET(md_query)

# Check for bad request / errors

# Convert from JSON and return list
md_parsed <- httr::content(md_response)

# Check for bad request / errors
if(httr::http_error(md_response)){
stop(paste('GeoCDL returned an error:',
httr::http_status(md_response)$message, '\n',
md_parsed$detail))
}

# Format list into text
cat(paste0('Name: ', md_parsed$name, '\n',
'ID: ', md_parsed$id, '\n',
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file is part of the standard setup for testthat.
# It is recommended that you do not modify it.
#
# Where should you do additional test configuration?
# Learn more about the roles of various files in:
# * https://r-pkgs.org/tests.html
# * https://testthat.r-lib.org/reference/test_package.html#special-files

library(testthat)
library(rgeocdl)

test_check("rgeocdl")
4 changes: 4 additions & 0 deletions tests/testthat/test-upload_geometry.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test_that("unsupported geometries return GeoCDL message", {
expect_condition(upload_geometry('test'),
'No uploaded polygon data found for GUID ')
})
6 changes: 6 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test_that("invalid datasets return GeoCDL message", {
expect_condition(submit_subset_query('10.1.1.80:8000/subset_polygon?datasets=PRISM',
dsn = '.',
req_name = ''),
'Incorrect dataset specification')
})
3 changes: 3 additions & 0 deletions tests/testthat/test-view_metadata.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_that("invalid datasets return GeoCDL message", {
expect_condition(view_metadata('PRIS'),'Invalid dataset ID')
})

0 comments on commit 0bad7dd

Please sign in to comment.