@@ -2,21 +2,22 @@ test_that("Pvol for the Netherlands can be downloaded", {
22 skip_if(Sys.which(" KNMI_vol_h5_to_ODIM_h5" ) == " " )
33 skip_if_offline(host = " api.dataplatform.knmi.nl" )
44
5- # make sure local env is used by keyring so that api key can be set
6- withr :: local_options(list (
7- " keyring_backend" = " env"
8- ))
9- # get public key here https://developer.dataplatform.knmi.nl/open-data-api#token
10- withr :: local_envvar(
11- list (
12- " getRad_nl_api_key" = " eyJvcmciOiI1ZTU1NGUxOTI3NGE5NjAwMDEyYTNlYjEiLCJpZCI6ImVlNDFjMWI0MjlkODQ2MThiNWI4ZDViZDAyMTM2YTM3IiwiaCI6Im11cm11cjEyOCJ9"
5+ # First see if a key can be retrieved if not make sure env is used as a keyring backend
6+ if (rlang :: is_error(rlang :: catch_cnd(getRad :: get_secret(" nl_api_key" )))) {
7+ withr :: local_options(list (
8+ " keyring_backend" = " env"
9+ ))
10+ }
11+ # If no key can be retrieved from the current backend set the key to the anonymous key of KNMI
12+ if (rlang :: is_error(rlang :: catch_cnd(getRad :: get_secret(" nl_api_key" )))) {
13+ # get public key here https://developer.dataplatform.knmi.nl/open-data-api#token
14+ withr :: local_envvar(
15+ list (
16+ " getRad_nl_api_key" = " eyJvcmciOiI1ZTU1NGUxOTI3NGE5NjAwMDEyYTNlYjEiLCJpZCI6ImVlNDFjMWI0MjlkODQ2MThiNWI4ZDViZDAyMTM2YTM3IiwiaCI6Im11cm11cjEyOCJ9"
17+ )
1318 )
14- )
19+ }
1520 time <- as.POSIXct(" 2024-4-4 20:00:00" , tz = " Europe/Helsinki" )
16- expect_s3_class(
17- get_pvol(" nlhrw" , time , param = " all" ),
18- " pvol"
19- )
2021 pvol <- expect_s3_class(get_pvol(" nlhrw" , time , param = " all" ), " pvol" )
2122 expect_true(bioRad :: is.pvol(pvol ))
2223 expect_identical(
@@ -31,15 +32,24 @@ test_that("Pvol for the Netherlands can be downloaded. Incorrect converter resul
3132
3233 # make sure local env is used by keyring so that api key can be set
3334 withr :: local_options(list (
34- " keyring_backend" = " env" ,
3535 " getRad.nl_converter" = " ls"
3636 ))
37- # get public key here https://developer.dataplatform.knmi.nl/open-data-api#token
38- withr :: local_envvar(
39- list (
40- " getRad_nl_api_key" = " eyJvcmciOiI1ZTU1NGUxOTI3NGE5NjAwMDEyYTNlYjEiLCJpZCI6ImVlNDFjMWI0MjlkODQ2MThiNWI4ZDViZDAyMTM2YTM3IiwiaCI6Im11cm11cjEyOCJ9"
37+
38+ # First see if a key can be retrieved if not make sure env is used as a keyring backend
39+ if (rlang :: is_error(rlang :: catch_cnd(getRad :: get_secret(" nl_api_key" )))) {
40+ withr :: local_options(list (
41+ " keyring_backend" = " env"
42+ ))
43+ }
44+ # If no key can be retrieved from the current backend set the key to the anonymous key of KNMI
45+ if (rlang :: is_error(rlang :: catch_cnd(getRad :: get_secret(" nl_api_key" )))) {
46+ # get public key here https://developer.dataplatform.knmi.nl/open-data-api#token
47+ withr :: local_envvar(
48+ list (
49+ " getRad_nl_api_key" = " eyJvcmciOiI1ZTU1NGUxOTI3NGE5NjAwMDEyYTNlYjEiLCJpZCI6ImVlNDFjMWI0MjlkODQ2MThiNWI4ZDViZDAyMTM2YTM3IiwiaCI6Im11cm11cjEyOCJ9"
50+ )
4151 )
42- )
52+ }
4353 time <- as.POSIXct(" 2024-4-4 20:00:00" , tz = " Europe/Helsinki" )
4454 expect_error(
4555 get_pvol(" nlhrw" , time , param = " all" ),
0 commit comments