diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 588a51a2..50b90cb5 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -29,7 +29,7 @@ jobs: env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} R_KEEP_PKG_SOURCE: yes - BCDC_KEY: ${{ secrets.BCDC_KEY }} + # BCDC_KEY: ${{ secrets.BCDC_KEY }} BCDC_TEST_RECORD: ${{ secrets.BCDC_TEST_RECORD }} steps: diff --git a/DESCRIPTION b/DESCRIPTION index 7f694918..61192763 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -62,7 +62,7 @@ VignetteBuilder: knitr Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.1.9000 +RoxygenNote: 7.3.2 Collate: 'bcdata-package.R' 'bcdc-get-citation.R' diff --git a/NEWS.md b/NEWS.md index 2c07e0ff..584dfa05 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,7 @@ `local()` for local functions more restrictive; updated tests and examples (#341). * Deprecate the `bcdata.single_download_limit` option, as it was mostly redundant with `bcdata.chunk_limit`, and should always be set by the server. Please set the page size limit for paginated requests via the `bcdata.chunk_limit` option (#332) +* Updated internals to adapt to changes in B.C. Data Catalogue (#342m, #343) # bcdata 0.4.1 diff --git a/R/bcdc-get-citation.R b/R/bcdc-get-citation.R index b5cf57b0..7ff2682e 100644 --- a/R/bcdc-get-citation.R +++ b/R/bcdc-get-citation.R @@ -93,8 +93,8 @@ bcdc_get_citation.bcdc_record <- function(record) { } clean_org_name <- function(rec) { - name <- jsonlite::fromJSON(rec$contacts)$name + name <- vapply(rec$contacts, function(x) x$name, FUN.VALUE = character(1)) name <- trimws(name) name <- paste0(name, collapse = ", ") - sub(",([^,]*)$", " &\\1", name) + gsub(",([^,]*)$", " &\\1", name) } diff --git a/R/bcdc_search.R b/R/bcdc_search.R index 29ab0968..aaee28f2 100644 --- a/R/bcdc_search.R +++ b/R/bcdc_search.R @@ -14,7 +14,7 @@ #' #' @param facet the facet(s) for which to retrieve valid values. Can be one or #' more of: -#' `"license_id", "download_audience", "res_format", "sector", "organization", "groups"` +#' `"license_id", "download_audience", "res_format", "publish_state", "organization", "groups"` #' #' @return A data frame of values for the selected facet #' @export @@ -30,7 +30,7 @@ #' ) #' } bcdc_search_facets <- function(facet = c("license_id", "download_audience", - "res_format", "sector", + "res_format", "publish_state", "organization", "groups")) { if(!has_internet()) stop("No access to internet", call. = FALSE) # nocov diff --git a/R/describe-feature.R b/R/describe-feature.R index 78d73134..41a05054 100644 --- a/R/describe-feature.R +++ b/R/describe-feature.R @@ -125,14 +125,14 @@ feature_helper <- function(whse_name){ xml_df } - - obj_desc_join <- function(record) { stopifnot(inherits(record, "bcdc_record")) wfs_resource <- get_wfs_resource_from_record(record) whse_name <- wfs_resource$object_name - wfs_df <- jsonlite::fromJSON(wfs_resource$details) + wfs_df <- purrr::list_rbind( + purrr::map(wfs_resource$details, as.data.frame) + ) dplyr::left_join( feature_helper(whse_name), diff --git a/R/utils.R b/R/utils.R index 4a542bdd..e8098881 100644 --- a/R/utils.R +++ b/R/utils.R @@ -148,8 +148,10 @@ bcdc_auth <- function() { ## Check if there is internet ## h/t to https://github.com/ropensci/handlr/blob/pluralize/tests/testthat/helper-handlr.R has_internet <- function() { - z <- try(suppressWarnings(readLines('https://www.google.com', n = 1)), - silent = TRUE) + z <- try( + suppressWarnings(readLines('https://www.google.com', n = 1)), + silent = TRUE + ) !inherits(z, "try-error") } @@ -285,13 +287,15 @@ read_from_url <- function(resource, ...){ fun$package, " package.") handle_excel(tmp, ...) - tryCatch(do.call(fun$fun, list(tmp, ...)), - error = function(e) { - stop("Reading the data set failed with the following error message:\n\n ", e, - "\nThe file can be found here:\n '", - tmp, "'\nif you would like to try to read it manually.\n", - call. = FALSE) - }) +tryCatch( + do.call(fun$fun, list(tmp, ...)), + error = function(e) { + stop("Reading the data set failed with the following error message:\n\n ", e, + "\nThe file can be found here:\n '", + tmp, "'\nif you would like to try to read it manually.\n", + call. = FALSE) + } +) } @@ -305,11 +309,11 @@ resource_to_tibble <- function(x){ package_id = safe_map_chr(x, "package_id"), location = simplify_string(safe_map_chr(x, "resource_storage_location")) ) - - mutate(res_df, - wfs_available = wfs_available(res_df), - bcdata_available = wfs_available | other_format_available(res_df)) -} + + dplyr::mutate(res_df, + wfs_available = wfs_available(res_df), + bcdata_available = wfs_available | other_format_available(res_df)) + } #' @importFrom rlang "%||%" safe_map_chr <- function(x, name) { @@ -329,10 +333,13 @@ pagination_sort_col <- function(cols_df) { if (idcol %in% cols) return(idcol) } #Otherwise use the first column - this is likely pretty fragile - warning("Unable to find a suitable column to sort on for pagination. Using", - " the first column (", cols[1], - "). Please check your data for obvious duplicated or missing rows.", - call. = FALSE) + warning( + "Unable to find a suitable column to sort on for pagination. Using", + " the first column (", + cols[1], + "). Please check your data for obvious duplicated or missing rows.", + call. = FALSE + ) cols[1] } @@ -348,11 +355,15 @@ handle_zip <- function(x) { files <- list_supported_files(dir) # check if it's a shapefile - if (length(files) > 1L) { - stop("More than one supported file in zip file. It has been downloaded and ", - "extracted to '", dir, "', where you can access its contents manually.", - call. = FALSE) - } +if (length(files) > 1L) { + stop( + "More than one supported file in zip file. It has been downloaded and ", + "extracted to '", + dir, + "', where you can access its contents manually.", + call. = FALSE + ) +} files } diff --git a/man/bcdc_search_facets.Rd b/man/bcdc_search_facets.Rd index 12b3e56d..85885809 100644 --- a/man/bcdc_search_facets.Rd +++ b/man/bcdc_search_facets.Rd @@ -5,14 +5,14 @@ \title{Get the valid values for a facet (that you can use in \code{\link[=bcdc_search]{bcdc_search()}})} \usage{ bcdc_search_facets( - facet = c("license_id", "download_audience", "res_format", "sector", "organization", - "groups") + facet = c("license_id", "download_audience", "res_format", "publish_state", + "organization", "groups") ) } \arguments{ \item{facet}{the facet(s) for which to retrieve valid values. Can be one or more of: -\verb{"license_id", "download_audience", "res_format", "sector", "organization", "groups"}} +\verb{"license_id", "download_audience", "res_format", "publish_state", "organization", "groups"}} } \value{ A data frame of values for the selected facet diff --git a/tests/testthat/test-bcdc-get-citation.R b/tests/testthat/test-bcdc-get-citation.R index 3bb684b3..b6caa089 100644 --- a/tests/testthat/test-bcdc-get-citation.R +++ b/tests/testthat/test-bcdc-get-citation.R @@ -16,6 +16,6 @@ test_that("bcdc_get_citation take a character and returns a bibentry",{ rec <- bcdc_get_record(point_record) expect_s3_class(bcdc_get_citation(rec), c("citation", "bibentry")) expect_s3_class(bcdc_get_citation(point_record), c("citation", "bibentry")) - test_url <- paste0("https://catalogue.data.gov.bc.ca/dataset/", point_record) + test_url <- glue::glue("{catalogue_base_url()}/dataset/{point_record}") expect_s3_class(bcdc_get_citation(test_url), c("citation", "bibentry")) }) diff --git a/tests/testthat/test-get-data.R b/tests/testthat/test-get-data.R index 7a23188d..16b2799b 100644 --- a/tests/testthat/test-get-data.R +++ b/tests/testthat/test-get-data.R @@ -13,8 +13,10 @@ test_that("bcdc_get_data collects an sf object for a valid record and resource id", { skip_if_net_down() skip_on_cran() - bc_airports <- bcdc_get_data('76b1b7a3-2112-4444-857a-afccf7b20da8', - resource = "4d0377d9-e8a1-429b-824f-0ce8f363512c") + bc_airports <- bcdc_get_data( + '76b1b7a3-2112-4444-857a-afccf7b20da8', + resource = "4d0377d9-e8a1-429b-824f-0ce8f363512c" + ) expect_s3_class(bc_airports, "sf") expect_equal(attr(bc_airports, "sf_column"), "geometry") }) @@ -23,16 +25,40 @@ test_that("bcdc_get_data collects an sf object for a valid record and resource i test_that("bcdc_get_data works with slug and full url with corresponding resource", { skip_if_net_down() skip_on_cran() - expect_s3_class(ret1 <- bcdc_get_data("https://catalogue.data.gov.bc.ca/dataset/bc-airports", resource = "4d0377d9-e8a1-429b-824f-0ce8f363512c"), - "sf") - expect_s3_class(ret2 <- bcdc_get_data("bc-airports", resource = "4d0377d9-e8a1-429b-824f-0ce8f363512c"), - "sf") - expect_s3_class(ret3 <- bcdc_get_data("https://catalogue.data.gov.bc.ca/dataset/76b1b7a3-2112-4444-857a-afccf7b20da8", resource = "4d0377d9-e8a1-429b-824f-0ce8f363512c"), - "sf") - expect_s3_class(ret4 <- bcdc_get_data("76b1b7a3-2112-4444-857a-afccf7b20da8", resource = "4d0377d9-e8a1-429b-824f-0ce8f363512c"), - "sf") - expect_s3_class(ret5 <- bcdc_get_data("https://catalogue.data.gov.bc.ca/dataset/76b1b7a3-2112-4444-857a-afccf7b20da8/resource/4d0377d9-e8a1-429b-824f-0ce8f363512c"), - "sf") + expect_s3_class( + ret1 <- bcdc_get_data( + glue::glue("{catalogue_base_url()}/dataset/bc-airports"), + resource = "4d0377d9-e8a1-429b-824f-0ce8f363512c" + ), + "sf" + ) + expect_s3_class( + ret2 <- bcdc_get_data( + "bc-airports", + resource = "4d0377d9-e8a1-429b-824f-0ce8f363512c" + ), + "sf" + ) + expect_s3_class( + ret3 <- bcdc_get_data( + glue::glue("{catalogue_base_url()}/dataset/76b1b7a3-2112-4444-857a-afccf7b20da8"), + resource = "4d0377d9-e8a1-429b-824f-0ce8f363512c" + ), + "sf" + ) + expect_s3_class( + ret4 <- bcdc_get_data( + "76b1b7a3-2112-4444-857a-afccf7b20da8", + resource = "4d0377d9-e8a1-429b-824f-0ce8f363512c" + ), + "sf" + ) + expect_s3_class( + ret5 <- bcdc_get_data( + glue::glue("{catalogue_base_url()}/dataset/76b1b7a3-2112-4444-857a-afccf7b20da8/resource/4d0377d9-e8a1-429b-824f-0ce8f363512c") + ), + "sf" + ) for (x in list(ret2, ret3, ret4, ret5)) { expect_equal(dim(x), dim(ret1)) @@ -41,7 +67,7 @@ test_that("bcdc_get_data works with slug and full url with corresponding resourc }) -test_that("bcdc_get_data works with a non-wms record with only one resource",{ +test_that("bcdc_get_data works with a non-wms record with only one resource", { skip_if_net_down() skip_on_cran() name <- "ee9d4ee0-6a34-4dff-89e0-9add9a969168" # "criminal-code-traffic-offences" @@ -51,59 +77,83 @@ test_that("bcdc_get_data works with a non-wms record with only one resource",{ test_that("bcdc_get_data works when using read_excel arguments", { skip_if_net_down() skip_on_cran() - ret <- bcdc_get_data("2e469ff2-dadb-45ea-af9d-f5683a4b9465", - resource = "18510a60-de82-440a-b806-06fba70eaf9d", - skip = 4, n_max = 3) + ret <- bcdc_get_data( + "2e469ff2-dadb-45ea-af9d-f5683a4b9465", + resource = "18510a60-de82-440a-b806-06fba70eaf9d", + skip = 4, + n_max = 3 + ) expect_s3_class(ret, "tbl") expect_equal(nrow(ret), 3L, ignore_attr = TRUE) }) -test_that("bcdc_get_data works with an xls when specifying a specific resource",{ +test_that("bcdc_get_data works with an xls when specifying a specific resource", { skip_if_net_down() skip_on_cran() name <- 'bc-grizzly-bear-habitat-classification-and-rating' - expect_s3_class(bcdc_get_data(name, resource = '7b09f82f-e7d0-44bf-9310-b94039b323a8'), "tbl") + expect_s3_class( + bcdc_get_data(name, resource = '7b09f82f-e7d0-44bf-9310-b94039b323a8'), + "tbl" + ) }) test_that("bcdc_get_data will return non-wms resources",{ skip_if_net_down() skip_on_cran() - expect_s3_class(bcdc_get_data(record = '76b1b7a3-2112-4444-857a-afccf7b20da8', - resource = 'fcccba36-b528-4731-8978-940b3cc04f69'), "tbl") + expect_s3_class( + bcdc_get_data( + record = '76b1b7a3-2112-4444-857a-afccf7b20da8', + resource = 'fcccba36-b528-4731-8978-940b3cc04f69' + ), + "tbl" + ) - expect_s3_class(bcdc_get_data(record = 'fa542137-a976-49a6-856d-f1201adb2243', - resource = 'dc1098a7-a4b8-49a3-adee-9badd4429279'), "tbl") + expect_s3_class( + bcdc_get_data( + record = 'fa542137-a976-49a6-856d-f1201adb2243', + resource = 'dc1098a7-a4b8-49a3-adee-9badd4429279' + ), + "tbl" + ) }) test_that("bcdc_get_data works with a zipped shp file", { skip_if_net_down() skip_on_cran() - expect_s3_class(bcdc_get_data(record = '481d6d4d-a536-4df9-9e9c-7473cd2ed89e', - resource = '41c9bff0-4e25-49fc-a3e2-2a2e426ac71d'), - "sf") + expect_s3_class( + bcdc_get_data( + record = '481d6d4d-a536-4df9-9e9c-7473cd2ed89e', + resource = '41c9bff0-4e25-49fc-a3e2-2a2e426ac71d' + ), + "sf" + ) }) test_that("unknown single file (shp) inside zip", { skip_if_net_down() skip_on_cran() - expect_s3_class(bcdc_get_data("e31f7488-27fa-4330-ae86-160a0deb8a59"), - "sf") + expect_s3_class( + bcdc_get_data("e31f7488-27fa-4330-ae86-160a0deb8a59"), + "sf" + ) }) test_that("fails when resource doesn't exist", { skip_if_net_down() skip_on_cran() - expect_error(bcdc_get_data("300c0980-b5e3-4202-b0da-d816f14fadad", - resource = "not-a-real-resource"), - "The specified resource does not exist in this record") + expect_error(bcdc_get_data( + "300c0980-b5e3-4202-b0da-d816f14fadad", + resource = "not-a-real-resource" + ), "The specified resource does not exist in this record") }) test_that("fails when multiple files in a zip", { skip_if_net_down() skip_on_cran() - expect_error(bcdc_get_data("300c0980-b5e3-4202-b0da-d816f14fadad", - resource = "c212a8a7-c625-4464-b9c8-4527c843f52f"), - "More than one supported file in zip file") + expect_error(bcdc_get_data( + "300c0980-b5e3-4202-b0da-d816f14fadad", + resource = "c212a8a7-c625-4464-b9c8-4527c843f52f" + ), "More than one supported file in zip file") }) test_that("fails informatively when can't read a file", { @@ -111,24 +161,34 @@ test_that("fails informatively when can't read a file", { skip_on_cran() expect_error( suppressWarnings( - bcdc_get_data(record = '523dce9d-b464-44a5-b733-2022e94546c3', - resource = '4cc98644-f6eb-410b-9df0-f9b2beac9717') + bcdc_get_data( + record = '523dce9d-b464-44a5-b733-2022e94546c3', + resource = '4cc98644-f6eb-410b-9df0-f9b2beac9717' + ) ), "Reading the data set failed with the following error message:") }) -test_that("bcdc_get_data can return the wms resource when it is specified by resource",{ +test_that("bcdc_get_data can return the wms resource when it is specified by resource", { skip_if_net_down() skip_on_cran() - expect_s3_class(bcdc_get_data('76b1b7a3-2112-4444-857a-afccf7b20da8', - resource = "4d0377d9-e8a1-429b-824f-0ce8f363512c"), "sf") + expect_s3_class( + bcdc_get_data( + '76b1b7a3-2112-4444-857a-afccf7b20da8', + resource = "4d0377d9-e8a1-429b-824f-0ce8f363512c" + ), + "sf" + ) }) test_that("a wms record with only one resource works with only the record id",{ skip_if_net_down() skip_on_cran() - expect_s3_class(bcdc_get_data("bc-college-region-boundaries"), "sf") + expect_s3_class( + bcdc_get_data("bc-college-region-boundaries"), + "sf" + ) }) test_that("bcdc_get_data works with a bcdc_record object", { @@ -138,44 +198,66 @@ test_that("bcdc_get_data works with a bcdc_record object", { expect_s3_class(bcdc_get_data(record), "sf") record <- bcdc_get_record('fa542137-a976-49a6-856d-f1201adb2243') - expect_s3_class(bcdc_get_data(record, - resource = 'dc1098a7-a4b8-49a3-adee-9badd4429279'), - "tbl") + expect_s3_class( + bcdc_get_data(record, resource = 'dc1098a7-a4b8-49a3-adee-9badd4429279'), + "tbl" + ) }) test_that("bcdc_get_data fails with invalid input", { skip_if_net_down() skip_on_cran() - expect_error(bcdc_get_data(35L), - "No bcdc_get_data method for an object of class integer") + expect_error( + bcdc_get_data(35L), + "No bcdc_get_data method for an object of class integer" + ) }) test_that("bcdc_get_data works with BCGW name", { skip_if_net_down() skip_on_cran() - expect_s3_class(bcdc_get_data("WHSE_IMAGERY_AND_BASE_MAPS.GSR_AIRPORTS_SVW"), "bcdc_sf") + expect_s3_class( + bcdc_get_data("WHSE_IMAGERY_AND_BASE_MAPS.GSR_AIRPORTS_SVW"), + "bcdc_sf" + ) }) test_that("bcdc_get_data fails when no downloadable resources", { skip_if_net_down() skip_on_cran() - expect_error(bcdc_get_data("4e237966-3db8-4e28-8e59-296bf0b8d8e4"), - "There are no resources that bcdata can download from this record") + expect_error( + bcdc_get_data("4e237966-3db8-4e28-8e59-296bf0b8d8e4"), + "There are no resources that bcdata can download from this record" + ) }) test_that("bcdc_get_data fails when >1 resource not specified & noninteractive", { skip_if_net_down() skip_on_cran() - expect_error(bcdc_get_data("21c72822-2502-4431-b9a2-92fc9401ef12"), - "The record you are trying to access appears to have more than one resource.") + expect_error( + bcdc_get_data("21c72822-2502-4431-b9a2-92fc9401ef12"), + "The record you are trying to access appears to have more than one resource." + ) }) test_that("bcdc_get_data handles sheet name specification", { skip_if_net_down() skip_on_cran() - expect_message(bcdc_get_data('8620ce82-4943-43c4-9932-40730a0255d6'), 'This .xlsx resource contains the following sheets:') - expect_error(bcdc_get_data('8620ce82-4943-43c4-9932-40730a0255d6', sheet = "foo"), "Error: Sheet 'foo' not found") - expect_s3_class(bcdc_get_data('8620ce82-4943-43c4-9932-40730a0255d6', sheet = "Multi Unit Homes"), "data.frame") + expect_message( + bcdc_get_data('8620ce82-4943-43c4-9932-40730a0255d6'), + 'This .xlsx resource contains the following sheets:' + ) + expect_error( + bcdc_get_data('8620ce82-4943-43c4-9932-40730a0255d6', sheet = "foo"), + "Error: Sheet 'foo' not found" + ) + expect_s3_class( + bcdc_get_data( + '8620ce82-4943-43c4-9932-40730a0255d6', + sheet = "Multi Unit Homes" + ), + "data.frame" + ) }) test_that("bcdc_get_data returns a list object when resource has a json extension", { diff --git a/tests/testthat/test-get_record.R b/tests/testthat/test-get_record.R index 3c446f0c..7c94fe5d 100644 --- a/tests/testthat/test-get_record.R +++ b/tests/testthat/test-get_record.R @@ -13,14 +13,26 @@ test_that("bcdc_get_record works with slug and full url", { skip_on_cran() skip_if_net_down() - expect_s3_class(ret1 <- bcdc_get_record("https://catalogue.data.gov.bc.ca/dataset/bc-airports"), - "bcdc_record") - expect_s3_class(ret2 <- bcdc_get_record("bc-airports"), - "bcdc_record") - expect_s3_class(ret3 <- bcdc_get_record("https://catalogue.data.gov.bc.ca/dataset/76b1b7a3-2112-4444-857a-afccf7b20da8"), - "bcdc_record") - expect_s3_class(ret4 <- bcdc_get_record("76b1b7a3-2112-4444-857a-afccf7b20da8"), - "bcdc_record") + expect_s3_class( + ret1 <- bcdc_get_record( + glue::glue("{catalogue_base_url()}/dataset/bc-airports") + ), + "bcdc_record" + ) + expect_s3_class( + ret2 <- bcdc_get_record("bc-airports"), + "bcdc_record" + ) + expect_s3_class( + ret3 <- bcdc_get_record( + glue::glue("{catalogue_base_url()}/dataset/76b1b7a3-2112-4444-857a-afccf7b20da8") + ), + "bcdc_record" + ) + expect_s3_class( + ret4 <- bcdc_get_record("76b1b7a3-2112-4444-857a-afccf7b20da8"), + "bcdc_record" + ) expect_equal(ret1$title, "BC Airports") lapply(list(ret2, ret3, ret4), expect_equal, ret1) }) @@ -29,9 +41,15 @@ test_that("bcdc_search_facets works", { skip_on_cran() skip_if_net_down() ret_names <- c("facet", "count", "display_name", "name") - lapply(c("license_id", "download_audience", "res_format", - "sector", "organization"), - function(x) expect_named(bcdc_search_facets(x)) + lapply( + c( + "license_id", + "download_audience", + "res_format", + "publish_state", + "organization" + ), + function(x) expect_named(bcdc_search_facets(x)) ) expect_error(bcdc_search_facets("foo"), "'arg' should be one of") }) @@ -83,8 +101,10 @@ test_that("bcdc_search works", { expect_s3_class(bcdc_search("forest"), "bcdc_recordlist") expect_s3_class(bcdc_search("regional district", res_format = "fgdb"), "bcdc_recordlist") - expect_error(bcdc_search(organization = "foo"), - "foo is not a valid value for organization") + expect_error( + bcdc_search(organization = "foo"), + "foo is not a valid value for organization" + ) }) test_that("a record with bcgeographicwarehouse AND wms is return by bcdc_get_record",{ @@ -122,8 +142,10 @@ test_that("a data frame with 8 columns of expected types is returned by bcdc_tid expect_type(d$bcdata_available, "logical") expect_equal(d, bcdc_tidy_resources('76b1b7a3-2112-4444-857a-afccf7b20da8')) expect_error(bcdc_tidy_resources(list()), "No bcdc_tidy_resources method for an object of class") - expect_error(bcdc_tidy_resources("WHSE_IMAGERY_AND_BASE_MAPS.GSR_AIRPORTS_SVW"), - "No bcdc_tidy_resources method for a BCGW object name") + expect_error( + bcdc_tidy_resources("WHSE_IMAGERY_AND_BASE_MAPS.GSR_AIRPORTS_SVW"), + "No bcdc_tidy_resources method for a BCGW object name" + ) }) test_that("bcdc_get_record works with/without authentication", { @@ -135,16 +157,20 @@ test_that("bcdc_get_record works with/without authentication", { on.exit(Sys.setenv(BCDC_KEY = key_val)) # record NOT requiring auth - expect_message(res <- bcdc_get_record(point_record), - "Authorizing with your stored API key") + expect_message( + res <- bcdc_get_record(point_record), + "Authorizing with your stored API key" + ) expect_s3_class(res, "bcdc_record") # record requiring auth auth_record_id <- Sys.getenv("BCDC_TEST_RECORD") skip_if_not(nzchar(key_val)) - expect_message(res <- bcdc_get_record(auth_record_id), - "Authorizing with your stored API key") + expect_message( + res <- bcdc_get_record(auth_record_id), + "Authorizing with your stored API key" + ) expect_s3_class(res, "bcdc_record") Sys.unsetenv("BCDC_KEY") diff --git a/tests/testthat/test-query-geodata-collect.R b/tests/testthat/test-query-geodata-collect.R index 131ddc61..8c94e4c8 100644 --- a/tests/testthat/test-query-geodata-collect.R +++ b/tests/testthat/test-query-geodata-collect.R @@ -31,7 +31,9 @@ test_that("bcdc_query_geodata succeeds with a records over 10000 rows", { skip_if_net_down() skip("Skipping the BEC test, though available for testing") expect_s3_class( - collect(bcdc_query_geodata("terrestrial-protected-areas-representation-by-biogeoclimatic-unit")), + collect( + bcdc_query_geodata("terrestrial-protected-areas-representation-by-biogeoclimatic-unit") + ), "bcdc_sf" ) }) @@ -41,7 +43,10 @@ test_that("bcdc_query_geodata works with slug and full url using collect", { skip_on_cran() skip_if_net_down() expect_s3_class( - ret1 <- bcdc_query_geodata("https://catalogue.data.gov.bc.ca/dataset/bc-airports") %>% collect(), + ret1 <- bcdc_query_geodata( + glue::glue("{catalogue_base_url()}/dataset/bc-airports") + ) %>% + collect(), "sf" ) expect_s3_class( @@ -49,7 +54,9 @@ test_that("bcdc_query_geodata works with slug and full url using collect", { "sf" ) expect_s3_class( - ret3 <- bcdc_query_geodata("https://catalogue.data.gov.bc.ca/dataset/76b1b7a3-2112-4444-857a-afccf7b20da8") + ret3 <- bcdc_query_geodata( + glue::glue("{catalogue_base_url()}/dataset/76b1b7a3-2112-4444-857a-afccf7b20da8") + ) %>% collect(), "sf" ) @@ -58,7 +65,11 @@ test_that("bcdc_query_geodata works with slug and full url using collect", { "sf" ) expect_s3_class( - ret5 <- bcdc_query_geodata("https://catalogue.data.gov.bc.ca/dataset/76b1b7a3-2112-4444-857a-afccf7b20da8/resource/4d0377d9-e8a1-429b-824f-0ce8f363512c") + ret5 <- bcdc_query_geodata( + glue::glue( + "{catalogue_base_url()}/dataset/76b1b7a3-2112-4444-857a-afccf7b20da8/resource/4d0377d9-e8a1-429b-824f-0ce8f363512c" + ) + ) %>% collect(), "sf" )