From 4bd0c2337574c8026442495e8bfeb29b3fdc15df Mon Sep 17 00:00:00 2001 From: salvafern Date: Wed, 19 Apr 2023 16:06:20 +0200 Subject: [PATCH] fix: polish error msg, tests, code --- R/01_gaz_search.R | 141 +++++++++--------- R/02_gaz_relations.R | 40 +++-- R/03_gaz_sources.R | 65 ++++---- R/utils.R | 6 +- man/gaz_rest_sources.Rd | 6 + man/gaz_sources.Rd | 6 + real-tests/testthat/test-gaz.R | 48 +++++- real-tests/testthat/test-prod.R | 5 +- .../api/rest/bysource/Victor+Scarabino.json | 5 + .../gaz/api/rest/relations/49243-8ef451.R | 9 ++ tests/testthat/gaz/api/rest/sourceid/53.json | 6 + tests/testthat/gaz/api/rest/toname/49243.json | 3 + tests/testthat/test-gaz.R | 42 +++++- tests/testthat/test-prod.R | 5 +- 14 files changed, 247 insertions(+), 140 deletions(-) create mode 100644 tests/testthat/gaz/api/rest/bysource/Victor+Scarabino.json create mode 100644 tests/testthat/gaz/api/rest/relations/49243-8ef451.R create mode 100644 tests/testthat/gaz/api/rest/sourceid/53.json create mode 100644 tests/testthat/gaz/api/rest/toname/49243.json diff --git a/R/01_gaz_search.R b/R/01_gaz_search.R index e071aeb..0267250 100644 --- a/R/01_gaz_search.R +++ b/R/01_gaz_search.R @@ -161,7 +161,7 @@ gaz_rest_record_by_mrgid <- function(mrgid, with_geometry = FALSE, rdf = FALSE){ # Add more info to error message if 404 not found if(httr2::resp_status(resp) == 404){ httr2::resp_check_status(resp, c( - "i" = glue::glue("The MRGID <{mrgid}> does not exists.") + "i" = glue::glue("The MRGID <{mrgid}> does not exist.") )) } @@ -269,7 +269,7 @@ gaz_rest_records_by_name <- function(name, with_geometry = FALSE, typeid = NULL, # Check status: first offset should be 200 if(httr2::resp_is_error(resp)){ - # If first is 404, either the typeID is not correct or the name does not exists + # If first is 404, either the typeID is not correct or the name does not exist if(httr2::resp_status(resp) == 404){ # base msg @@ -283,7 +283,7 @@ gaz_rest_records_by_name <- function(name, with_geometry = FALSE, typeid = NULL, msg <- c(msg, "i" = glue::glue("The term '{name}' may not be available for the selected type."), "*" = "Try with `typeid = NULL`." - ) + ) httr2::resp_check_status(resp, info = msg) } @@ -311,52 +311,51 @@ gaz_rest_records_by_name <- function(name, with_geometry = FALSE, typeid = NULL, # In any other case of error, abort and return the HTTP error httr2::resp_check_status(resp) - }else{ - - # If all ok, continue with first offset - resp <- resp %>% - httr2::resp_body_json() %>% - dplyr::bind_rows() + } - # End if there are no more records - if(nrow(resp) < 100){ - resp <- resp %>% dplyr::arrange(MRGID) + # If all ok, continue with first offset + resp <- resp %>% + httr2::resp_body_json() %>% + dplyr::bind_rows() - if(with_geometry){ - resp <- resp %>% gaz_add_geometry() - } + # End if there are no more records + if(nrow(resp) < 100){ + resp <- resp %>% dplyr::arrange(MRGID) - return(resp) + if(with_geometry){ + resp <- resp %>% gaz_add_geometry() } - # Enter infinite loop - while(TRUE){ - offset <- offset + 100 - resp_n <- gaz_records_by_name_at(offset) - http_status <- httr2::resp_status(resp_n) + return(resp) + } - if(httr2::resp_is_error(resp_n) & http_status != 404){ - # Sanity check - httr2::resp_check_status(resp_n) - } + # Enter infinite loop + while(TRUE){ + offset <- offset + 100 + resp_n <- gaz_records_by_name_at(offset) + http_status <- httr2::resp_status(resp_n) - if(http_status == 404){ - # End of the loop - resp <- resp %>% dplyr::arrange(MRGID) + if(httr2::resp_is_error(resp_n) & http_status != 404){ + # Sanity check + httr2::resp_check_status(resp_n) + } - if(with_geometry) resp <- resp %>% gaz_add_geometry() + if(http_status == 404){ + # End of the loop + resp <- resp %>% dplyr::arrange(MRGID) - return(resp) - } + if(with_geometry) resp <- resp %>% gaz_add_geometry() + return(resp) + } - # If no errors and not 404, continue with pagination - resp <- resp_n %>% - httr2::resp_body_json() %>% - dplyr::bind_rows(resp) - } + # If no errors and not 404, continue with pagination + resp <- resp_n %>% + httr2::resp_body_json() %>% + dplyr::bind_rows(resp) } + } @@ -469,7 +468,7 @@ gaz_rest_records_by_lat_long <- function(latitude, longitude, with_geometry = FA # Check status: first offset should be 200 if(httr2::resp_is_error(resp)){ - # If first is 404, either the typeID is not correct or the name does not exists + # If first is 404, either the typeID is not correct or the name does not exist if(httr2::resp_status(resp) == 404){ # base msg @@ -493,15 +492,37 @@ gaz_rest_records_by_lat_long <- function(latitude, longitude, with_geometry = FA # In any other case of error, abort and return the HTTP error httr2::resp_check_status(resp) - }else{ + } + # If all ok, continue with first offset + resp <- resp %>% + httr2::resp_body_json() %>% + dplyr::bind_rows() + + # End if there are no more records + if(nrow(resp) < 100){ + resp <- resp %>% dplyr::arrange(MRGID) - # If all ok, continue with first offset - resp <- resp %>% - httr2::resp_body_json() %>% - dplyr::bind_rows() + if(with_geometry){ + resp <- resp %>% gaz_add_geometry() + } + + return(resp) + } + + # If 100 rows or more, enter infinite loop + while(TRUE){ + + offset <- offset + 100 + resp_n <- get_records_by_lat_long_at(offset) + http_status <- httr2::resp_status(resp_n) + + if(httr2::resp_is_error(resp_n) & http_status != 404){ + # Sanity check + httr2::resp_check_status(resp_n) + } - # End if there are no more records - if(nrow(resp) < 100){ + if(http_status == 404){ + # End of the loop resp <- resp %>% dplyr::arrange(MRGID) if(with_geometry){ @@ -511,36 +532,16 @@ gaz_rest_records_by_lat_long <- function(latitude, longitude, with_geometry = FA return(resp) } - # If 100 rows or more, enter infinite loop - while(TRUE){ - - offset <- offset + 100 - resp_n <- get_records_by_lat_long_at(offset) - http_status <- httr2::resp_status(resp_n) - - if(httr2::resp_is_error(resp_n) & http_status != 404){ - # Sanity check - httr2::resp_check_status(resp_n) - } + # If no errors and not 404, continue with pagination + resp <- resp_n %>% + httr2::resp_body_json() %>% + dplyr::bind_rows(resp) - if(http_status == 404){ - # End of the loop - resp <- resp %>% dplyr::arrange(MRGID) + } - if(with_geometry){ - resp <- resp %>% gaz_add_geometry() - } +} - return(resp) - } - # If no errors and not 404, continue with pagination - resp <- resp_n %>% - httr2::resp_body_json() %>% - dplyr::bind_rows(resp) - } - } -} diff --git a/R/02_gaz_relations.R b/R/02_gaz_relations.R index b416855..e15db08 100644 --- a/R/02_gaz_relations.R +++ b/R/02_gaz_relations.R @@ -26,7 +26,6 @@ #' # Or using its mrgid #' gaz_relations(3293) #' } - gaz_relations <- function(x, ...){ UseMethod("gaz_relations") } @@ -83,23 +82,6 @@ gaz_rest_relations_by_mrgid <- function(mrgid, with_geometry = FALSE, direction mrgid <- checkmate::assert_integerish(mrgid, lower = 1, any.missing = FALSE, null.ok = TRUE, coerce = TRUE, len = 1) - # Extra info for status 404 not found - .is_error <- function(resp){ - if(httr2::resp_status(resp) == 404){ - httr2::resp_check_status(resp, info = c( - "i" = glue::glue("MRGID: <{mrgid}>"), - "i" = glue::glue("type: `{type}`"), - "i" = glue::glue("direction: `{direction}`") - )) - } - - if(httr2::resp_is_error(resp)){ - TRUE - }else{ - FALSE - } - } - # Perform resp <- marineregions.org() %>% httr2::request() %>% @@ -109,9 +91,23 @@ gaz_rest_relations_by_mrgid <- function(mrgid, with_geometry = FALSE, direction httr2::req_url_query(direction = direction, type = type) %>% httr2::req_user_agent(mr_user_agent) %>% httr2::req_headers(accept = "application/json") %>% - httr2::req_error(is_error = .is_error) %>% - httr2::req_perform() %>% - httr2::resp_body_json() %>% + httr2::req_error(is_error = function(resp) FALSE) %>% + httr2::req_perform() + + # Sanity check + if(httr2::resp_is_error(resp)){ + if(httr2::resp_status(resp) == 404){ + assert_mrgid_exists(mrgid) + + httr2::resp_check_status(resp, info = c("x" = glue::glue( + 'No relations found for MRGID <{mrgid}> with `direction` = "{direction}" and `type` = "{type}".' + ))) + } + httr2::resp_check_status(resp) + } + + # Continue if ok + resp <- httr2::resp_body_json(resp) %>% dplyr::bind_rows() if(with_geometry){ @@ -119,5 +115,5 @@ gaz_rest_relations_by_mrgid <- function(mrgid, with_geometry = FALSE, direction } resp - } + diff --git a/R/03_gaz_sources.R b/R/03_gaz_sources.R index cabb4df..7a5ed93 100644 --- a/R/03_gaz_sources.R +++ b/R/03_gaz_sources.R @@ -78,7 +78,7 @@ gaz_rest_records_by_source <- function(source, with_geometry = FALSE){ httr2::req_error(is_error = function(resp) FALSE) %>% httr2::req_perform() - # If error 404, either a wrong source was provided or there are no records for that source. + # If error 404, a wrong source was provided if(httr2::resp_is_error(resp)){ if(httr2::resp_status(resp) == 404){ @@ -100,11 +100,10 @@ gaz_rest_records_by_source <- function(source, with_geometry = FALSE){ httr2::resp_body_json() %>% dplyr::bind_rows() + # Sanity check + # This service returns 200 and "[]" when there are no records if(nrow(resp) == 0){ - cli::cli_abort(c( - "!" = "There are no MRGIDs for this source.", - "i" = "Source: {.val {source}}" - )) + cli::cli_abort(c("!" = 'No records found for {.arg source} = {.val {source}}')) } if(with_geometry){ @@ -113,9 +112,6 @@ gaz_rest_records_by_source <- function(source, with_geometry = FALSE){ resp } -# src <- "Van Eck, B.T.M. (Ed.) (1999). De Scheldeatlas: een beeld van een estuarium. Rijksinstituut voor Kust en Zee/Schelde InformatieCentrum: Middelburg. ISBN 90-369-3434-6. 120 pp." -# gaz_rest_records_by_source(src) -# gaz_rest_records_by_source("this is not a source") #' Get all the Marine Regions sources @@ -126,6 +122,9 @@ gaz_rest_records_by_source <- function(source, with_geometry = FALSE){ #' - `sourceURL`: if available, the URL of the source. #' @export #' +#' @details +#' gaz_search() is a memoised function from gaz_rest_search(). See [memoise::memoise()]. +#' #' @seealso [gaz_rest], [gaz_search_by_source()], [gaz_rest_records_by_source()], [gaz_rest_source_by_sourceid()] #' #' @examples \dontrun{ @@ -134,6 +133,9 @@ gaz_rest_records_by_source <- function(source, with_geometry = FALSE){ #' #' # is the same as #' gaz_sources() +#' +#' memoise::is.memoised(gaz_sources) +#' #> [1] TRUE #' } gaz_rest_sources <- function(){ sourceID <- NULL @@ -158,36 +160,36 @@ gaz_rest_sources <- function(){ if(httr2::resp_is_error(resp)){ httr2::resp_check_status(resp) - }else{ + } - resp <- resp %>% - httr2::resp_body_json() %>% - dplyr::bind_rows() + resp <- resp %>% + httr2::resp_body_json() %>% + dplyr::bind_rows() - # Enter infinite loop - while(TRUE){ - offset <- offset + 100 - resp_n <- get_source_at(offset) - http_status <- httr2::resp_status(resp_n) + # Enter infinite loop + while(TRUE){ + offset <- offset + 100 + resp_n <- get_source_at(offset) + http_status <- httr2::resp_status(resp_n) - if(httr2::resp_is_error(resp_n) & http_status != 404){ - # Sanity check - httr2::resp_check_status(resp_n) - } + if(httr2::resp_is_error(resp_n) & http_status != 404){ + # Sanity check + httr2::resp_check_status(resp_n) + } - if(http_status == 404){ - # End of the loop - resp <- resp %>% dplyr::arrange(sourceID) - return(resp) - } + if(http_status == 404){ + # End of the loop + resp <- resp %>% dplyr::arrange(sourceID) + return(resp) + } - # If no errors and not 404, continue with pagination - resp <- resp_n %>% - httr2::resp_body_json() %>% - dplyr::bind_rows(resp) - } + # If no errors and not 404, continue with pagination + resp <- resp_n %>% + httr2::resp_body_json() %>% + dplyr::bind_rows(resp) } + } #' @name gaz_sources @@ -226,4 +228,3 @@ gaz_rest_source_by_sourceid <- function(sourceid){ } - diff --git a/R/utils.R b/R/utils.R index 7cc7838..5a7f0c0 100644 --- a/R/utils.R +++ b/R/utils.R @@ -30,7 +30,7 @@ gaz_rest_names_by_mrgid <- function(mrgid){ # Add more info to error message if 404 not found if(httr2::resp_status(resp) == 404){ httr2::resp_check_status(resp, c( - "x" = glue::glue("The MRGID <{mrgid}> does not exists.") + "x" = glue::glue("The MRGID <{mrgid}> does not exist.") )) } @@ -196,3 +196,7 @@ marineregions.org <- function(){ getOption("marineregions.url", "https://marineregions.org/") } +assert_mrgid_exists <- function(mrgid){ + gaz_rest_names_by_mrgid(mrgid) + invisible(NULL) +} diff --git a/man/gaz_rest_sources.Rd b/man/gaz_rest_sources.Rd index f2e5741..e1c85cf 100644 --- a/man/gaz_rest_sources.Rd +++ b/man/gaz_rest_sources.Rd @@ -17,6 +17,9 @@ a data frame with three columns: \description{ Get all the Marine Regions sources } +\details{ +gaz_search() is a memoised function from gaz_rest_search(). See \code{\link[memoise:memoise]{memoise::memoise()}}. +} \examples{ \dontrun{ # This @@ -24,6 +27,9 @@ gaz_rest_sources() # is the same as gaz_sources() + +memoise::is.memoised(gaz_sources) +#> [1] TRUE } } \seealso{ diff --git a/man/gaz_sources.Rd b/man/gaz_sources.Rd index ac67bd4..2cd3321 100644 --- a/man/gaz_sources.Rd +++ b/man/gaz_sources.Rd @@ -17,6 +17,9 @@ a data frame with three columns: \description{ Get all the Marine Regions sources } +\details{ +gaz_search() is a memoised function from gaz_rest_search(). See \code{\link[memoise:memoise]{memoise::memoise()}}. +} \examples{ \dontrun{ # This @@ -24,6 +27,9 @@ gaz_rest_sources() # is the same as gaz_sources() + +memoise::is.memoised(gaz_sources) +#> [1] TRUE } } \seealso{ diff --git a/real-tests/testthat/test-gaz.R b/real-tests/testthat/test-gaz.R index b063ba3..a88bb44 100644 --- a/real-tests/testthat/test-gaz.R +++ b/real-tests/testthat/test-gaz.R @@ -25,7 +25,7 @@ mvb <- 30666 # only centroid rocks_placetype <- 193 # Perform - +# httptest2::with_mock_dir("gaz", { test_that("gaz_search.numeric", { gaz_search(17) %>% expect_mr() gaz_search(c(14, 17), rdf = TRUE) %>% expect_s3_class("rdf") @@ -97,6 +97,15 @@ rocks_placetype <- 193 gaz_search_by_source("Belgian Sea Fisheries") %>% expect_mr() gaz_search_by_source("This is not a source") %>% expect_error() + + gaz_search_by_source(53) %>% + expect_error(regexp = "No records", fixed = TRUE) + + .f <- function(){ + httr2::with_mock(mock_500, + gaz_rest_records_by_source("Belgian Sea Fisheries")) + } + expect_error(.f(), regexp = "500", fixed = TRUE) }) test_that("gaz_sources",{ @@ -130,8 +139,29 @@ rocks_placetype <- 193 gaz_relations(type = "partof", direction = "upper") %>% expect_mr() - .f <- function() httr2::with_mock(mock_404, gaz_search(b24nm)) - expect_error(.f(), regexp = "does not exists", fixed = TRUE) + .f <- function() gaz_relations(b24nm, type = "fake type") + expect_error(.f(), regexp = "Assertion", fixed = TRUE) + + .f <- function() gaz_relations(b24nm, type = c("partof", "administrativepartof")) + expect_error(.f(), regexp = "Assertion", fixed = TRUE) + + .f <- function() gaz_relations(b24nm, type = 1) + expect_error(.f(), regexp = "Assertion", fixed = TRUE) + + .f <- function() gaz_relations(b24nm, direction = "fake direction") + expect_error(.f(), regexp = "Assertion", fixed = TRUE) + + .f <- function() gaz_relations(b24nm, direction = c("lower", "upper")) + expect_error(.f(), regexp = "Assertion", fixed = TRUE) + + .f <- function() gaz_relations(b24nm, direction = 1) + expect_error(.f(), regexp = "Assertion", fixed = TRUE) + + .f <- function() gaz_relations(b24nm, type = "influencedby", direction = "lower") + expect_error(.f(), regexp = "No relations found", fixed = TRUE) + + .f <- function() httr2::with_mock(mock_404, gaz_relations(b24nm)) + expect_error(.f(), regexp = "does not exist", fixed = TRUE) }) @@ -227,5 +257,15 @@ rocks_placetype <- 193 expect_error(.f()) .f <- function() gaz_rest_names_by_mrgid(999999999) - expect_error(.f(), regexp = "does not exists", fixed = TRUE) + expect_error(.f(), regexp = "does not exist", fixed = TRUE) + + .f <- function() assert_mrgid_exists(3293) + expect_invisible(.f()) + + .f <- function() assert_mrgid_exists(999999999) + expect_error(.f(), regexp = "does not exist", fixed = TRUE) }) + +# }, simplify = TRUE) + + diff --git a/real-tests/testthat/test-prod.R b/real-tests/testthat/test-prod.R index 5f51e57..6f856e8 100644 --- a/real-tests/testthat/test-prod.R +++ b/real-tests/testthat/test-prod.R @@ -4,9 +4,6 @@ .f <- function() mrp_get("eez", filter="") expect_error(.f(), "XML getFeature request SAX parsing error") - .f <- function() mrp_get("eez", filter="") - expect_error(.f(), "XML getFeature request SAX parsing error") - .f <- function(){ mrp_get("eez", filter=" @@ -117,7 +114,7 @@ expect_s3_class(sf::st_geometry(x), "sfc_MULTILINESTRING") # Expect errors - .f <- function() mrp_get("this product does not exists") + .f <- function() mrp_get("this product does not exist") expect_error(.f()) .f <- function() mrp_get("ecs_boundaries", cql_filter = "this is not a good filter") diff --git a/tests/testthat/gaz/api/rest/bysource/Victor+Scarabino.json b/tests/testthat/gaz/api/rest/bysource/Victor+Scarabino.json new file mode 100644 index 0000000..b5ec18f --- /dev/null +++ b/tests/testthat/gaz/api/rest/bysource/Victor+Scarabino.json @@ -0,0 +1,5 @@ +[ + [ + + ] +] diff --git a/tests/testthat/gaz/api/rest/relations/49243-8ef451.R b/tests/testthat/gaz/api/rest/relations/49243-8ef451.R new file mode 100644 index 0000000..a97b843 --- /dev/null +++ b/tests/testthat/gaz/api/rest/relations/49243-8ef451.R @@ -0,0 +1,9 @@ +structure(list(method = "GET", url = "api/rest/relations//49243/?direction=lower&type=influencedby", + status_code = 404L, headers = structure(list(date = "Wed, 19 Apr 2023 12:36:50 GMT", + server = "Apache/2.4.53 (Win64)", `content-security-policy` = "upgrade-insecure-requests; script-src * 'unsafe-inline' 'unsafe-eval' blob:; object-src *; frame-ancestors 'self' www.vliz.be vliz.be;", + `cross-origin-opener-policy` = "same-origin", `access-control-allow-origin` = "*", + `access-control-allow-headers` = "X-Requested-With, Content-Type, Accept, Origin, Authorization", + `access-control-allow-methods` = "GET, POST, OPTIONS", + `content-length` = "2", `content-type` = "application/json; charset=UTF-8;", + `set-cookie` = "vliz_webc=vliz_webc1; path=/", connection = "keep-alive"), class = "httr2_headers"), + body = charToRaw("[]")), class = "httr2_response") diff --git a/tests/testthat/gaz/api/rest/sourceid/53.json b/tests/testthat/gaz/api/rest/sourceid/53.json new file mode 100644 index 0000000..e68bf51 --- /dev/null +++ b/tests/testthat/gaz/api/rest/sourceid/53.json @@ -0,0 +1,6 @@ +[ + { + "source": "Victor Scarabino", + "url": "http://www.vliz.be/en/imis?module=person&persid=18777" + } +] diff --git a/tests/testthat/gaz/api/rest/toname/49243.json b/tests/testthat/gaz/api/rest/toname/49243.json new file mode 100644 index 0000000..511cd32 --- /dev/null +++ b/tests/testthat/gaz/api/rest/toname/49243.json @@ -0,0 +1,3 @@ +[ + "Belgian 24 NM" +] diff --git a/tests/testthat/test-gaz.R b/tests/testthat/test-gaz.R index 408c91c..f76348b 100644 --- a/tests/testthat/test-gaz.R +++ b/tests/testthat/test-gaz.R @@ -97,6 +97,15 @@ httptest2::with_mock_dir("gaz", { gaz_search_by_source("Belgian Sea Fisheries") %>% expect_mr() gaz_search_by_source("This is not a source") %>% expect_error() + + gaz_search_by_source(53) %>% + expect_error(regexp = "No records", fixed = TRUE) + + .f <- function(){ + httr2::with_mock(mock_500, + gaz_rest_records_by_source("Belgian Sea Fisheries")) + } + expect_error(.f(), regexp = "500", fixed = TRUE) }) test_that("gaz_sources",{ @@ -130,8 +139,29 @@ httptest2::with_mock_dir("gaz", { gaz_relations(type = "partof", direction = "upper") %>% expect_mr() - .f <- function() httr2::with_mock(mock_404, gaz_search(b24nm)) - expect_error(.f(), regexp = "does not exists", fixed = TRUE) + .f <- function() gaz_relations(b24nm, type = "fake type") + expect_error(.f(), regexp = "Assertion", fixed = TRUE) + + .f <- function() gaz_relations(b24nm, type = c("partof", "administrativepartof")) + expect_error(.f(), regexp = "Assertion", fixed = TRUE) + + .f <- function() gaz_relations(b24nm, type = 1) + expect_error(.f(), regexp = "Assertion", fixed = TRUE) + + .f <- function() gaz_relations(b24nm, direction = "fake direction") + expect_error(.f(), regexp = "Assertion", fixed = TRUE) + + .f <- function() gaz_relations(b24nm, direction = c("lower", "upper")) + expect_error(.f(), regexp = "Assertion", fixed = TRUE) + + .f <- function() gaz_relations(b24nm, direction = 1) + expect_error(.f(), regexp = "Assertion", fixed = TRUE) + + .f <- function() gaz_relations(b24nm, type = "influencedby", direction = "lower") + expect_error(.f(), regexp = "No relations found", fixed = TRUE) + + .f <- function() httr2::with_mock(mock_404, gaz_relations(b24nm)) + expect_error(.f(), regexp = "does not exist", fixed = TRUE) }) @@ -227,7 +257,13 @@ httptest2::with_mock_dir("gaz", { expect_error(.f()) .f <- function() gaz_rest_names_by_mrgid(999999999) - expect_error(.f(), regexp = "does not exists", fixed = TRUE) + expect_error(.f(), regexp = "does not exist", fixed = TRUE) + + .f <- function() assert_mrgid_exists(3293) + expect_invisible(.f()) + + .f <- function() assert_mrgid_exists(999999999) + expect_error(.f(), regexp = "does not exist", fixed = TRUE) }) }, simplify = TRUE) diff --git a/tests/testthat/test-prod.R b/tests/testthat/test-prod.R index 3431c0b..1b54326 100644 --- a/tests/testthat/test-prod.R +++ b/tests/testthat/test-prod.R @@ -199,9 +199,6 @@ httptest2::with_mock_dir("prod/fail/", { .f <- function() mrp_get("eez", filter="") expect_error(.f(), "XML getFeature request SAX parsing error") - .f <- function() mrp_get("eez", filter="") - expect_error(.f(), "XML getFeature request SAX parsing error") - .f <- function(){ mrp_get("eez", filter=" @@ -312,7 +309,7 @@ httptest::with_mock_dir("prod/ok/", { expect_s3_class(sf::st_geometry(x), "sfc_MULTILINESTRING") # Expect errors - .f <- function() mrp_get("this product does not exists") + .f <- function() mrp_get("this product does not exist") expect_error(.f()) .f <- function() mrp_get("ecs_boundaries", cql_filter = "this is not a good filter")