diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 0cb3593..f67292d 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -29,6 +29,7 @@ jobs: - {os: ubuntu-latest, r: '4.1.0'} env: + getRad_nl_api_key: ${{ secrets.GETRAD_NL_API_KEY }} GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} R_KEEP_PKG_SOURCE: yes diff --git a/.github/workflows/regular-checks.yaml b/.github/workflows/regular-checks.yaml index 8967ac5..5c8cbc5 100644 --- a/.github/workflows/regular-checks.yaml +++ b/.github/workflows/regular-checks.yaml @@ -22,6 +22,7 @@ jobs: - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} env: + getRad_nl_api_key: ${{ secrets.GETRAD_NL_API_KEY }} GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} R_KEEP_PKG_SOURCE: yes diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 0ab748d..1d28b2b 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -13,6 +13,7 @@ jobs: test-coverage: runs-on: ubuntu-latest env: + getRad_nl_api_key: ${{ secrets.GETRAD_NL_API_KEY }} GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: diff --git a/tests/testthat/test-get_pvol_nl.R b/tests/testthat/test-get_pvol_nl.R index 783bbd6..f753e63 100644 --- a/tests/testthat/test-get_pvol_nl.R +++ b/tests/testthat/test-get_pvol_nl.R @@ -2,21 +2,22 @@ test_that("Pvol for the Netherlands can be downloaded", { skip_if(Sys.which("KNMI_vol_h5_to_ODIM_h5") == "") skip_if_offline(host = "api.dataplatform.knmi.nl") - # make sure local env is used by keyring so that api key can be set - withr::local_options(list( - "keyring_backend" = "env" - )) - # get public key here https://developer.dataplatform.knmi.nl/open-data-api#token - withr::local_envvar( - list( - "getRad_nl_api_key" = "eyJvcmciOiI1ZTU1NGUxOTI3NGE5NjAwMDEyYTNlYjEiLCJpZCI6ImVlNDFjMWI0MjlkODQ2MThiNWI4ZDViZDAyMTM2YTM3IiwiaCI6Im11cm11cjEyOCJ9" + # First see if a key can be retrieved if not make sure env is used as a keyring backend + if (rlang::is_error(rlang::catch_cnd(getRad::get_secret("nl_api_key")))) { + withr::local_options(list( + "keyring_backend" = "env" + )) + } + # If no key can be retrieved from the current backend set the key to the anonymous key of KNMI + if (rlang::is_error(rlang::catch_cnd(getRad::get_secret("nl_api_key")))) { + # get public key here https://developer.dataplatform.knmi.nl/open-data-api#token + withr::local_envvar( + list( + "getRad_nl_api_key" = "eyJvcmciOiI1ZTU1NGUxOTI3NGE5NjAwMDEyYTNlYjEiLCJpZCI6ImVlNDFjMWI0MjlkODQ2MThiNWI4ZDViZDAyMTM2YTM3IiwiaCI6Im11cm11cjEyOCJ9" + ) ) - ) + } time <- as.POSIXct("2024-4-4 20:00:00", tz = "Europe/Helsinki") - expect_s3_class( - get_pvol("nlhrw", time, param = "all"), - "pvol" - ) pvol <- expect_s3_class(get_pvol("nlhrw", time, param = "all"), "pvol") expect_true(bioRad::is.pvol(pvol)) expect_identical( @@ -31,15 +32,24 @@ test_that("Pvol for the Netherlands can be downloaded. Incorrect converter resul # make sure local env is used by keyring so that api key can be set withr::local_options(list( - "keyring_backend" = "env", "getRad.nl_converter" = "ls" )) - # get public key here https://developer.dataplatform.knmi.nl/open-data-api#token - withr::local_envvar( - list( - "getRad_nl_api_key" = "eyJvcmciOiI1ZTU1NGUxOTI3NGE5NjAwMDEyYTNlYjEiLCJpZCI6ImVlNDFjMWI0MjlkODQ2MThiNWI4ZDViZDAyMTM2YTM3IiwiaCI6Im11cm11cjEyOCJ9" + + # First see if a key can be retrieved if not make sure env is used as a keyring backend + if (rlang::is_error(rlang::catch_cnd(getRad::get_secret("nl_api_key")))) { + withr::local_options(list( + "keyring_backend" = "env" + )) + } + # If no key can be retrieved from the current backend set the key to the anonymous key of KNMI + if (rlang::is_error(rlang::catch_cnd(getRad::get_secret("nl_api_key")))) { + # get public key here https://developer.dataplatform.knmi.nl/open-data-api#token + withr::local_envvar( + list( + "getRad_nl_api_key" = "eyJvcmciOiI1ZTU1NGUxOTI3NGE5NjAwMDEyYTNlYjEiLCJpZCI6ImVlNDFjMWI0MjlkODQ2MThiNWI4ZDViZDAyMTM2YTM3IiwiaCI6Im11cm11cjEyOCJ9" + ) ) - ) + } time <- as.POSIXct("2024-4-4 20:00:00", tz = "Europe/Helsinki") expect_error( get_pvol("nlhrw", time, param = "all"), diff --git a/tests/testthat/test-get_pvol_ro.R b/tests/testthat/test-get_pvol_ro.R index b52a736..b5822d9 100644 --- a/tests/testthat/test-get_pvol_ro.R +++ b/tests/testthat/test-get_pvol_ro.R @@ -11,7 +11,8 @@ test_that("Check if the available attributes changed", { unique() |> gsub(pattern = ".hdf", replacement = "") |> sort(), - c("KDP", "RhoHV", "V", "ZDR", "dBZ") |> sort() + c("Height", "KDP", "RhoHV", "V", "ZDR", "dBR", "dBZ") |> sort() + # Height and dBR are none polar files ) }) test_that("Pvol for Romania can be downloaded", { diff --git a/tests/testthat/test-get_vpts_coverage_rmi.R b/tests/testthat/test-get_vpts_coverage_rmi.R index 36319c4..3701504 100644 --- a/tests/testthat/test-get_vpts_coverage_rmi.R +++ b/tests/testthat/test-get_vpts_coverage_rmi.R @@ -41,7 +41,7 @@ test_that("get_vpts_coverage_rmi() returns known radars and years", { expect_in( lubridate::year(cov$date), - seq(2019, 2025) + seq(2019, lubridate::year(Sys.Date())) ) })