From ea23c290af7f1d9323d457674ff1202c1bd01493 Mon Sep 17 00:00:00 2001 From: sbudai Date: Wed, 8 Apr 2026 00:24:19 +0200 Subject: [PATCH] V1.1.0 >> v1.1.1 ## New functionality - None. ## Changes - Some queries are allowed to capture 1 year of the data as a maximum time span. But the leap year handling had not been elaborated yet. From this version the leap year cases are going to be handled nicely. - Typos have fixed in the documentations. - The `ENTSOE_PAT` is going to be checked to be in UUID v4 format from now on. - The vignettes have been slightly adjusted. ## Miscellaneous - The code base and the unit tests have been adjusted in such a way which makes the whole project more maintainable. --- DESCRIPTION | 2 +- NAMESPACE | 6 +- NEWS.md | 17 + R/constants.R | 1 + R/en_balancing.R | 1207 ++++----- R/en_generation.R | 328 +-- R/en_helpers.R | 130 +- R/en_load.R | 298 +-- R/en_market.R | 891 +++---- R/en_outages.R | 390 ++- R/en_transmission.R | 551 ++-- R/utils.R | 160 +- README.Rmd | 2 +- README.md | 8 +- man/accounting_point_eic.Rd | 8 +- man/all_approved_eic.Rd | 8 +- man/area_eic.Rd | 8 +- man/continuous_offered_transfer_capacities.Rd | 4 +- man/explicit_offered_transfer_capacities.Rd | 4 +- man/gen_storage_mean_filling_rate.Rd | 4 +- man/implicit_offered_transfer_capacities.Rd | 4 +- man/location_eic.Rd | 8 +- man/netted_volumes_per_border.Rd | 4 +- man/outages_cons_units.Rd | 6 +- man/party_eic.Rd | 8 +- man/resource_object_eic.Rd | 8 +- man/substation_eic.Rd | 8 +- man/tie_line_eic.Rd | 8 +- tests/testthat/fixtures/eiccodes.csv | 3 + tests/testthat/fixtures/entsoe_gen_min.xml | 41 + .../testthat/fixtures/merge_date_and_time.xml | 25 + tests/testthat/fixtures/no_data.xml | 1 + tests/testthat/fixtures/offset_response.xml | 1 + tests/testthat/fixtures/test_df_list.rds | Bin 2384 -> 2593 bytes .../tests/testthat/fixtures/cd_catalog.xml | 211 -- .../tests/testthat/fixtures/mtcars.csv | 33 - tests/testthat/test-en_balancing.R | 1231 ++++----- tests/testthat/test-en_generation.R | 463 ++-- tests/testthat/test-en_helpers.R | 485 ++-- tests/testthat/test-en_load.R | 420 +--- tests/testthat/test-en_market.R | 2233 ++++++----------- tests/testthat/test-en_outages.R | 932 ++----- tests/testthat/test-en_transmission.R | 1236 +++------ tests/testthat/test-utils.R | 2186 +++++++--------- vignettes/architecture.Rmd | 26 +- vignettes/da-price-spread-vignette.Rmd | 2 +- vignettes/getting-started.Rmd | 4 +- vignettes/time-series-restructuring.Rmd | 4 +- vignettes/working-with-eic-codes.Rmd | 4 +- 49 files changed, 4971 insertions(+), 8651 deletions(-) create mode 100644 tests/testthat/fixtures/eiccodes.csv create mode 100644 tests/testthat/fixtures/entsoe_gen_min.xml create mode 100644 tests/testthat/fixtures/merge_date_and_time.xml create mode 100644 tests/testthat/fixtures/no_data.xml create mode 100644 tests/testthat/fixtures/offset_response.xml delete mode 100644 tests/testthat/fixtures/tests/testthat/fixtures/cd_catalog.xml delete mode 100644 tests/testthat/fixtures/tests/testthat/fixtures/mtcars.csv diff --git a/DESCRIPTION b/DESCRIPTION index 9ac3f076..60e49863 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: entsoeapi Type: Package Title: Client for the 'ENTSO-E' Transparency Platform API -Version: 1.1.0 +Version: 1.1.1 Authors@R: c(person("Kenneth", "Rose", role=c("aut", "cph"), email="kennethrose82@gmail.com"), person("Sándor", "Budai", role=c("aut", "cre", "cph"), email="sbudai.ga@gmail.com")) Description: Provides a standardized R client for the 'ENTSO-E' (European Network of diff --git a/NAMESPACE b/NAMESPACE index a312c8a3..4a337504 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -81,12 +81,14 @@ export(tie_line_eic) export(total_commercial_sched) export(total_nominated_capacity) importFrom(cachem,cache_mem) +importFrom(checkmate,assert_character) importFrom(checkmate,assert_choice) importFrom(checkmate,assert_count) importFrom(checkmate,assert_data_frame) importFrom(checkmate,assert_flag) importFrom(checkmate,assert_integerish) importFrom(checkmate,assert_string) +importFrom(checkmate,test_string) importFrom(cli,cli_abort) importFrom(cli,cli_alert) importFrom(cli,cli_alert_danger) @@ -122,7 +124,6 @@ importFrom(dplyr,rename_with) importFrom(dplyr,select) importFrom(dplyr,ungroup) importFrom(httr2,req_headers) -importFrom(httr2,req_method) importFrom(httr2,req_perform) importFrom(httr2,req_progress) importFrom(httr2,req_retry) @@ -142,6 +143,7 @@ importFrom(lubridate,days) importFrom(lubridate,duration) importFrom(lubridate,parse_date_time) importFrom(lubridate,year) +importFrom(lubridate,years) importFrom(lubridate,ymd) importFrom(snakecase,to_snake_case) importFrom(stats,runif) @@ -151,12 +153,14 @@ importFrom(stringr,str_detect) importFrom(stringr,str_extract) importFrom(stringr,str_match) importFrom(stringr,str_match_all) +importFrom(stringr,str_remove) importFrom(stringr,str_remove_all) importFrom(stringr,str_replace) importFrom(stringr,str_replace_all) importFrom(stringr,str_split_1) importFrom(stringr,str_sub) importFrom(stringr,str_subset) +importFrom(stringr,str_to_lower) importFrom(tidyr,fill) importFrom(tidyr,nest) importFrom(tidyr,unite) diff --git a/NEWS.md b/NEWS.md index 19c7fc7a..fe6d9751 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,20 @@ +# entsoeapi v1.1.1 (2026-04-08) + +## New functionality + +- None. + +## Changes + +- Some queries are allowed to capture 1 year of the data as a maximum time span. But the leap year handling had not been elaborated yet. From this version the leap year cases are going to be handled nicely. +- Typos have fixed in the documentations. +- The `ENTSOE_PAT` is going to be checked to be in UUID v4 format from now on. +- The vignettes have been slightly adjusted. + +## Miscellaneous + +- The code base and the unit tests have been adjusted in such a way which makes the whole project more maintainable. + # entsoeapi v1.1.0 (2026-03-31) ## New functionality diff --git a/R/constants.R b/R/constants.R index 9a94a41f..f029fd08 100644 --- a/R/constants.R +++ b/R/constants.R @@ -8,6 +8,7 @@ .pd_alloc_eic <- "cio-lio/xml/allocated-eic-codes.xml" .pd_csv_eic <- "/cio-lio/csv/" .feed_url <- "https://external-api.tp.entsoe.eu/news/feed" +.test_token <- "497dcba3-ecbf-4587-a2dd-5eb0665e6880" possible_eic_chars <- stats::setNames( object = 0L:36L, nm = c(as.character(0:9), LETTERS, "-") diff --git a/R/en_balancing.R b/R/en_balancing.R index 91f35fe6..4a7aa68a 100644 --- a/R/en_balancing.R +++ b/R/en_balancing.R @@ -19,10 +19,9 @@ #' #' @return A [tibble::tibble()] with the queried data. #' -#' @importFrom checkmate assert_string assert_choice +#' @importFrom checkmate assert_choice #' @importFrom lubridate ymd days -#' @importFrom cli cli_abort -#` +#' #' @export #' #' @examplesIf there_is_provider() && nchar(Sys.getenv("ENTSOE_PAT")) > 0L @@ -39,48 +38,33 @@ elastic_demands <- function( eic = NULL, process_type = NULL, - period_start = ymd( - Sys.Date() - days(x = 7L), - tz = "CET" - ), - period_end = ymd( - Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 7L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) assert_choice(x = process_type, choices = c("A47", "A51")) - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for a (maximum) 1 year long period - query_string <- paste0( - "documentType=A37", - "&processType=", process_type, - "&businessType=B75", - "&Acquiring_domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A37", + "&processType=", process_type, + "&businessType=B75", + "&Acquiring_domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -106,9 +90,7 @@ elastic_demands <- function( #' #' @return A [tibble::tibble()] with the queried data. #' -#' @importFrom checkmate assert_string #' @importFrom lubridate ymd days -#' @importFrom cli cli_abort #' #' @export #' @@ -124,47 +106,32 @@ elastic_demands <- function( #' netted_volumes <- function( eic = NULL, - period_start = ymd( - Sys.Date() - days(x = 7L), - tz = "CET" - ), - period_end = ymd( - Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 7L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one day - if (difftime(period_end, period_start, units = "day") > 1L) { - cli_abort("One day range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for a (maximum) 1 year long period - query_string <- paste0( - "documentType=B17", - "&processType=A63", - "&Acquiring_domain=", eic, - "&Connecting_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 day" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=B17", + "&processType=A63", + "&Acquiring_domain=", eic, + "&Connecting_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -197,9 +164,8 @@ netted_volumes <- function( #' #' @return A [tibble::tibble()] with the queried data. #' -#' @importFrom checkmate assert_string assert_choice +#' @importFrom checkmate assert_choice #' @importFrom lubridate ymd days -#' @importFrom cli cli_abort #' #' @export #' @@ -217,48 +183,33 @@ netted_volumes <- function( exchanged_volumes <- function( eic = NULL, process_type = NULL, - period_start = ymd( - Sys.Date() - days(x = 7L), - tz = "CET" - ), - period_end = ymd( - Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 7L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) assert_choice(x = process_type, choices = c("A51", "A60", "A61")) - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one day - if (difftime(period_end, period_start, units = "day") > 1L) { - cli_abort("One day range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for a (maximum) 1 year long period - query_string <- paste0( - "documentType=B17", - "&processType=", process_type, - "&Acquiring_domain=", eic, - "&Connecting_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 day" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=B17", + "&processType=", process_type, + "&Acquiring_domain=", eic, + "&Connecting_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -288,9 +239,8 @@ exchanged_volumes <- function( #' #' @return A [tibble::tibble()] with the queried data. #' -#' @importFrom checkmate assert_string assert_choice +#' @importFrom checkmate assert_choice #' @importFrom lubridate ymd days -#' @importFrom cli cli_abort #' #' @export #' @@ -310,50 +260,35 @@ balancing_border_cap_limit <- function( eic_in = NULL, eic_out = NULL, process_type = "A51", - period_start = ymd( - Sys.Date() - days(x = 7L), - tz = "CET" - ), - period_end = ymd( - Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 7L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic_in, var_name = "eic_in") assert_eic(eic = eic_out, var_name = "eic_out") assert_choice(x = process_type, choices = c("A47", "A51", "A63")) - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for a (maximum) 1 year long period - query_string <- paste0( - "documentType=A31", - "&BusinessType=A26", - "&processType=", process_type, - "&In_Domain=", eic_in, - "&Out_Domain=", eic_out, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A31", + "&BusinessType=A26", + "&processType=", process_type, + "&In_Domain=", eic_in, + "&Out_Domain=", eic_out, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -381,9 +316,8 @@ balancing_border_cap_limit <- function( #' #' @return A [tibble::tibble()] with the queried data. #' -#' @importFrom checkmate assert_string assert_choice +#' @importFrom checkmate assert_choice #' @importFrom lubridate ymd days -#' @importFrom cli cli_abort #' #' @export #' @@ -403,49 +337,34 @@ exchanged_volumes_per_border <- function( acquiring_eic = NULL, connecting_eic = NULL, process_type = NULL, - period_start = ymd( - Sys.Date() - days(x = 7L), - tz = "CET" - ), - period_end = ymd( - Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 7L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = acquiring_eic, var_name = "acquiring_eic") assert_eic(eic = connecting_eic, var_name = "connecting_eic") assert_choice(x = process_type, choices = c("A51", "A60", "A61")) - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one day - if (difftime(period_end, period_start, units = "day") > 1L) { - cli_abort("One day range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url - query_string <- paste0( - "documentType=A30", - "&processType=", process_type, - "&Acquiring_domain=", acquiring_eic, - "&Connecting_Domain=", connecting_eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 day" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A30", + "&processType=", process_type, + "&Acquiring_domain=", acquiring_eic, + "&Connecting_Domain=", connecting_eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -476,8 +395,8 @@ exchanged_volumes_per_border <- function( #' #' @return A [tibble::tibble()] with the queried data. #' -#' @importFrom checkmate assert_choice assert_string -#' @importFrom cli cli_abort +#' @importFrom checkmate assert_choice +#' @importFrom lubridate ymd days #' #' @export #' @@ -499,14 +418,8 @@ netted_volumes_per_border <- function( acquiring_eic = NULL, connecting_eic = NULL, process_type = NULL, - period_start = lubridate::ymd( - Sys.Date() - lubridate::days(x = 7L), - tz = "CET" - ), - period_end = lubridate::ymd( - Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 7L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { @@ -516,35 +429,26 @@ netted_volumes_per_border <- function( x = process_type, choices = c("A51", "A60", "A61", "A63") ) - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one day - if (difftime(period_end, period_start, units = "day") > 1L) { - cli_abort("One day range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url - query_string <- paste0( - "documentType=A30", - "&processType=", process_type, - "&Acquiring_domain=", acquiring_eic, - "&Connecting_Domain=", connecting_eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 day" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A30", + "&processType=", process_type, + "&Acquiring_domain=", acquiring_eic, + "&Connecting_Domain=", connecting_eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -573,9 +477,8 @@ netted_volumes_per_border <- function( #' #' @return A [tibble::tibble()] with the queried data. #' -#' @importFrom checkmate assert_string assert_choice +#' @importFrom checkmate assert_choice #' @importFrom lubridate ymd days -#' @importFrom cli cli_abort #' #' @export #' @@ -598,14 +501,8 @@ hvdc_link_constrains <- function( eic_out = NULL, eic_ic = NULL, process_type = "A63", - period_start = ymd( - Sys.Date() - days(x = 7L), - tz = "CET" - ), - period_end = ymd( - Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 7L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { @@ -613,37 +510,28 @@ hvdc_link_constrains <- function( assert_eic(eic = eic_out, var_name = "eic_out") assert_eic(eic = eic_ic, var_name = "eic_ic", null_ok = TRUE) assert_choice(x = process_type, choices = c("A47", "A51", "A63")) - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url - query_string <- paste0( - "documentType=A99", - "&processType=", process_type, - "&BusinessType=B06", - "&In_Domain=", eic_in, - "&Out_Domain=", eic_out, - if (is.null(eic_ic)) "" else "®isteredResource=", eic_ic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A99", + "&processType=", process_type, + "&BusinessType=B06", + "&In_Domain=", eic_in, + "&Out_Domain=", eic_out, + if (is.null(eic_ic)) "" else "®isteredResource=", eic_ic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -675,9 +563,8 @@ hvdc_link_constrains <- function( #' #' @return A [tibble::tibble()] with the queried data. #' -#' @importFrom checkmate assert_string assert_choice +#' @importFrom checkmate assert_choice #' @importFrom lubridate ymd days -#' @importFrom cli cli_abort #' #' @export #' @@ -697,14 +584,8 @@ hvdc_link_constrains <- function( changes_to_bid_availability <- function( eic = NULL, business_type = "C46", - period_start = ymd( - Sys.Date() - days(x = 7L), - tz = "CET" - ), - period_end = ymd( - Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 7L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { @@ -713,35 +594,26 @@ changes_to_bid_availability <- function( business_type, choices = c("C40", "C41", "C42", "C43", "C44", "C45", "C46") ) - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url - query_string <- paste0( - "documentType=B45", - "&processType=A47", - "&businessType=", business_type, - "&ControlArea_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=B45", + "&processType=A47", + "&businessType=", business_type, + "&ControlArea_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -764,9 +636,7 @@ changes_to_bid_availability <- function( #' #' @return A [tibble::tibble()] with the queried data. #' -#' @importFrom checkmate assert_string #' @importFrom lubridate ymd days -#' @importFrom cli cli_abort #' #' @export #' @@ -782,46 +652,31 @@ changes_to_bid_availability <- function( #' current_balancing_state <- function( eic = NULL, - period_start = ymd( - Sys.Date() - days(x = 7L), - tz = "CET" - ), - period_end = ymd( - Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 7L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than 100 days - if (difftime(period_end, period_start, units = "day") > 100L) { - cli_abort("100 day range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url - query_string <- paste0( - "documentType=A86", - "&businessType=B33", - "&Area_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "100 days" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A86", + "&businessType=B33", + "&Area_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -843,7 +698,6 @@ current_balancing_state <- function( #' #' @return A [tibble::tibble()] with the queried data. #' -#' @importFrom checkmate assert_string #' @importFrom lubridate ymd days #' #' @export @@ -864,42 +718,31 @@ current_balancing_state <- function( balancing_energy_bids <- function( eic = NULL, process_type = "A47", - period_start = ymd( - Sys.Date() - days(x = 7L), - tz = "CET" - ), - period_end = ymd( - Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 7L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) - assert_string(x = security_token, min.chars = 1L) - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url - query_string <- paste0( - "documentType=A37", - "&processType=", process_type, - "&businessType=B74", - "&Connecting_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A37", + "&processType=", process_type, + "&businessType=B74", + "&Connecting_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -929,9 +772,8 @@ balancing_energy_bids <- function( #' #' @return A [tibble::tibble()] with the queried data. #' -#' @importFrom checkmate assert_string assert_choice +#' @importFrom checkmate assert_choice #' @importFrom lubridate ymd days -#' @importFrom cli cli_abort #' #' @export #' @@ -949,14 +791,8 @@ balancing_energy_bids <- function( aggregated_balancing_energy_bids <- function( # nolint: object_length_linter eic = NULL, process_type = NULL, - period_start = ymd( - Sys.Date() - days(x = 7L), - tz = "CET" - ), - period_end = ymd( - Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 7L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { @@ -965,34 +801,25 @@ aggregated_balancing_energy_bids <- function( # nolint: object_length_linter x = process_type, choices = c("A51", "A46", "A47", "A60", "A61", "A67", "A68") ) - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url - query_string <- paste0( - "documentType=A24", - "&processType=", process_type, - "&area_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A24", + "&processType=", process_type, + "&area_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -1026,7 +853,7 @@ aggregated_balancing_energy_bids <- function( # nolint: object_length_linter #' #' @return A [tibble::tibble()] with the queried data. #' -#' @importFrom checkmate assert_string assert_choice +#' @importFrom checkmate assert_choice #' @importFrom lubridate ymd days #' #' @export @@ -1046,14 +873,8 @@ procured_balancing_capacity <- function( eic = NULL, process_type = NULL, market_agreement_type = NULL, - period_start = ymd( - Sys.Date() - days(x = 7L), - tz = "CET" - ), - period_end = ymd( - Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 7L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { @@ -1064,37 +885,27 @@ procured_balancing_capacity <- function( choices = c("A01", "A02", "A03", "A04", "A05", "A06", "A07", "A13"), null.ok = TRUE ) - assert_string(x = security_token, min.chars = 1L) - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url - query_string <- paste0( - "documentType=A15", - "&processType=", process_type, - "&area_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end ) - # if market_agreement_type is provided, add it to the query string - if (!is.null(market_agreement_type)) { - query_string <- paste0( - query_string, - "&type_MarketAgreement.Type=", market_agreement_type - ) - } - - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A15", + "&processType=", process_type, + "&area_Domain=", eic, + if (!is.null(market_agreement_type)) { + paste0("&type_MarketAgreement.Type=", market_agreement_type) + }, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -1120,7 +931,7 @@ procured_balancing_capacity <- function( #' #' @return A [tibble::tibble()] with the queried data. #' -#' @importFrom checkmate assert_string assert_choice +#' @importFrom checkmate assert_choice #' @importFrom lubridate ymd days #' #' @export @@ -1142,14 +953,8 @@ allocation_of_cross_zonal_balancing_cap <- function( # nolint: object_length_lin eic_acquiring = NULL, eic_connecting = NULL, market_agreement_type = NULL, - period_start = ymd( - Sys.Date() - days(x = 7L), - tz = "CET" - ), - period_end = ymd( - Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 7L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { @@ -1160,38 +965,28 @@ allocation_of_cross_zonal_balancing_cap <- function( # nolint: object_length_lin choices = c("A01", "A02", "A06"), null.ok = TRUE ) - assert_string(x = security_token, min.chars = 1L) - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url - query_string <- paste0( - "documentType=A38", - "&processType=A46", - "&Acquiring_Domain=", eic_acquiring, - "&Connecting_Domain=", eic_connecting, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end ) - # if market_agreement_type is provided, add it to the query string - if (!is.null(market_agreement_type)) { - query_string <- paste0( - query_string, - "&type_MarketAgreement.Type=", market_agreement_type - ) - } - - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A38", + "&processType=A46", + "&Acquiring_Domain=", eic_acquiring, + "&Connecting_Domain=", eic_connecting, + if (!is.null(market_agreement_type)) { + paste0("&type_MarketAgreement.Type=", market_agreement_type) + }, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -1228,7 +1023,7 @@ allocation_of_cross_zonal_balancing_cap <- function( # nolint: object_length_lin #' #' @return A [tibble::tibble()] with the queried data. #' -#' @importFrom checkmate assert_string assert_choice +#' @importFrom checkmate assert_choice #' @importFrom lubridate ymd days #' #' @export @@ -1249,14 +1044,8 @@ contracted_reserves <- function( market_agreement_type = NULL, process_type = NULL, psr_type = NULL, - period_start = ymd( - Sys.Date() - days(x = 7L), - tz = "CET" - ), - period_end = ymd( - Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 7L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { @@ -1275,32 +1064,27 @@ contracted_reserves <- function( choices = c("A03", "A04", "A05"), null.ok = TRUE ) - assert_string(x = security_token, min.chars = 1L) - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url - query_string <- paste0( - "documentType=A81", - "&businessType=B95", - "&type_MarketAgreement.Type=", market_agreement_type, - if (!is.null(process_type)) paste0("&processType=", process_type), - if (!is.null(psr_type)) paste0("&psrType=", psr_type), - "&controlArea_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A81", + "&businessType=B95", + "&type_MarketAgreement.Type=", market_agreement_type, + if (!is.null(process_type)) paste0("&processType=", process_type), + if (!is.null(psr_type)) paste0("&psrType=", psr_type), + "&controlArea_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -1324,9 +1108,7 @@ contracted_reserves <- function( #' #' @return A [tibble::tibble()] with the queried data. #' -#' @importFrom checkmate assert_string #' @importFrom lubridate ymd days -#' @importFrom cli cli_abort #' #' @export #' @@ -1344,51 +1126,32 @@ activated_balancing_prices <- function( eic = NULL, process_type = "A16", business_type = NULL, - period_start = ymd( - Sys.Date() - days(x = 7L), - tz = "CET" - ), - period_end = ymd( - Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 7L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url - query_string <- paste0( - "documentType=A84", - "&processType=", process_type, - "&controlArea_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # add optional business_type if provided - if (!is.null(business_type)) { - query_string <- paste0(query_string, "&businessType=", business_type) - } - - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A84", + "&processType=", process_type, + "&controlArea_Domain=", eic, + if (!is.null(business_type)) paste0("&businessType=", business_type), + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -1410,9 +1173,7 @@ activated_balancing_prices <- function( #' #' @return A [tibble::tibble()] with the queried data. #' -#' @importFrom checkmate assert_string #' @importFrom lubridate ymd days -#' @importFrom cli cli_abort #' #' @export #' @@ -1428,45 +1189,30 @@ activated_balancing_prices <- function( #' imbalance_prices <- function( eic = NULL, - period_start = ymd( - Sys.Date() - days(x = 7L), - tz = "CET" - ), - period_end = ymd( - Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 7L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url - query_string <- paste0( - "documentType=A85", - "&controlArea_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A85", + "&controlArea_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -1488,9 +1234,7 @@ imbalance_prices <- function( #' #' @return A [tibble::tibble()] with the queried data. #' -#' @importFrom checkmate assert_string #' @importFrom lubridate ymd days -#' @importFrom cli cli_abort #' #' @export #' @@ -1506,45 +1250,30 @@ imbalance_prices <- function( #' imbalance_volumes <- function( eic = NULL, - period_start = ymd( - Sys.Date() - days(x = 7L), - tz = "CET" - ), - period_end = ymd( - Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 7L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url - query_string <- paste0( - "documentType=A86", - "&controlArea_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A86", + "&controlArea_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -1566,9 +1295,7 @@ imbalance_volumes <- function( #' #' @return A [tibble::tibble()] with the queried data. #' -#' @importFrom checkmate assert_string #' @importFrom lubridate ymd days -#' @importFrom cli cli_abort #' #' @export #' @@ -1584,45 +1311,30 @@ imbalance_volumes <- function( #' financial_expenses_and_income <- function( eic = NULL, - period_start = ymd( - Sys.Date() - days(x = 7L), - tz = "CET" - ), - period_end = ymd( - Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 7L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url - query_string <- paste0( - "documentType=A87", - "&controlArea_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A87", + "&controlArea_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -1644,9 +1356,7 @@ financial_expenses_and_income <- function( #' #' @return A [tibble::tibble()] with the queried data. #' -#' @importFrom checkmate assert_string #' @importFrom lubridate ymd days -#' @importFrom cli cli_abort #' #' @export #' @@ -1662,46 +1372,31 @@ financial_expenses_and_income <- function( #' fcr_total_capacity <- function( eic = NULL, - period_start = ymd( - Sys.Date() - days(x = 7L), - tz = "CET" - ), - period_end = ymd( - Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 7L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url - query_string <- paste0( - "documentType=A26", - "&businessType=A25", - "&area_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A26", + "&businessType=A25", + "&area_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -1723,9 +1418,7 @@ fcr_total_capacity <- function( #' #' @return A [tibble::tibble()] with the queried data. #' -#' @importFrom checkmate assert_string #' @importFrom lubridate ymd days -#' @importFrom cli cli_abort #' #' @export #' @@ -1741,46 +1434,31 @@ fcr_total_capacity <- function( #' shares_of_fcr_capacity <- function( eic = NULL, - period_start = ymd( - Sys.Date() - days(x = 7L), - tz = "CET" - ), - period_end = ymd( - Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 7L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url - query_string <- paste0( - "documentType=A26", - "&businessType=C23", - "&area_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A26", + "&businessType=C23", + "&area_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -1804,7 +1482,7 @@ shares_of_fcr_capacity <- function( #' #' @return A [tibble::tibble()] with the queried data. #' -#' @importFrom checkmate assert_string assert_choice +#' @importFrom checkmate assert_choice #' @importFrom lubridate ymd days #' #' @export @@ -1833,43 +1511,32 @@ shares_of_fcr_capacity <- function( rr_and_frr_actual_capacity <- function( eic = NULL, process_type = NULL, - period_start = ymd( - Sys.Date() - days(x = 7L), - tz = "CET" - ), - period_end = ymd( - Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 7L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) assert_choice(x = process_type, choices = c("A56", "A46")) - assert_string(x = security_token, min.chars = 1L) - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url - query_string <- paste0( - "documentType=A26", - "&processType=", process_type, - "&businessType=C78", - "&Area_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A26", + "&processType=", process_type, + "&businessType=C78", + "&Area_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -1896,9 +1563,8 @@ rr_and_frr_actual_capacity <- function( #' #' @return A [tibble::tibble()] with the queried data. #' -#' @importFrom checkmate assert_string assert_choice +#' @importFrom checkmate assert_choice #' @importFrom lubridate ymd days -#' @importFrom cli cli_abort #' #' @export #' @@ -1931,48 +1597,33 @@ sharing_of_rr_and_frr_capacity <- function( eic_acquiring = NULL, eic_connecting = NULL, process_type = NULL, - period_start = ymd( - Sys.Date() - days(x = 7L), - tz = "CET" - ), - period_end = ymd( - Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 7L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic_acquiring, var_name = "eic_acquiring") assert_eic(eic = eic_connecting, var_name = "eic_connecting") assert_choice(x = process_type, choices = c("A56", "A46")) - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url - query_string <- paste0( - "documentType=A26", - "&BusinessType=C22", - "&processType=", process_type, - "&Acquiring_Domain=", eic_acquiring, - "&Connecting_Domain=", eic_connecting, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A26", + "&BusinessType=C22", + "&processType=", process_type, + "&Acquiring_Domain=", eic_acquiring, + "&Connecting_Domain=", eic_connecting, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } diff --git a/R/en_generation.R b/R/en_generation.R index ec8914b7..0ff58252 100644 --- a/R/en_generation.R +++ b/R/en_generation.R @@ -29,8 +29,7 @@ globalVariables( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd year -#' @importFrom checkmate assert_string assert_integerish -#' @importFrom cli cli_abort +#' @importFrom checkmate assert_integerish #' #' @export #' @@ -51,31 +50,22 @@ gen_installed_capacity_per_pt <- function( security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) - assert_string(security_token, min.chars = 1L) + check_sec_token(security_token = security_token) assert_integerish(year, len = 1L) - # convert year into the accepted format - period_start <- paste0(year, "01010000") - period_end <- paste0(year + 1L, "01010000") - - # compose GET request url for the denoted year - query_string <- paste0( - "documentType=A68", - "&processType=A33", - "&in_Domain=", eic, - if (!is.null(psr_type)) paste0("&psrType=", psr_type), - "&periodStart=", period_start, - "&periodEnd=", period_end - ) - - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A68", + "&processType=A33", + "&in_Domain=", eic, + if (!is.null(psr_type)) paste0("&psrType=", psr_type), + "&periodStart=", paste0(year, "01010000"), + "&periodEnd=", paste0(year + 1L, "01010000") + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -101,7 +91,7 @@ gen_installed_capacity_per_pt <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd year -#' @importFrom checkmate assert_string assert_integerish +#' @importFrom checkmate assert_integerish #' @importFrom cli cli_abort #' #' @export @@ -123,7 +113,7 @@ gen_installed_capacity_per_pu <- function( security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) - assert_string(security_token, min.chars = 1L) + check_sec_token(security_token = security_token) assert_integerish(year, len = 1L) # check if year is within the legal limit @@ -133,30 +123,19 @@ gen_installed_capacity_per_pu <- function( ) } - # convert year into the accepted format - period_start <- paste0(year, "01010000") - period_end <- paste0(year + 1L, "01010000") - - # compose GET request url for the denoted year - query_string <- paste0( - "documentType=A71", - "&processType=A33", - "&in_Domain=", eic, - { - if (!is.null(psr_type)) paste0("&psrType=", psr_type) - }, - "&periodStart=", period_start, - "&periodEnd=", period_end + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A71", + "&processType=A33", + "&in_Domain=", eic, + if (!is.null(psr_type)) paste0("&psrType=", psr_type), + "&periodStart=", paste0(year, "01010000"), + "&periodEnd=", paste0(year + 1L, "01010000") + ), + security_token = security_token, + tidy_output = tidy_output ) - - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token - ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -184,8 +163,6 @@ gen_installed_capacity_per_pu <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string -#' @importFrom cli cli_abort #' #' @export #' @@ -209,37 +186,26 @@ gen_per_prod_type <- function( security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) - assert_string(security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for a (maximum) 1 year long period - query_string <- paste0( - "documentType=A75", - "&processType=A16", - "&in_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end, - { - if (!is.null(gen_type)) paste0("&psrType=", gen_type) - } + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A75", + "&processType=A16", + "&in_Domain=", eic, + if (!is.null(gen_type)) paste0("&psrType=", gen_type), + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -267,16 +233,14 @@ gen_per_prod_type <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string -#' @importFrom cli cli_abort #' #' @export #' #' @examplesIf there_is_provider() && nchar(Sys.getenv("ENTSOE_PAT")) > 0L #' df <- entsoeapi::gen_storage_mean_filling_rate( #' eic = "10YFR-RTE------C", -#' period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), -#' period_end = lubridate::ymd(x = "2021-02-15", tz = "CET"), +#' period_start = lubridate::ymd(x = "2020-01-01", tz = "CET"), +#' period_end = lubridate::ymd(x = "2020-01-31", tz = "CET"), #' tidy_output = TRUE #' ) #' @@ -284,42 +248,31 @@ gen_per_prod_type <- function( #' gen_storage_mean_filling_rate <- function( eic = NULL, - period_start = ymd(Sys.Date() - days(x = 7L), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 7L), tz = "CET"), period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) - assert_string(security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 380L) { - cli_abort("Maximum 380 days range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for a (maximum) 1 year long period - query_string <- paste0( - "documentType=A72", - "&processType=A16", - "&in_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "380 days" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A72", + "&processType=A16", + "&in_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -346,8 +299,6 @@ gen_storage_mean_filling_rate <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string -#' @importFrom cli cli_abort #' @importFrom dplyr mutate lead bind_rows #' #' @export @@ -365,42 +316,28 @@ gen_storage_mean_filling_rate <- function( #' gen_per_gen_unit <- function( eic = NULL, - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), gen_type = NULL, tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) - assert_string(security_token, min.chars = 1L) - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end + ) # break time interval of period_start into 24 hour long parts to_time <- difftime( - time1 = strptime( - x = period_end, - format = "%Y%m%d%H%M", - tz = "UTC" - ) |> - as.POSIXct(tz = "UTC"), - time2 = strptime( - x = period_start, - format = "%Y%m%d%H%M", - tz = "UTC" - ) |> - as.POSIXct(tz = "UTC"), + time1 = as.POSIXct(x = period$end, format = "%Y%m%d%H%M", tz = "UTC"), + time2 = as.POSIXct(x = period$start, format = "%Y%m%d%H%M", tz = "UTC"), units = "days" ) |> ceiling() - 1L period_start_list <- as.POSIXct( - x = period_start, + x = period$start, format = "%Y%m%d%H%M", tz = "UTC" ) + seq(from = 0L, to = to_time) * 24L * 60L * 60L @@ -413,7 +350,8 @@ gen_per_gen_unit <- function( Filter(f = length) # create combination matrix dataframe - par_matrix <- expand.grid(par_list, + par_matrix <- expand.grid( + par_list, stringsAsFactors = FALSE, KEEP.OUT.ATTRS = FALSE ) @@ -423,7 +361,7 @@ gen_per_gen_unit <- function( mutate( periodEnd = lead( x = periodStart, - default = as.POSIXct(x = period_end, format = "%Y%m%d%H%M", tz = "UTC") + default = as.POSIXct(x = period$end, format = "%Y%m%d%H%M", tz = "UTC") ), .by = if (!is.null(gen_type)) "psrType" ) @@ -436,7 +374,8 @@ gen_per_gen_unit <- function( ) # create the corresponding part of the request URL from the par matrix - # vectorised: paste each column as "&name=value", then collapse across columns + # vectorised: paste each column as "&name=value", + # then collapse across columns par_part <- do.call( what = paste0, args = lapply( @@ -455,25 +394,19 @@ gen_per_gen_unit <- function( # iterate (maximum) 24 hours long periods thru # and append them into one tibble - result_tbl_appended <- query_string_list |> - lapply(\(query_string) { - # send GET request - en_cont_list <- api_req_safe( + lapply( + query_string_list, + \(query_string) { + # send GET request and return with the extracted response + run_api_query( query_string = query_string, - security_token = security_token - ) - - # return with the extracted response - extract_response( - content = en_cont_list, + security_token = security_token, tidy_output = tidy_output ) - }) |> + } + ) |> Filter(f = length) |> bind_rows() - - # return with all the generation data - result_tbl_appended } @@ -499,8 +432,6 @@ gen_per_gen_unit <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string -#' @importFrom cli cli_abort #' #' @export #' @@ -522,34 +453,25 @@ gen_day_ahead_forecast <- function( security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) - assert_string(security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url - query_string <- paste0( - "documentType=A71", - "&processType=A01", - "&in_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A71", + "&processType=A01", + "&in_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -581,8 +503,7 @@ gen_day_ahead_forecast <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string assert_choice -#' @importFrom cli cli_abort +#' @importFrom checkmate assert_choice #' #' @export #' @@ -607,32 +528,23 @@ gen_wind_solar_forecasts <- function( ) { assert_eic(eic = eic) assert_choice(x = process_type, choices = c("A01", "A18", "A40")) - assert_string(security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for a (minimum) 24 hours long period - query_string <- paste0( - "documentType=A69", - "&processType=", process_type, - "&in_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A69", + "&processType=", process_type, + "&in_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } diff --git a/R/en_helpers.R b/R/en_helpers.R index e6bb750d..e366b4a6 100644 --- a/R/en_helpers.R +++ b/R/en_helpers.R @@ -3,13 +3,30 @@ #' #' @param csv_file Character scalar. The CSV filename #' (e.g. `"X_eicCodes.csv"`). -#' @param cache_key Character scalar. The cache key -#' (e.g. `"party_eic_df_key"`). #' #' @return A tibble extracted from the source csv. #' +#' @importFrom checkmate assert_choice +#' @importFrom dplyr case_when +#' #' @noRd fetch_eic_csv <- function(csv_file, cache_key) { + assert_choice( + csv_file, + choices = c( + "X_eicCodes.csv", "Y_eicCodes.csv", "Z_eicCodes.csv", "T_eicCodes.csv", + "V_eicCodes.csv", "W_eicCodes.csv", "A_eicCodes.csv" + ) + ) + cache_key <- case_when( + csv_file == "X_eicCodes.csv" ~ "party_eic_df_key", + csv_file == "Y_eicCodes.csv" ~ "area_eic_df_key", + csv_file == "Z_eicCodes.csv" ~ "accounting_point_eic_df_key", + csv_file == "T_eicCodes.csv" ~ "tie_line_eic_df_key", + csv_file == "V_eicCodes.csv" ~ "location_eic_df_key", + csv_file == "W_eicCodes.csv" ~ "resource_object_eic_df_key", + csv_file == "A_eicCodes.csv" ~ "substation_eic_df_key" + ) cache_get_or_compute( # nolint: object_usage_linter key = cache_key, label = paste(csv_file, "file"), @@ -29,10 +46,10 @@ fetch_eic_csv <- function(csv_file, cache_key) { #' #' @return #' A tibble of accordingly filtered EIC codes, which contains such columns as -#' `EicCode`, `EicDisplayName`, `EicLongName`, `EicParent`, -#' `EicResponsibleParty`, `EicStatus`, `MarketParticipantPostalCode`, -#' `MarketParticipantIsoCountryCode`, `MarketParticipantVatCode`, -#' `EicTypeFunctionList` and `type`. +#' `eic_code`, `eic_display_name`, `eic_long_name`, `eic_parent`, +#' `eic_responsible_party`, `eic_status`, `market_participant_postal_code`, +#' `market_participant_iso_country_code`, `market_participant_vat_code`, +#' `eic_type_function_list` and `type`. #' #' @export #' @@ -42,10 +59,7 @@ fetch_eic_csv <- function(csv_file, cache_key) { #' dplyr::glimpse(eic_party) #' party_eic <- function() { - fetch_eic_csv( - csv_file = "X_eicCodes.csv", - cache_key = "party_eic_df_key" - ) + fetch_eic_csv(csv_file = "X_eicCodes.csv") } @@ -59,10 +73,10 @@ party_eic <- function() { #' #' @return #' A tibble of accordingly filtered EIC codes, which contains such columns as -#' `EicCode`, `EicDisplayName`, `EicLongName`, `EicParent`, -#' `EicResponsibleParty`, `EicStatus`, `MarketParticipantPostalCode`, -#' `MarketParticipantIsoCountryCode`, `MarketParticipantVatCode`, -#' `EicTypeFunctionList` and `type`. +#' `eic_code`, `eic_display_name`, `eic_long_name`, `eic_parent`, +#' `eic_responsible_party`, `eic_status`, `market_participant_postal_code`, +#' `market_participant_iso_country_code`, `market_participant_vat_code`, +#' `eic_type_function_list` and `type`. #' #' @export #' @@ -72,10 +86,7 @@ party_eic <- function() { #' dplyr::glimpse(eic_area) #' area_eic <- function() { - fetch_eic_csv( - csv_file = "Y_eicCodes.csv", - cache_key = "area_eic_df_key" - ) + fetch_eic_csv(csv_file = "Y_eicCodes.csv") } @@ -91,10 +102,10 @@ area_eic <- function() { #' #' @return #' A tibble of accordingly filtered EIC codes, which contains such columns as -#' `EicCode`, `EicDisplayName`, `EicLongName`, `EicParent`, -#' `EicResponsibleParty`, `EicStatus`, `MarketParticipantPostalCode`, -#' `MarketParticipantIsoCountryCode`, `MarketParticipantVatCode`, -#' `EicTypeFunctionList` and `type`. +#' `eic_code`, `eic_display_name`, `eic_long_name`, `eic_parent`, +#' `eic_responsible_party`, `eic_status`, `market_participant_postal_code`, +#' `market_participant_iso_country_code`, `market_participant_vat_code`, +#' `eic_type_function_list` and `type`. #' #' @export #' @@ -104,10 +115,7 @@ area_eic <- function() { #' dplyr::glimpse(eic_accounting_point) #' accounting_point_eic <- function() { - fetch_eic_csv( - csv_file = "Z_eicCodes.csv", - cache_key = "accounting_point_eic_df_key" - ) + fetch_eic_csv(csv_file = "Z_eicCodes.csv") } @@ -123,10 +131,10 @@ accounting_point_eic <- function() { #' #' @return #' A tibble of accordingly filtered EIC codes, which contains such columns as -#' `EicCode`, `EicDisplayName`, `EicLongName`, `EicParent`, -#' `EicResponsibleParty`, `EicStatus`, `MarketParticipantPostalCode`, -#' `MarketParticipantIsoCountryCode`, `MarketParticipantVatCode`, -#' `EicTypeFunctionList` and `type`. +#' `eic_code`, `eic_display_name`, `eic_long_name`, `eic_parent`, +#' `eic_responsible_party`, `eic_status`, `market_participant_postal_code`, +#' `market_participant_iso_country_code`, `market_participant_vat_code`, +#' `eic_type_function_list` and `type`. #' #' @export #' @@ -136,10 +144,7 @@ accounting_point_eic <- function() { #' dplyr::glimpse(eic_tie_line) #' tie_line_eic <- function() { - fetch_eic_csv( - csv_file = "T_eicCodes.csv", - cache_key = "tie_line_eic_df_key" - ) + fetch_eic_csv(csv_file = "T_eicCodes.csv") } @@ -154,10 +159,10 @@ tie_line_eic <- function() { #' #' @return #' A tibble of accordingly filtered EIC codes, which contains such columns as -#' `EicCode`, `EicDisplayName`, `EicLongName`, `EicParent`, -#' `EicResponsibleParty`, `EicStatus`, `MarketParticipantPostalCode`, -#' `MarketParticipantIsoCountryCode`, `MarketParticipantVatCode`, -#' `EicTypeFunctionList` and `type`. +#' `eic_code`, `eic_display_name`, `eic_long_name`, `eic_parent`, +#' `eic_responsible_party`, `eic_status`, `market_participant_postal_code`, +#' `market_participant_iso_country_code`, `market_participant_vat_code`, +#' `eic_type_function_list` and `type`. #' #' @export #' @@ -167,10 +172,7 @@ tie_line_eic <- function() { #' dplyr::glimpse(eic_location) #' location_eic <- function() { - fetch_eic_csv( - csv_file = "V_eicCodes.csv", - cache_key = "location_eic_df_key" - ) + fetch_eic_csv(csv_file = "V_eicCodes.csv") } @@ -186,10 +188,10 @@ location_eic <- function() { #' #' @return #' A tibble of accordingly filtered EIC codes, which contains such columns as -#' `EicCode`, `EicDisplayName`, `EicLongName`, `EicParent`, -#' `EicResponsibleParty`, `EicStatus`, `MarketParticipantPostalCode`, -#' `MarketParticipantIsoCountryCode`, `MarketParticipantVatCode`, -#' `EicTypeFunctionList` and `type`. +#' `eic_code`, `eic_display_name`, `eic_long_name`, `eic_parent`, +#' `eic_responsible_party`, `eic_status`, `market_participant_postal_code`, +#' `market_participant_iso_country_code`, `market_participant_vat_code`, +#' `eic_type_function_list` and `type`. #' #' @export #' @@ -199,10 +201,7 @@ location_eic <- function() { #' dplyr::glimpse(eic_resource_object) #' resource_object_eic <- function() { - fetch_eic_csv( - csv_file = "W_eicCodes.csv", - cache_key = "resource_object_eic_df_key" - ) + fetch_eic_csv(csv_file = "W_eicCodes.csv") } @@ -223,10 +222,10 @@ resource_object_eic <- function() { #' #' @return #' A tibble of accordingly filtered EIC codes, which contains such columns as -#' `EicCode`, `EicDisplayName`, `EicLongName`, `EicParent`, -#' `EicResponsibleParty`, `EicStatus`, `MarketParticipantPostalCode`, -#' `MarketParticipantIsoCountryCode`, `MarketParticipantVatCode`, -#' `EicTypeFunctionList` and `type`. +#' `eic_code`, `eic_display_name`, `eic_long_name`, `eic_parent`, +#' `eic_responsible_party`, `eic_status`, `market_participant_postal_code`, +#' `market_participant_iso_country_code`, `market_participant_vat_code`, +#' `eic_type_function_list` and `type`. #' #' @export #' @@ -236,10 +235,7 @@ resource_object_eic <- function() { #' dplyr::glimpse(eic_substation) #' substation_eic <- function() { - fetch_eic_csv( - csv_file = "A_eicCodes.csv", - cache_key = "substation_eic_df_key" - ) + fetch_eic_csv(csv_file = "A_eicCodes.csv") } @@ -255,10 +251,10 @@ substation_eic <- function() { #' #' @return #' A tibble of accordingly filtered EIC codes, which contains such columns as -#' `EicCode`, `EicDisplayName`, `EicLongName`, `EicParent`, -#' `EicResponsibleParty`, `EicStatus`, `MarketParticipantPostalCode`, -#' `MarketParticipantIsoCountryCode`, `MarketParticipantVatCode`, -#' `EicTypeFunctionList` and `type`. +#' `eic_code`, `eic_display_name`, `eic_long_name`, `eic_parent`, +#' `eic_responsible_party`, `eic_status`, `market_participant_postal_code`, +#' `market_participant_iso_country_code`, `market_participant_vat_code`, +#' `eic_type_function_list` and `type`. #' #' @importFrom dplyr bind_rows #' @@ -344,7 +340,7 @@ all_allocated_eic <- function() { #' #' @export #' -#' @importFrom httr2 request req_method req_user_agent req_timeout req_retry +#' @importFrom httr2 request req_user_agent req_timeout req_retry #' resp_body_xml #' @importFrom xml2 xml_find_all xml_find_first xml_text read_html #' @importFrom cli cli_h1 cli_h2 cli_text cli_alert_info @@ -355,7 +351,6 @@ all_allocated_eic <- function() { get_news <- function(feed_url = .feed_url, n = 5L) { resp <- feed_url |> request() |> - req_method(method = "GET") |> req_user_agent(string = user_agent_string) |> req_timeout(seconds = 30L) |> req_retry( @@ -390,7 +385,12 @@ get_news <- function(feed_url = .feed_url, n = 5L) { xml_text() |> trimws() }, - error = \(e) trimws(raw_desc) + error = \(e) { + cli_alert_warning( + "Could not parse HTML description for item {i}, using raw text." + ) + trimws(raw_desc) + } ) cli_h2("{titles[[i]]}") diff --git a/R/en_load.R b/R/en_load.R index 92d6aebd..f5afe584 100644 --- a/R/en_load.R +++ b/R/en_load.R @@ -23,8 +23,6 @@ #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string -#' @importFrom cli cli_abort #' #' @export #' @@ -42,44 +40,31 @@ #' load_actual_total <- function( eic = NULL, - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) - assert_string(security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for a (maximum) 1 year long period - query_string <- paste0( - "documentType=A65", - "&processType=A16", - "&outBiddingZone_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # compose GET request url for a (maximum) 1 year long period + run_api_query( + query_string = paste0( + "documentType=A65", + "&processType=A16", + "&outBiddingZone_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -109,8 +94,6 @@ load_actual_total <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string -#' @importFrom cli cli_abort #' #' @export #' @@ -128,44 +111,31 @@ load_actual_total <- function( #' load_day_ahead_total_forecast <- function( eic = NULL, - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) - assert_string(security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for a (maximum) 1 year long period - query_string <- paste0( - "documentType=A65", - "&processType=A01", - "&outBiddingZone_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # compose GET request url for a (maximum) 1 year long period + run_api_query( + query_string = paste0( + "documentType=A65", + "&processType=A01", + "&outBiddingZone_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -195,8 +165,6 @@ load_day_ahead_total_forecast <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string -#' @importFrom cli cli_abort #' #' @export #' @@ -212,44 +180,31 @@ load_day_ahead_total_forecast <- function( #' load_week_ahead_total_forecast <- function( eic = NULL, - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) - assert_string(security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for a (maximum) 1 year long period - query_string <- paste0( - "documentType=A65", - "&processType=A31", - "&outBiddingZone_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # compose GET request url for a (maximum) 1 year long period + run_api_query( + query_string = paste0( + "documentType=A65", + "&processType=A31", + "&outBiddingZone_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -279,8 +234,6 @@ load_week_ahead_total_forecast <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string -#' @importFrom cli cli_abort #' #' @export #' @@ -296,44 +249,31 @@ load_week_ahead_total_forecast <- function( #' load_month_ahead_total_forecast <- function( # nolint: object_length_linter eic = NULL, - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) - assert_string(security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for a (maximum) 1 year long period - query_string <- paste0( - "documentType=A65", - "&processType=A32", - "&outBiddingZone_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # compose GET request url for a (maximum) 1 year long period + run_api_query( + query_string = paste0( + "documentType=A65", + "&processType=A32", + "&outBiddingZone_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -363,8 +303,6 @@ load_month_ahead_total_forecast <- function( # nolint: object_length_linter #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string -#' @importFrom cli cli_abort #' #' @export #' @@ -380,42 +318,31 @@ load_month_ahead_total_forecast <- function( # nolint: object_length_linter #' load_year_ahead_total_forecast <- function( eic = NULL, - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) - assert_string(security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for a (maximum) 1 year long period - query_string <- paste0( - "documentType=A65", - "&processType=A33", - "&outBiddingZone_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # compose GET request url for a (maximum) 1 year long period + run_api_query( + query_string = paste0( + "documentType=A65", + "&processType=A33", + "&outBiddingZone_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -445,8 +372,6 @@ load_year_ahead_total_forecast <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string -#' @importFrom cli cli_abort #' #' @export #' @@ -462,40 +387,29 @@ load_year_ahead_total_forecast <- function( #' load_year_ahead_forecast_margin <- function( # nolint: object_length_linter eic = NULL, - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) - assert_string(security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for a (maximum) 1 year long period - query_string <- paste0( - "documentType=A70", - "&processType=A33", - "&outBiddingZone_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # compose GET request url for a (maximum) 1 year long period + run_api_query( + query_string = paste0( + "documentType=A70", + "&processType=A33", + "&outBiddingZone_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } diff --git a/R/en_market.R b/R/en_market.R index b0331826..d5cf64b0 100644 --- a/R/en_market.R +++ b/R/en_market.R @@ -25,8 +25,7 @@ #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string assert_choice -#' @importFrom cli cli_abort +#' @importFrom checkmate assert_choice #' #' @export #' @@ -45,12 +44,8 @@ implicit_offered_transfer_capacity <- function( # nolint: object_length_linter eic_in = NULL, eic_out = NULL, - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), contract_type = "A01", tidy_output = FALSE, security_token = Sys.getenv("ENTSOE_PAT") @@ -58,36 +53,27 @@ implicit_offered_transfer_capacity <- function( # nolint: object_length_linter assert_eic(eic = eic_in, var_name = "eic_in") assert_eic(eic = eic_out, var_name = "eic_out") assert_choice(x = contract_type, choices = c("A01", "A07")) - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for the denoted period - query_string <- paste0( - "documentType=A31", - "&auction.Type=A01", - "&contract_MarketAgreement.Type=", contract_type, - "&in_Domain=", eic_in, - "&out_Domain=", eic_out, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # compose GET request url for the denoted period + run_api_query( + query_string = paste0( + "documentType=A31", + "&auction.Type=A01", + "&contract_MarketAgreement.Type=", contract_type, + "&in_Domain=", eic_in, + "&out_Domain=", eic_out, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -124,8 +110,7 @@ implicit_offered_transfer_capacity <- function( # nolint: object_length_linter #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string assert_choice -#' @importFrom cli cli_abort +#' @importFrom checkmate assert_choice #' #' @export #' @@ -144,12 +129,8 @@ implicit_offered_transfer_capacity <- function( # nolint: object_length_linter explicit_offered_transfer_capacity <- function( # nolint: object_length_linter eic_in = NULL, eic_out = NULL, - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), contract_type = "A01", tidy_output = FALSE, security_token = Sys.getenv("ENTSOE_PAT") @@ -160,36 +141,27 @@ explicit_offered_transfer_capacity <- function( # nolint: object_length_linter x = contract_type, choices = c("A01", "A02", "A03", "A04", "A06", "A07", "A08") ) - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for the denoted period - query_string <- paste0( - "documentType=A31", - "&auction.Type=A02", - "&contract_MarketAgreement.Type=", contract_type, - "&in_Domain=", eic_in, - "&out_Domain=", eic_out, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # compose GET request url for the denoted period + run_api_query( + query_string = paste0( + "documentType=A31", + "&auction.Type=A02", + "&contract_MarketAgreement.Type=", contract_type, + "&in_Domain=", eic_in, + "&out_Domain=", eic_out, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -216,8 +188,6 @@ explicit_offered_transfer_capacity <- function( # nolint: object_length_linter #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string -#' @importFrom cli cli_abort #' #' @export #' @@ -235,47 +205,34 @@ explicit_offered_transfer_capacity <- function( # nolint: object_length_linter continuous_offered_transfer_capacity <- function( # nolint: object_length_linter eic_in = NULL, eic_out = NULL, - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = FALSE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic_in, var_name = "eic_in") assert_eic(eic = eic_out, var_name = "eic_out") - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for the denoted period - query_string <- paste0( - "documentType=A31", - "&auction.Type=A08", - "&contract_MarketAgreement.Type=A07", - "&in_Domain=", eic_in, - "&out_Domain=", eic_out, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # compose GET request url for the denoted period + run_api_query( + query_string = paste0( + "documentType=A31", + "&auction.Type=A08", + "&contract_MarketAgreement.Type=A07", + "&in_Domain=", eic_in, + "&out_Domain=", eic_out, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -306,8 +263,8 @@ continuous_offered_transfer_capacity <- function( # nolint: object_length_linter #' #' @return A [tibble::tibble()] with the queried data. #' -#' @importFrom checkmate assert_string assert_choice -#' @importFrom cli cli_abort +#' @importFrom checkmate assert_choice +#' @importFrom lubridate ymd days #' #' @export #' @@ -337,13 +294,8 @@ continuous_offered_transfer_capacity <- function( # nolint: object_length_linter implicit_offered_transfer_capacities <- function( # nolint: object_length_linter eic_in = NULL, eic_out = NULL, - period_start = lubridate::ymd( - x = Sys.Date() - lubridate::days(x = 1L), - tz = "CET" - ), - period_end = lubridate::ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(x = Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), contract_type = "A01", tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") @@ -351,33 +303,27 @@ implicit_offered_transfer_capacities <- function( # nolint: object_length_linter assert_eic(eic = eic_in, var_name = "eic_in") assert_eic(eic = eic_out, var_name = "eic_out") assert_choice(x = contract_type, choices = c("A01", "A07")) - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - query_string <- paste0( - "documentType=A31", - "&auction.Type=A01", - "&contract_MarketAgreement.Type=", contract_type, - "&in_Domain=", eic_in, - "&out_Domain=", eic_out, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # compose GET request url for the denoted period + run_api_query( + query_string = paste0( + "documentType=A31", + "&auction.Type=A01", + "&contract_MarketAgreement.Type=", contract_type, + "&in_Domain=", eic_in, + "&out_Domain=", eic_out, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -415,8 +361,8 @@ implicit_offered_transfer_capacities <- function( # nolint: object_length_linter #' #' @return A [tibble::tibble()] with the queried data. #' -#' @importFrom checkmate assert_string assert_choice -#' @importFrom cli cli_abort +#' @importFrom checkmate assert_choice +#' @importFrom lubridate ymd days #' #' @export #' @@ -435,49 +381,39 @@ implicit_offered_transfer_capacities <- function( # nolint: object_length_linter explicit_offered_transfer_capacities <- function( # nolint: object_length_linter eic_in = NULL, eic_out = NULL, - period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET" - ), - period_end = lubridate::ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), contract_type = "A01", tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic_in, var_name = "eic_in") assert_eic(eic = eic_out, var_name = "eic_out") - assert_string(x = security_token, min.chars = 1L) + check_sec_token(security_token = security_token) assert_choice( x = contract_type, choices = c("A01", "A02", "A03", "A04", "A06", "A07", "A08") ) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - query_string <- paste0( - "documentType=A31", - "&auction.Type=A02", - "&contract_MarketAgreement.Type=", contract_type, - "&in_Domain=", eic_in, - "&out_Domain=", eic_out, - "&periodStart=", period_start, - "&periodEnd=", period_end + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # compose GET request url for the denoted period + run_api_query( + query_string = paste0( + "documentType=A31", + "&auction.Type=A02", + "&contract_MarketAgreement.Type=", contract_type, + "&in_Domain=", eic_in, + "&out_Domain=", eic_out, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -503,8 +439,7 @@ explicit_offered_transfer_capacities <- function( # nolint: object_length_linter #' #' @return A [tibble::tibble()] with the queried data. #' -#' @importFrom checkmate assert_string -#' @importFrom cli cli_abort +#' @importFrom lubridate ymd days #' #' @export #' @@ -522,47 +457,34 @@ explicit_offered_transfer_capacities <- function( # nolint: object_length_linter continuous_offered_transfer_capacities <- function( # nolint: object_length_linter eic_in = NULL, eic_out = NULL, - period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET" - ), - period_end = lubridate::ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic_in, var_name = "eic_in") assert_eic(eic = eic_out, var_name = "eic_out") - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for the denoted period - query_string <- paste0( - "documentType=A31", - "&auction.Type=A08", - "&contract_MarketAgreement.Type=A07", - "&in_Domain=", eic_in, - "&out_Domain=", eic_out, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # compose GET request url for the denoted period + run_api_query( + query_string = paste0( + "documentType=A31", + "&auction.Type=A08", + "&contract_MarketAgreement.Type=A07", + "&in_Domain=", eic_in, + "&out_Domain=", eic_out, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -594,8 +516,7 @@ continuous_offered_transfer_capacities <- function( # nolint: object_length_lint #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string assert_choice assert_flag -#' @importFrom cli cli_abort +#' @importFrom checkmate assert_choice assert_flag #' #' @export #' @@ -613,12 +534,8 @@ continuous_offered_transfer_capacities <- function( # nolint: object_length_lint #' flow_based_allocations <- function( eic = NULL, - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), process_type = "A43", archive = FALSE, tidy_output = FALSE, @@ -630,31 +547,27 @@ flow_based_allocations <- function( choices = c("A32", "A33", "A43", "A44") ) assert_flag(archive) - assert_string(x = security_token, min.chars = 1L) - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for the denoted period - query_string <- paste0( - "documentType=B09", - "&processType=", process_type, - if (archive) "&StorageType=archive" else "", - "&in_Domain=", eic, - "&out_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # compose GET request url for the denoted period + run_api_query( + query_string = paste0( + "documentType=B09", + "&processType=", process_type, + if (archive) "&StorageType=archive" else "", + "&in_Domain=", eic, + "&out_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -691,8 +604,7 @@ flow_based_allocations <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string assert_choice -#' @importFrom cli cli_abort +#' @importFrom checkmate assert_choice #' #' @export #' @@ -711,12 +623,8 @@ flow_based_allocations <- function( auction_revenue <- function( eic_in = NULL, eic_out = NULL, - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), contract_type = "A01", tidy_output = FALSE, security_token = Sys.getenv("ENTSOE_PAT") @@ -727,36 +635,27 @@ auction_revenue <- function( x = contract_type, choices = c("A01", "A02", "A03", "A04", "A06", "A07", "A08") ) - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for the denoted period - query_string <- paste0( - "documentType=A25", - "&businessType=B07", - "&contract_MarketAgreement.Type=", contract_type, - "&in_Domain=", eic_in, - "&out_Domain=", eic_out, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # compose GET request url for the denoted period + run_api_query( + query_string = paste0( + "documentType=A25", + "&businessType=B07", + "&contract_MarketAgreement.Type=", contract_type, + "&in_Domain=", eic_in, + "&out_Domain=", eic_out, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -783,8 +682,6 @@ auction_revenue <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string -#' @importFrom cli cli_abort #' #' @export #' @@ -802,46 +699,33 @@ auction_revenue <- function( total_nominated_capacity <- function( eic_in = NULL, eic_out = NULL, - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic_in, var_name = "eic_in") assert_eic(eic = eic_out, var_name = "eic_out") - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for the denoted period - query_string <- paste0( - "documentType=A26", - "&businessType=B08", - "&in_Domain=", eic_in, - "&out_Domain=", eic_out, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # compose GET request url for the denoted period + run_api_query( + query_string = paste0( + "documentType=A26", + "&businessType=B08", + "&in_Domain=", eic_in, + "&out_Domain=", eic_out, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -886,8 +770,7 @@ total_nominated_capacity <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string assert_choice -#' @importFrom cli cli_abort +#' @importFrom checkmate assert_choice #' #' @export #' @@ -905,12 +788,8 @@ total_nominated_capacity <- function( already_allocated_total_capacity <- function( # nolint: object_length_linter eic_in = NULL, eic_out = NULL, - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), auction_category = "A04", contract_type = "A01", tidy_output = FALSE, @@ -918,13 +797,7 @@ already_allocated_total_capacity <- function( # nolint: object_length_linter ) { assert_eic(eic = eic_in, var_name = "eic_in") assert_eic(eic = eic_out, var_name = "eic_out") - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - + check_sec_token(security_token = security_token) assert_choice( x = auction_category, choices = c("A01", "A02", "A03", "A04") @@ -933,31 +806,27 @@ already_allocated_total_capacity <- function( # nolint: object_length_linter x = contract_type, choices = c("A01", "A02", "A03", "A04", "A06", "A07", "A08") ) - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for the denoted period - query_string <- paste0( - "documentType=A26", - "&businessType=A29", - "&contract_MarketAgreement.Type=", contract_type, - "&auction.Category=", auction_category, - "&in_Domain=", eic_in, - "&out_Domain=", eic_out, - "&periodStart=", period_start, - "&periodEnd=", period_end + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # compose GET request url for the denoted period + run_api_query( + query_string = paste0( + "documentType=A26", + "&businessType=A29", + "&contract_MarketAgreement.Type=", contract_type, + "&auction.Category=", auction_category, + "&in_Domain=", eic_in, + "&out_Domain=", eic_out, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -985,8 +854,6 @@ already_allocated_total_capacity <- function( # nolint: object_length_linter #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string -#' @importFrom cli cli_abort #' #' @export #' @@ -1013,47 +880,34 @@ already_allocated_total_capacity <- function( # nolint: object_length_linter #' energy_prices <- function( eic = NULL, - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), contract_type = "A01", tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) assert_choice(x = contract_type, choices = c("A01", "A07")) - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for the denoted period - query_string <- paste0( - "documentType=A44", - "&in_Domain=", eic, - "&out_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end, - "&contract_MarketAgreement.type=", contract_type + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # compose GET request url for the denoted period + run_api_query( + query_string = paste0( + "documentType=A44", + "&in_Domain=", eic, + "&out_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end, + "&contract_MarketAgreement.type=", contract_type + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -1081,8 +935,7 @@ energy_prices <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string assert_choice -#' @importFrom cli cli_abort +#' @importFrom checkmate assert_choice #' #' @export #' @@ -1099,48 +952,35 @@ energy_prices <- function( #' net_positions <- function( eic = NULL, - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), contract_type = "A01", tidy_output = FALSE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) assert_choice(x = contract_type, choices = c("A01", "A07")) - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for the denoted period - query_string <- paste0( - "documentType=A25", - "&businessType=B09", - "&contract_MarketAgreement.Type=", contract_type, - "&in_Domain=", eic, - "&out_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # compose GET request url for the denoted period + run_api_query( + query_string = paste0( + "documentType=A25", + "&businessType=B09", + "&contract_MarketAgreement.Type=", contract_type, + "&in_Domain=", eic, + "&out_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -1176,8 +1016,7 @@ net_positions <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string assert_choice -#' @importFrom cli cli_abort +#' @importFrom checkmate assert_choice #' #' @export #' @@ -1194,12 +1033,8 @@ net_positions <- function( #' congestion_income <- function( eic = NULL, - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), contract_type = "A01", tidy_output = FALSE, security_token = Sys.getenv("ENTSOE_PAT") @@ -1209,36 +1044,27 @@ congestion_income <- function( x = contract_type, choices = c("A01", "A02", "A03", "A04", "A06", "A07", "A08") ) - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for the denoted period - query_string <- paste0( - "documentType=A25", - "&businessType=B10", - "&contract_MarketAgreement.Type=", contract_type, - "&in_Domain=", eic, - "&out_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # compose GET request url for the denoted period + run_api_query( + query_string = paste0( + "documentType=A25", + "&businessType=B10", + "&contract_MarketAgreement.Type=", contract_type, + "&in_Domain=", eic, + "&out_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -1281,8 +1107,7 @@ congestion_income <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string assert_choice assert_count -#' @importFrom cli cli_abort +#' @importFrom checkmate assert_choice assert_count #' #' @export #' @@ -1303,12 +1128,8 @@ congestion_income <- function( allocated_transfer_capacities_3rd_countries <- function( # nolint: object_length_linter eic_in = NULL, eic_out = NULL, - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), contract_type = "A01", auction_category = "A04", position = 1L, @@ -1326,40 +1147,35 @@ allocated_transfer_capacities_3rd_countries <- function( # nolint: object_length choices = c("A01", "A02", "A03", "A04") ) assert_count(position, positive = TRUE) - assert_string(x = security_token, min.chars = 1L) - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for the denoted period - query_string <- paste0( - "documentType=A94", - "&auction.Type=A02", - "&contract_MarketAgreement.Type=", contract_type, - "&in_Domain=", eic_in, - "&out_Domain=", eic_out, - if (!is.null(auction_category)) { - paste0("&auction.Category=", auction_category) - }, - if (!is.null(position)) { - paste0( - "&classificationSequence_AttributeInstanceComponent.Position=", - as.integer(position) - ) - }, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A94", + "&auction.Type=A02", + "&contract_MarketAgreement.Type=", contract_type, + "&in_Domain=", eic_in, + "&out_Domain=", eic_out, + if (!is.null(auction_category)) { + paste0("&auction.Category=", auction_category) + }, + if (!is.null(position)) { + paste0( + "&classificationSequence_AttributeInstanceComponent.Position=", + as.integer(position) + ) + }, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -1383,8 +1199,6 @@ allocated_transfer_capacities_3rd_countries <- function( # nolint: object_length #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string -#' @importFrom cli cli_abort #' #' @export #' @@ -1400,45 +1214,32 @@ allocated_transfer_capacities_3rd_countries <- function( # nolint: object_length #' intraday_prices <- function( eic = NULL, - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for the denoted period - query_string <- paste0( - "documentType=A44", - "&contract_MarketAgreement.Type=A07", - "&in_Domain=", eic, - "&out_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A44", + "&contract_MarketAgreement.Type=A07", + "&in_Domain=", eic, + "&out_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -1469,9 +1270,8 @@ intraday_prices <- function( #' #' @return A [tibble::tibble()] with the queried data. #' -#' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string assert_choice -#' @importFrom cli cli_abort +#' @importFrom lubridate ymd days years +#' @importFrom checkmate assert_choice #' #' @export #' @@ -1489,12 +1289,8 @@ intraday_prices <- function( aggregated_bids <- function( eic = NULL, process_type = NULL, - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { @@ -1503,32 +1299,23 @@ aggregated_bids <- function( x = process_type, choices = c("A51", "A46", "A47", "A60", "A61", "A67", "A68") ) - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for the denoted period - query_string <- paste0( - "documentType=A24", - "&processType=", process_type, - "&area_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A24", + "&processType=", process_type, + "&area_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } diff --git a/R/en_outages.R b/R/en_outages.R index 03a5132c..ebc7029d 100644 --- a/R/en_outages.R +++ b/R/en_outages.R @@ -54,12 +54,8 @@ #' outages_both <- function( eic = NULL, - period_start = ymd(Sys.Date() + days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date() + days(x = 2L), - tz = "CET" - ), + period_start = ymd(Sys.Date() + days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date() + days(x = 2L), tz = "CET"), doc_status = NULL, event_nature = NULL, tidy_output = TRUE, @@ -146,8 +142,7 @@ outages_both <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string assert_choice -#' @importFrom cli cli_abort +#' @importFrom checkmate assert_choice #' #' @export #' @@ -168,19 +163,15 @@ outages_both <- function( #' outages_gen_units <- function( eic = NULL, - period_start = ymd(Sys.Date() + days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date() + days(x = 2L), - tz = "CET" - ), + period_start = ymd(Sys.Date() + days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date() + days(x = 2L), tz = "CET"), doc_status = NULL, event_nature = NULL, tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) - assert_string(x = security_token, min.chars = 1L) + check_sec_token(security_token = security_token) assert_choice( x = doc_status, choices = c("A05", "A09", "A13"), null.ok = TRUE @@ -189,38 +180,25 @@ outages_gen_units <- function( x = event_nature, choices = c("A53", "A54"), null.ok = TRUE ) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for a (maximum) 1 year long period - query_string <- paste0( - "documentType=A80", - "&biddingZone_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - if (!is.null(doc_status)) { - query_string <- paste0(query_string, "&docStatus=", doc_status) - } - if (!is.null(event_nature)) { - query_string <- paste0(query_string, "&businessType=", event_nature) - } - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A80", + "&biddingZone_Domain=", eic, + if (!is.null(doc_status)) paste0("&docStatus=", doc_status), + if (!is.null(event_nature)) paste0("&businessType=", event_nature), + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -260,8 +238,7 @@ outages_gen_units <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string assert_choice -#' @importFrom cli cli_abort +#' @importFrom checkmate assert_choice #' #' @export #' @@ -284,19 +261,15 @@ outages_gen_units <- function( #' outages_prod_units <- function( eic = NULL, - period_start = ymd(Sys.Date() + days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date() + days(x = 2L), - tz = "CET" - ), + period_start = ymd(Sys.Date() + days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date() + days(x = 2L), tz = "CET"), doc_status = NULL, event_nature = NULL, tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) - assert_string(x = security_token, min.chars = 1L) + check_sec_token(security_token = security_token) assert_choice( doc_status, choices = c("A05", "A09", "A13"), null.ok = TRUE @@ -305,38 +278,25 @@ outages_prod_units <- function( event_nature, choices = c("A53", "A54"), null.ok = TRUE ) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for a (maximum) 1 year long period - query_string <- paste0( - "documentType=A77", - "&biddingZone_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - if (!is.null(doc_status)) { - query_string <- paste0(query_string, "&docStatus=", doc_status) - } - if (!is.null(event_nature)) { - query_string <- paste0(query_string, "&businessType=", event_nature) - } - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A77", + "&biddingZone_Domain=", eic, + if (!is.null(doc_status)) paste0("&docStatus=", doc_status), + if (!is.null(event_nature)) paste0("&businessType=", event_nature), + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -372,8 +332,7 @@ outages_prod_units <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string assert_choice -#' @importFrom cli cli_abort +#' @importFrom checkmate assert_choice #' #' @export #' @@ -391,51 +350,36 @@ outages_prod_units <- function( #' outages_offshore_grid <- function( eic = NULL, - period_start = ymd(Sys.Date() + days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date() + days(x = 2L), - tz = "CET" - ), + period_start = ymd(Sys.Date() + days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date() + days(x = 2L), tz = "CET"), doc_status = NULL, tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) - assert_string(x = security_token, min.chars = 1L) + check_sec_token(security_token = security_token) assert_choice( doc_status, choices = c("A05", "A09", "A13"), null.ok = TRUE ) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for a (maximum) 1 year long period - query_string <- paste0( - "documentType=A79", - "&biddingZone_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - if (!is.null(doc_status)) { - query_string <- paste0(query_string, "&docStatus=", doc_status) - } - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A79", + "&biddingZone_Domain=", eic, + if (!is.null(doc_status)) paste0("&docStatus=", doc_status), + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -462,10 +406,8 @@ outages_offshore_grid <- function( #' One year range limit applies #' @param period_start_update notification submission/update starting date #' in POSIXct or YYYY-MM-DD HH:MM:SS format -#' One year range limit applies #' @param period_end_update notification submission/update ending date #' in POSIXct or YYYY-MM-DD HH:MM:SS format -#' One year range limit applies #' @param doc_status Notification document status. "A05" for active, #' "A09" for cancelled and "A13" for withdrawn. #' Defaults to NULL which means "A05" and "A09" together. @@ -480,8 +422,7 @@ outages_offshore_grid <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string assert_choice -#' @importFrom cli cli_abort +#' @importFrom checkmate assert_choice #' #' @export #' @@ -496,12 +437,8 @@ outages_offshore_grid <- function( #' outages_cons_units <- function( eic = NULL, - period_start = ymd(Sys.Date() + days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date() + days(x = 2L), - tz = "CET" - ), + period_start = ymd(Sys.Date() + days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date() + days(x = 2L), tz = "CET"), period_start_update = NULL, period_end_update = NULL, doc_status = NULL, @@ -510,7 +447,7 @@ outages_cons_units <- function( security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) - assert_string(x = security_token, min.chars = 1L) + check_sec_token(security_token = security_token) assert_choice( doc_status, choices = c("A05", "A09", "A13"), null.ok = TRUE @@ -519,47 +456,35 @@ outages_cons_units <- function( event_nature, choices = c("A53", "A54"), null.ok = TRUE ) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - period_start_update <- url_posixct_format(period_start_update) - period_end_update <- url_posixct_format(period_end_update) - - # compose GET request url for a (maximum) 1 year long period - query_string <- paste0( - "documentType=A76", - "&biddingZone_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - if (!is.null(doc_status)) { - query_string <- paste0(query_string, "&docStatus=", doc_status) - } - if (!is.null(event_nature)) { - query_string <- paste0(query_string, "&businessType=", event_nature) - } - if (!is.null(period_start_update) && !is.null(period_end_update)) { - query_string <- paste0( - query_string, - "&periodStartUpdate=", period_start_update, - "&periodEndUpdate=", period_end_update - ) - } - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A76", + "&biddingZone_Domain=", eic, + if (!is.null(doc_status)) paste0("&docStatus=", doc_status), + if (!is.null(event_nature)) paste0("&businessType=", event_nature), + if (!is.null(period_start_update) && !is.null(period_end_update)) { + period_update <- check_period( + period_start = period_start_update, + period_end = period_end_update + ) + paste0( + "&periodStartUpdate=", period_update$start, + "&periodEndUpdate=", period_update$end + ) + }, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -599,8 +524,7 @@ outages_cons_units <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string assert_choice -#' @importFrom cli cli_abort +#' @importFrom checkmate assert_choice #' #' @export #' @@ -628,12 +552,8 @@ outages_cons_units <- function( outages_transmission_grid <- function( eic_in = NULL, eic_out = NULL, - period_start = ymd(Sys.Date() + days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date() + days(x = 3L), - tz = "CET" - ), + period_start = ymd(Sys.Date() + days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date() + days(x = 3L), tz = "CET"), period_start_update = NULL, period_end_update = NULL, doc_status = NULL, @@ -643,7 +563,7 @@ outages_transmission_grid <- function( ) { assert_eic(eic = eic_in, var_name = "eic_in") assert_eic(eic = eic_out, var_name = "eic_out") - assert_string(x = security_token, min.chars = 1L) + check_sec_token(security_token = security_token) assert_choice( doc_status, choices = c("A05", "A09", "A13"), null.ok = TRUE @@ -652,48 +572,36 @@ outages_transmission_grid <- function( event_nature, choices = c("A53", "A54"), null.ok = TRUE ) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - period_start_update <- url_posixct_format(period_start_update) - period_end_update <- url_posixct_format(period_end_update) - - # compose GET request url for a (maximum) 1 year long period - query_string <- paste0( - "documentType=A78", - "&in_Domain=", eic_in, - "&out_domain=", eic_out, - "&periodStart=", period_start, - "&periodEnd=", period_end + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - if (!is.null(doc_status)) { - query_string <- paste0(query_string, "&docStatus=", doc_status) - } - if (!is.null(event_nature)) { - query_string <- paste0(query_string, "&businessType=", event_nature) - } - if (!is.null(period_start_update) && !is.null(period_end_update)) { - query_string <- paste0( - query_string, - "&periodStartUpdate=", period_start_update, - "&periodEndUpdate=", period_end_update - ) - } - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A78", + "&in_Domain=", eic_in, + "&out_domain=", eic_out, + if (!is.null(doc_status)) paste0("&docStatus=", doc_status), + if (!is.null(event_nature)) paste0("&businessType=", event_nature), + if (!is.null(period_start_update) && !is.null(period_end_update)) { + period_update <- check_period( + period_start = period_start_update, + period_end = period_end_update + ) + paste0( + "&periodStartUpdate=", period_update$start, + "&periodEndUpdate=", period_update$end + ) + }, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -733,8 +641,7 @@ outages_transmission_grid <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string assert_choice -#' @importFrom cli cli_abort +#' @importFrom checkmate assert_choice #' #' @export #' @@ -750,12 +657,8 @@ outages_transmission_grid <- function( #' outages_fallbacks <- function( eic = NULL, - period_start = ymd(Sys.Date() - days(x = 7L), - tz = "CET" - ), - period_end = ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 7L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), process_type = "A63", event_nature = "A53", tidy_output = TRUE, @@ -767,33 +670,24 @@ outages_fallbacks <- function( event_nature, choices = c("C47", "A53", "A54", "A83") ) - assert_string(x = security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for a (maximum) 1 year long period - query_string <- paste0( - "documentType=A53", - "&biddingZone_Domain=", eic, - "&processType=", process_type, - "&businessType=", event_nature, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A53", + "&biddingZone_Domain=", eic, + "&processType=", process_type, + "&businessType=", event_nature, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } diff --git a/R/en_transmission.R b/R/en_transmission.R index 88293b93..4c1e2d42 100644 --- a/R/en_transmission.R +++ b/R/en_transmission.R @@ -29,8 +29,7 @@ #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string assert_choice -#' @importFrom cli cli_abort +#' @importFrom checkmate assert_choice #' #' @export #' @@ -52,12 +51,8 @@ expansion_and_dismantling_project <- function( # nolint: object_length_linter eic_in = NULL, eic_out = NULL, - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), business_type = NULL, doc_status = NULL, tidy_output = TRUE, @@ -65,7 +60,7 @@ expansion_and_dismantling_project <- function( # nolint: object_length_linter ) { assert_eic(eic = eic_in, var_name = "eic_in") assert_eic(eic = eic_out, var_name = "eic_out") - assert_string(security_token, min.chars = 1L) + check_sec_token(security_token = security_token) assert_choice( business_type, choices = c("B01", "B02"), null.ok = TRUE @@ -75,30 +70,25 @@ expansion_and_dismantling_project <- function( # nolint: object_length_linter choices = c("A01", "A02", "A05", "A09", "A13", "X01"), null.ok = TRUE ) - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for the denoted period - query_string <- paste0( - "documentType=A90", - "&in_Domain=", eic_in, - "&out_Domain=", eic_out, - "&periodStart=", period_start, - "&periodEnd=", period_end, - "&businessType=", business_type, - "&DocStatus=", doc_status + period <- check_period( + period_start = period_start, + period_end = period_end ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A90", + "&in_Domain=", eic_in, + "&out_Domain=", eic_out, + "&periodStart=", period$start, + "&periodEnd=", period$end, + "&businessType=", business_type, + "&DocStatus=", doc_status + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -124,8 +114,6 @@ expansion_and_dismantling_project <- function( # nolint: object_length_linter #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string -#' @importFrom cli cli_abort #' #' @export #' @@ -143,45 +131,32 @@ expansion_and_dismantling_project <- function( # nolint: object_length_linter intraday_cross_border_transfer_limits <- function( # nolint: object_length_linter eic_in = NULL, eic_out = NULL, - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic_in, var_name = "eic_in") assert_eic(eic = eic_out, var_name = "eic_out") - assert_string(security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for the denoted period - query_string <- paste0( - "documentType=A93", - "&in_Domain=", eic_in, - "&out_Domain=", eic_out, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A93", + "&in_Domain=", eic_in, + "&out_Domain=", eic_out, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -210,8 +185,7 @@ intraday_cross_border_transfer_limits <- function( # nolint: object_length_linte #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string assert_choice -#' @importFrom cli cli_abort +#' @importFrom checkmate assert_choice #' #' @export #' @@ -253,35 +227,26 @@ forecasted_transfer_capacities <- function( x = market_agreement_type, choices = c("A01", "A02", "A03", "A04") ) - assert_string(security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for the denoted period - query_string <- paste0( - "documentType=A61", - "&contract_MarketAgreement.Type=", market_agreement_type, - "&in_Domain=", eic_in, - "&out_Domain=", eic_out, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A61", + "&contract_MarketAgreement.Type=", market_agreement_type, + "&in_Domain=", eic_in, + "&out_Domain=", eic_out, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -306,8 +271,6 @@ forecasted_transfer_capacities <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string -#' @importFrom cli cli_abort #' #' @export #' @@ -333,46 +296,33 @@ forecasted_transfer_capacities <- function( day_ahead_commercial_sched <- function( eic_in = NULL, eic_out = NULL, - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic_in, var_name = "eic_in") assert_eic(eic = eic_out, var_name = "eic_out") - assert_string(security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for the denoted period - query_string <- paste0( - "documentType=A09", - "&contract_MarketAgreement.Type=A01", - "&in_Domain=", eic_in, - "&out_Domain=", eic_out, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A09", + "&contract_MarketAgreement.Type=A01", + "&in_Domain=", eic_in, + "&out_Domain=", eic_out, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -398,8 +348,6 @@ day_ahead_commercial_sched <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string -#' @importFrom cli cli_abort #' #' @export #' @@ -427,44 +375,33 @@ day_ahead_commercial_sched <- function( total_commercial_sched <- function( eic_in = NULL, eic_out = NULL, - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic_in, var_name = "eic_in") assert_eic(eic = eic_out, var_name = "eic_out") - assert_string(security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for the denoted period - query_string <- paste0( - "documentType=A09", - "&contract_MarketAgreement.Type=A05", - "&in_Domain=", eic_in, - "&out_Domain=", eic_out, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A09", + "&contract_MarketAgreement.Type=A05", + "&in_Domain=", eic_in, + "&out_Domain=", eic_out, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -490,8 +427,6 @@ total_commercial_sched <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string -#' @importFrom cli cli_abort #' #' @export #' @@ -519,45 +454,32 @@ total_commercial_sched <- function( cross_border_physical_flows <- function( eic_in = NULL, eic_out = NULL, - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic_in, var_name = "eic_in") assert_eic(eic = eic_out, var_name = "eic_out") - assert_string(security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for the denoted period - query_string <- paste0( - "documentType=A11", - "&in_Domain=", eic_in, - "&out_Domain=", eic_out, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A11", + "&in_Domain=", eic_in, + "&out_Domain=", eic_out, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -581,8 +503,6 @@ cross_border_physical_flows <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string -#' @importFrom cli cli_abort #' #' @export #' @@ -601,41 +521,32 @@ cross_border_physical_flows <- function( redispatching_cross_border <- function( eic_in = NULL, eic_out = NULL, - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic_in, var_name = "eic_in") assert_eic(eic = eic_out, var_name = "eic_out") - assert_string(security_token, min.chars = 1L) - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url - query_string <- paste0( - "documentType=A63", - "&businessType=A46", - "&in_Domain=", eic_in, - "&out_Domain=", eic_out, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A63", + "&businessType=A46", + "&in_Domain=", eic_in, + "&out_Domain=", eic_out, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -658,8 +569,6 @@ redispatching_cross_border <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string -#' @importFrom cli cli_abort #' #' @export #' @@ -676,40 +585,31 @@ redispatching_cross_border <- function( #' redispatching_internal <- function( eic = NULL, - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) - assert_string(security_token, min.chars = 1L) - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url - query_string <- paste0( - "documentType=A63", - "&businessType=A85", - "&in_Domain=", eic, - "&out_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A63", + "&businessType=A85", + "&in_Domain=", eic, + "&out_Domain=", eic, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -735,8 +635,6 @@ redispatching_internal <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string -#' @importFrom cli cli_abort #' #' @export #' @@ -755,40 +653,31 @@ redispatching_internal <- function( countertrading <- function( eic_in = NULL, eic_out = NULL, - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic_in, var_name = "eic_in") assert_eic(eic = eic_out, var_name = "eic_out") - assert_string(security_token, min.chars = 1L) - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url - query_string <- paste0( - "documentType=A91", - "&in_Domain=", eic_in, - "&out_Domain=", eic_out, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A91", + "&in_Domain=", eic_in, + "&out_Domain=", eic_out, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } @@ -817,8 +706,7 @@ countertrading <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string assert_choice -#' @importFrom cli cli_abort +#' @importFrom checkmate assert_choice #' #' @export #' @@ -835,52 +723,37 @@ countertrading <- function( #' costs_of_congestion_management <- function( eic = NULL, - period_start = ymd(Sys.Date() - days(x = 31L), - tz = "CET" - ), - period_end = ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 31L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), event_nature = NULL, tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic) - assert_string(security_token, min.chars = 1L) + check_sec_token(security_token = security_token) assert_choice( event_nature, choices = c("A46", "B03", "B04"), null.ok = TRUE ) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url - query_string <- paste0( - "documentType=A92", - "&in_Domain=", eic, - "&out_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end - ) - if (!is.null(event_nature)) { - query_string <- paste0(query_string, "&businessType=", event_nature) - } - - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A92", + "&in_Domain=", eic, + "&out_Domain=", eic, + if (!is.null(event_nature)) paste0("&businessType=", event_nature), + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output + ) } @@ -911,8 +784,7 @@ costs_of_congestion_management <- function( #' @return A [tibble::tibble()] with the queried data. #' #' @importFrom lubridate ymd days -#' @importFrom checkmate assert_string assert_choice -#' @importFrom cli cli_abort +#' @importFrom checkmate assert_choice #' #' @export #' @@ -932,45 +804,32 @@ net_transfer_capacities <- function( eic_in = NULL, eic_out = NULL, contract_type = "A02", - period_start = ymd(Sys.Date() - days(x = 1L), - tz = "CET" - ), - period_end = ymd(Sys.Date(), - tz = "CET" - ), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { assert_eic(eic = eic_in, var_name = "eic_in") assert_eic(eic = eic_out, var_name = "eic_out") assert_choice(x = contract_type, choices = c("A02", "A03", "A04")) - assert_string(security_token, min.chars = 1L) - - # check if the requested period is not longer than one year - if (difftime(period_end, period_start, units = "day") > 365L) { - cli_abort("One year range limit should be applied!") - } - - # convert timestamps into accepted format - period_start <- url_posixct_format(period_start) - period_end <- url_posixct_format(period_end) - - # compose GET request url for the denoted period - query_string <- paste0( - "documentType=A61", - "&contract_MarketAgreement.Type=", contract_type, - "&in_Domain=", eic_in, - "&out_Domain=", eic_out, - "&periodStart=", period_start, - "&periodEnd=", period_end + check_sec_token(security_token = security_token) + period <- check_period( + period_start = period_start, + period_end = period_end, + period_length = "1 year" ) - # send GET request - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token + # send GET request and return with the extracted response + run_api_query( + query_string = paste0( + "documentType=A61", + "&contract_MarketAgreement.Type=", contract_type, + "&in_Domain=", eic_in, + "&out_Domain=", eic_out, + "&periodStart=", period$start, + "&periodEnd=", period$end + ), + security_token = security_token, + tidy_output = tidy_output ) - - # return with the extracted response - extract_response(content = en_cont_list, tidy_output = tidy_output) } diff --git a/R/utils.R b/R/utils.R index b2e8b76a..9000c53c 100644 --- a/R/utils.R +++ b/R/utils.R @@ -162,6 +162,40 @@ assert_eic <- function(eic, var_name = "eic", null_ok = FALSE) { } +#' @title +#' Validate a security token +#' +#' @description +#' Asserts that `security_token` is a non-empty string that does not contain +#' URL-sensitive characters (`?` or `&`), which would corrupt the query string +#' sent to the ENTSO-E API and generally complies with the UUID v4 format, +#' which is a 32-character hexadecimal string in the format: +#' xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. +#' +#' @param security_token A character scalar to validate. +#' +#' @return Invisibly returns `security_token`. +#' Called for its side-effect (assertion). +#' +#' @importFrom checkmate test_string +#' @importFrom cli cli_abort +#' +#' @noRd +check_sec_token <- function(security_token) { + uuid_v4_pattern <- paste( + "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}", + "[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$", + sep = "-" + ) + if (!test_string(x = security_token, pattern = uuid_v4_pattern)) { + cli_abort( + "The {.arg security_token} should comply with the UUID v4 format!" + ) + } + invisible(security_token) +} + + #' @title #' Calculate the Number of Children for a Given Nodeset #' @@ -738,9 +772,9 @@ tidy_or_not <- function(tbl, tidy_output = FALSE) { ) # if curve_type is 'A01' or absent, do nothing; otherwise branch by type - if (length(curve_type) == 0L || curve_type == "A01") { + if (length(curve_type) == 0L || identical(x = curve_type, y = "A01")) { # no adjustment needed - } else if (curve_type == "A03") { + } else if (identical(curve_type, "A03")) { ts_resolution_requ_length <- ts_resolution_real_length <- ts_mrid <- NULL ts_resolution_ok <- ts_time_interval_start <- ts_time_interval_end <- NULL @@ -1001,7 +1035,7 @@ read_zipped_xml <- function(temp_file_path) { #' #' @importFrom checkmate assert_string #' @importFrom cli cli_h1 cli_alert cli_alert_success cli_abort -#' @importFrom httr2 request req_method req_user_agent req_verbose req_timeout +#' @importFrom httr2 request req_user_agent req_verbose req_timeout #' req_retry resp_status resp_content_type resp_body_raw resp_body_xml #' resp_body_html resp_body_json resp_status_desc req_headers #' @importFrom xmlconvert xml_to_list @@ -1016,8 +1050,8 @@ api_req <- function( query_string = NULL, security_token = NULL ) { - assert_string(query_string) - assert_string(security_token) + assert_string(x = query_string) + assert_string(x = security_token) url <- paste0(api_scheme, api_domain, api_name, query_string) cli_h1("API call") cli_alert("{url}&securityToken=<...>") @@ -1025,7 +1059,6 @@ api_req <- function( # retrieve data from the API req <- url |> request() |> - req_method(method = "GET") |> req_user_agent(string = user_agent_string) |> req_headers(SECURITY_TOKEN = security_token) |> req_verbose( @@ -1069,19 +1102,23 @@ api_req <- function( ) # read the xml content from each the decompressed files - en_cont_list <- read_zipped_xml(temp_file_path = temp_file_path) - - # return with the xml content list - en_cont_list + # and return with it + temp_file_path |> read_zipped_xml() } else if (rhct %in% expt_xml) { - # read the xml content from the response and return - result_obj |> - resp_body_xml(encoding = "UTF-8") + # read the xml content from the response and return with it + result_obj |> resp_body_xml(encoding = "UTF-8") } else { cli_abort( - "Not known response content-type: {result_obj$headers$`content-type`}" + paste( + "Not known response content-type:", + "{result_obj$headers$`content-type`}" + ) ) } + } else { + cli_abort( + "Unexpected HTTP {resp_status(resp = result_obj)} response" + ) } } else { error_obj <- resp$error @@ -1166,7 +1203,7 @@ api_req <- function( cli_abort(paste(response_reason, collapse = "\n")) } else { - cli_abort("{response_reason$code}: {response_reason$text}") + cli_abort(paste(response_reason, collapse = "\n")) } } @@ -1203,6 +1240,74 @@ api_req_safe <- safely(api_req) req_perform_safe <- safely(req_perform) +#' @title +#' Validate and format a period_start/period_end pair +#' +#' @param period_start POSIXct or character timestamp. +#' @param period_end POSIXct or character timestamp. +#' @param period_length n day(s) or n year(s) denoted as a text or NULL. +#' One can define the maximum allowed timespan between the period start date +#' and the end date. If NULL is provided, then it means no check. +#' +#' @return A named list with elements `start` and `end`, each a character +#' scalar in the format accepted by the ENTSO-E API. +#' +#' @importFrom lubridate years days +#' @importFrom stringr str_to_lower str_remove str_detect +#' @importFrom cli cli_abort +#' @importFrom checkmate assert_character +#' +#' @noRd +check_period <- function(period_start, period_end, period_length = NULL) { + if (sum(is.null(period_start), is.null(period_end)) > 0L) { + cli_abort("the period should have both start and end") + } + if (!is.null(period_length)) { + period_length <- str_to_lower(string = period_length) |> + trimws() + assert_character( + x = period_length, + pattern = "^[0-9]+\\s*(year|day)s?$" + ) + period_nr <- str_remove(string = period_length, pattern = "(day|year)s?") |> + as.integer() + if (str_detect(string = period_length, pattern = "days?$")) { + if (period_end > period_start + days(x = period_nr)) { + cli_abort("{period_nr} day{?s} range limit should be applied!") + } + } else { + if (period_end > period_start + years(x = period_nr)) { + cli_abort("{period_nr} year{?s} range limit should be applied!") + } + } + } + list( + start = url_posixct_format(period_start), + end = url_posixct_format(period_end) + ) +} + + +#' @title +#' Perform an ENTSO-E API request and extract the response +#' +#' @param query_string Character scalar. The query string to append to the +#' base API URL. +#' @param security_token Character scalar. The ENTSO-E security token. +#' @param tidy_output Logical scalar. Passed to `extract_response`. +#' +#' @return A [tibble::tibble()] with the queried data. +#' +#' @noRd +run_api_query <- function(query_string, security_token, tidy_output) { + en_cont_list <- api_req_safe( + query_string = query_string, + security_token = security_token + ) + extract_response(content = en_cont_list, tidy_output = tidy_output) +} + + #' @title #' converts the given POSIXct or character timestamp into the acceptable format #' @@ -1272,7 +1377,7 @@ url_posixct_format <- function(x) { #' #' @return A tibble of EIC codes parsed from the downloaded CSV file. #' -#' @importFrom stringr str_replace_all +#' @importFrom stringr str_replace_all str_detect #' @importFrom utils read.table #' @importFrom cli cli_abort cli_alert_danger #' @@ -1292,8 +1397,13 @@ get_eiccodes <- function( # unfortunately there is no general rule for that, # hence it must be set manually!! readlines_safe <- safely(readLines) - content <- suppressWarnings( - expr = readlines_safe(con = complete_url, encoding = "UTF-8") + content <- withCallingHandlers( + expr = readlines_safe(con = complete_url, encoding = "UTF-8"), + warning = \(w) { + is_ifl <- conditionMessage(w) |> + str_detect(pattern = "incomplete final line") + if (is_ifl) invokeRestart("muffleWarning") + } ) if (is.null(content$error)) { lns <- content$result |> @@ -1349,7 +1459,7 @@ get_eiccodes <- function( #' enriched with document-status definitions. #' #' @importFrom stats setNames runif -#' @importFrom httr2 request req_url_path_append req_method req_user_agent +#' @importFrom httr2 request req_url_path_append req_user_agent #' req_progress req_verbose req_timeout req_retry resp_body_raw #' @importFrom xml2 as_xml_document xml_contents xml_children xml_name xml_text #' @importFrom cli cli_alert_success cli_progress_bar cli_progress_update @@ -1375,7 +1485,6 @@ get_all_allocated_eic <- function( req <- paste0(pd_scheme, pd_domain) |> request() |> req_url_path_append(pd_alloc_eic) |> - req_method(method = "GET") |> req_user_agent(string = user_agent_string) |> req_progress() |> req_verbose( @@ -1783,7 +1892,7 @@ get_resource_object_eic <- function() { add_eic_names <- function(tbl) { if (is.null(tbl)) return(data.frame()) - affected_cols <- c() + affected_cols <- character(0L) # special case: ts_registered_resource_mrid uses a different lookup table if ("ts_registered_resource_mrid" %in% names(tbl)) { @@ -1920,7 +2029,7 @@ add_definitions <- function(tbl) { ) tbl_names <- names(tbl) - affected_cols <- c() + affected_cols <- character(0L) specs_idx <- def_specs |> vapply(FUN = \(ds) pluck(ds, 1L) %in% tbl_names, FUN.VALUE = TRUE) |> which() @@ -2018,7 +2127,7 @@ add_definitions <- function(tbl) { xml_to_table <- function(xml_content, tidy_output = FALSE) { is_xml_document <- inherits(x = xml_content, what = "xml_document") if (isFALSE(is_xml_document)) { - cli_abort("The 'xml_content' should be an xml document!") + cli_abort("The {.arg xml_content} should be an xml document!") } # extract nodesets from the XML document and process @@ -2056,7 +2165,7 @@ xml_to_table <- function(xml_content, tidy_output = FALSE) { result_tbl <- result_tbl |> mutate( across( - matches("[t|T]ime$|start$|end$"), + matches("[tT]ime$|start$|end$"), ~ as.POSIXct( x = .x, tryFormats = c( @@ -2351,7 +2460,7 @@ extract_response <- function( #' @examples #' there_is_provider() #' -#' @importFrom httr2 request req_method req_user_agent req_timeout req_retry +#' @importFrom httr2 request req_user_agent req_timeout req_retry #' resp_status #' #' @export @@ -2364,7 +2473,6 @@ there_is_provider <- function( api_scheme, api_domain, api_name, "foo=bar&securityToken=baz" ) |> request() |> - req_method(method = "GET") |> req_user_agent(string = user_agent_string) |> req_timeout(seconds = 10L) |> req_retry(max_tries = 1L) diff --git a/README.Rmd b/README.Rmd index 1ff7778f..8c9170e5 100644 --- a/README.Rmd +++ b/README.Rmd @@ -10,7 +10,7 @@ knitr::opts_chunk$set( comment = "#>", fig.path = "man/figures/README-", out.width = "100%" -) +) ``` # entsoeapi ![hexa sticker](man/figures/logo.png){width="120" height="120"} diff --git a/README.md b/README.md index 3ccac53b..d2744d29 100644 --- a/README.md +++ b/README.md @@ -507,7 +507,7 @@ entsoeapi::load_actual_total( #> ── API call ──────────────────────────────────────────────────────────────────── #> → https://web-api.tp.entsoe.eu/api?documentType=A65&processType=A16&outBiddingZone_Domain=10Y1001A1001A83F&periodStart=201912312300&periodEnd=202001012300&securityToken=<...> #> <- HTTP/2 200 -#> <- date: Mon, 30 Mar 2026 21:56:04 GMT +#> <- date: Tue, 07 Apr 2026 22:23:49 GMT #> <- content-type: text/xml #> <- content-disposition: inline; filename="Actual Total Load_201912312300-202001012300.xml" #> <- x-content-type-options: nosniff @@ -535,7 +535,7 @@ entsoeapi::load_actual_total( #> $ ts_object_aggregation_def "Area", "Area", "Area", "Area", "Area"… #> $ ts_business_type "A04", "A04", "A04", "A04", "A04", "A0… #> $ ts_business_type_def "Consumption", "Consumption", "Consump… -#> $ created_date_time 2026-03-30 21:56:04, 2026-03-30 21:56… +#> $ created_date_time 2026-04-07 22:23:49, 2026-04-07 22:23… #> $ revision_number 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,… #> $ time_period_time_interval_start 2019-12-31 23:00:00, 2019-12-31 23:00… #> $ time_period_time_interval_end 2020-01-01 23:00:00, 2020-01-01 23:00… @@ -565,7 +565,7 @@ entsoeapi::gen_per_prod_type( #> ── API call ──────────────────────────────────────────────────────────────────── #> → https://web-api.tp.entsoe.eu/api?documentType=A75&processType=A16&in_Domain=10Y1001A1001A83F&periodStart=201912312300&periodEnd=202001012300&securityToken=<...> #> <- HTTP/2 200 -#> <- date: Mon, 30 Mar 2026 21:56:06 GMT +#> <- date: Tue, 07 Apr 2026 22:23:49 GMT #> <- content-type: text/xml #> <- content-disposition: inline; filename="Aggregated Generation per Type_201912312300-202001012300.xml" #> <- x-content-type-options: nosniff @@ -594,7 +594,7 @@ entsoeapi::gen_per_prod_type( #> $ ts_business_type_def "Production", "Production", "Productio… #> $ ts_mkt_psr_type "B10", "B10", "B10", "B10", "B10", "B1… #> $ ts_mkt_psr_type_def "Hydro-electric pure pumped storage he… -#> $ created_date_time 2026-03-30 21:56:06, 2026-03-30 21:56… +#> $ created_date_time 2026-04-07 22:23:49, 2026-04-07 22:23… #> $ revision_number 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,… #> $ time_period_time_interval_start 2019-12-31 23:00:00, 2019-12-31 23:00… #> $ time_period_time_interval_end 2020-01-01 23:00:00, 2020-01-01 23:00… diff --git a/man/accounting_point_eic.Rd b/man/accounting_point_eic.Rd index 02e1b4a3..3e674226 100644 --- a/man/accounting_point_eic.Rd +++ b/man/accounting_point_eic.Rd @@ -8,10 +8,10 @@ accounting_point_eic() } \value{ A tibble of accordingly filtered EIC codes, which contains such columns as -\code{EicCode}, \code{EicDisplayName}, \code{EicLongName}, \code{EicParent}, -\code{EicResponsibleParty}, \code{EicStatus}, \code{MarketParticipantPostalCode}, -\code{MarketParticipantIsoCountryCode}, \code{MarketParticipantVatCode}, -\code{EicTypeFunctionList} and \code{type}. +\code{eic_code}, \code{eic_display_name}, \code{eic_long_name}, \code{eic_parent}, +\code{eic_responsible_party}, \code{eic_status}, \code{market_participant_postal_code}, +\code{market_participant_iso_country_code}, \code{market_participant_vat_code}, +\code{eic_type_function_list} and \code{type}. } \description{ This function downloads approved accounting point Z diff --git a/man/all_approved_eic.Rd b/man/all_approved_eic.Rd index caa77d29..68d2f576 100644 --- a/man/all_approved_eic.Rd +++ b/man/all_approved_eic.Rd @@ -8,10 +8,10 @@ all_approved_eic() } \value{ A tibble of accordingly filtered EIC codes, which contains such columns as -\code{EicCode}, \code{EicDisplayName}, \code{EicLongName}, \code{EicParent}, -\code{EicResponsibleParty}, \code{EicStatus}, \code{MarketParticipantPostalCode}, -\code{MarketParticipantIsoCountryCode}, \code{MarketParticipantVatCode}, -\code{EicTypeFunctionList} and \code{type}. +\code{eic_code}, \code{eic_display_name}, \code{eic_long_name}, \code{eic_parent}, +\code{eic_responsible_party}, \code{eic_status}, \code{market_participant_postal_code}, +\code{market_participant_iso_country_code}, \code{market_participant_vat_code}, +\code{eic_type_function_list} and \code{type}. } \description{ This function downloads all approved diff --git a/man/area_eic.Rd b/man/area_eic.Rd index d95001f1..66dc67e6 100644 --- a/man/area_eic.Rd +++ b/man/area_eic.Rd @@ -8,10 +8,10 @@ area_eic() } \value{ A tibble of accordingly filtered EIC codes, which contains such columns as -\code{EicCode}, \code{EicDisplayName}, \code{EicLongName}, \code{EicParent}, -\code{EicResponsibleParty}, \code{EicStatus}, \code{MarketParticipantPostalCode}, -\code{MarketParticipantIsoCountryCode}, \code{MarketParticipantVatCode}, -\code{EicTypeFunctionList} and \code{type}. +\code{eic_code}, \code{eic_display_name}, \code{eic_long_name}, \code{eic_parent}, +\code{eic_responsible_party}, \code{eic_status}, \code{market_participant_postal_code}, +\code{market_participant_iso_country_code}, \code{market_participant_vat_code}, +\code{eic_type_function_list} and \code{type}. } \description{ This function downloads approved area Y diff --git a/man/continuous_offered_transfer_capacities.Rd b/man/continuous_offered_transfer_capacities.Rd index 3bd8c892..3507518e 100644 --- a/man/continuous_offered_transfer_capacities.Rd +++ b/man/continuous_offered_transfer_capacities.Rd @@ -7,8 +7,8 @@ continuous_offered_transfer_capacities( eic_in = NULL, eic_out = NULL, - period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), tz = "CET"), - period_end = lubridate::ymd(Sys.Date(), tz = "CET"), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) diff --git a/man/explicit_offered_transfer_capacities.Rd b/man/explicit_offered_transfer_capacities.Rd index 8b169b69..f13461f1 100644 --- a/man/explicit_offered_transfer_capacities.Rd +++ b/man/explicit_offered_transfer_capacities.Rd @@ -7,8 +7,8 @@ explicit_offered_transfer_capacities( eic_in = NULL, eic_out = NULL, - period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), tz = "CET"), - period_end = lubridate::ymd(Sys.Date(), tz = "CET"), + period_start = ymd(Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), contract_type = "A01", tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") diff --git a/man/gen_storage_mean_filling_rate.Rd b/man/gen_storage_mean_filling_rate.Rd index 91f32127..50e55413 100644 --- a/man/gen_storage_mean_filling_rate.Rd +++ b/man/gen_storage_mean_filling_rate.Rd @@ -40,8 +40,8 @@ week value of the previous year. \dontshow{if (there_is_provider() && nchar(Sys.getenv("ENTSOE_PAT")) > 0L) withAutoprint(\{ # examplesIf} df <- entsoeapi::gen_storage_mean_filling_rate( eic = "10YFR-RTE------C", - period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), - period_end = lubridate::ymd(x = "2021-02-15", tz = "CET"), + period_start = lubridate::ymd(x = "2020-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-01-31", tz = "CET"), tidy_output = TRUE ) diff --git a/man/implicit_offered_transfer_capacities.Rd b/man/implicit_offered_transfer_capacities.Rd index 8f041fbd..8b445eaf 100644 --- a/man/implicit_offered_transfer_capacities.Rd +++ b/man/implicit_offered_transfer_capacities.Rd @@ -7,8 +7,8 @@ implicit_offered_transfer_capacities( eic_in = NULL, eic_out = NULL, - period_start = lubridate::ymd(x = Sys.Date() - lubridate::days(x = 1L), tz = "CET"), - period_end = lubridate::ymd(Sys.Date(), tz = "CET"), + period_start = ymd(x = Sys.Date() - days(x = 1L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), contract_type = "A01", tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") diff --git a/man/location_eic.Rd b/man/location_eic.Rd index d465a52f..a4148569 100644 --- a/man/location_eic.Rd +++ b/man/location_eic.Rd @@ -8,10 +8,10 @@ location_eic() } \value{ A tibble of accordingly filtered EIC codes, which contains such columns as -\code{EicCode}, \code{EicDisplayName}, \code{EicLongName}, \code{EicParent}, -\code{EicResponsibleParty}, \code{EicStatus}, \code{MarketParticipantPostalCode}, -\code{MarketParticipantIsoCountryCode}, \code{MarketParticipantVatCode}, -\code{EicTypeFunctionList} and \code{type}. +\code{eic_code}, \code{eic_display_name}, \code{eic_long_name}, \code{eic_parent}, +\code{eic_responsible_party}, \code{eic_status}, \code{market_participant_postal_code}, +\code{market_participant_iso_country_code}, \code{market_participant_vat_code}, +\code{eic_type_function_list} and \code{type}. } \description{ This function downloads approved location V diff --git a/man/netted_volumes_per_border.Rd b/man/netted_volumes_per_border.Rd index b2def11b..87618875 100644 --- a/man/netted_volumes_per_border.Rd +++ b/man/netted_volumes_per_border.Rd @@ -8,8 +8,8 @@ netted_volumes_per_border( acquiring_eic = NULL, connecting_eic = NULL, process_type = NULL, - period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 7L), tz = "CET"), - period_end = lubridate::ymd(Sys.Date(), tz = "CET"), + period_start = ymd(Sys.Date() - days(x = 7L), tz = "CET"), + period_end = ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) diff --git a/man/outages_cons_units.Rd b/man/outages_cons_units.Rd index d1ab7efd..a51314e9 100644 --- a/man/outages_cons_units.Rd +++ b/man/outages_cons_units.Rd @@ -33,12 +33,10 @@ in POSIXct or YYYY-MM-DD HH:MM:SS format One year range limit applies} \item{period_start_update}{notification submission/update starting date -in POSIXct or YYYY-MM-DD HH:MM:SS format -One year range limit applies} +in POSIXct or YYYY-MM-DD HH:MM:SS format} \item{period_end_update}{notification submission/update ending date -in POSIXct or YYYY-MM-DD HH:MM:SS format -One year range limit applies} +in POSIXct or YYYY-MM-DD HH:MM:SS format} \item{doc_status}{Notification document status. "A05" for active, "A09" for cancelled and "A13" for withdrawn. diff --git a/man/party_eic.Rd b/man/party_eic.Rd index 53706606..3f47bf18 100644 --- a/man/party_eic.Rd +++ b/man/party_eic.Rd @@ -8,10 +8,10 @@ party_eic() } \value{ A tibble of accordingly filtered EIC codes, which contains such columns as -\code{EicCode}, \code{EicDisplayName}, \code{EicLongName}, \code{EicParent}, -\code{EicResponsibleParty}, \code{EicStatus}, \code{MarketParticipantPostalCode}, -\code{MarketParticipantIsoCountryCode}, \code{MarketParticipantVatCode}, -\code{EicTypeFunctionList} and \code{type}. +\code{eic_code}, \code{eic_display_name}, \code{eic_long_name}, \code{eic_parent}, +\code{eic_responsible_party}, \code{eic_status}, \code{market_participant_postal_code}, +\code{market_participant_iso_country_code}, \code{market_participant_vat_code}, +\code{eic_type_function_list} and \code{type}. } \description{ This function downloads approved party X diff --git a/man/resource_object_eic.Rd b/man/resource_object_eic.Rd index 288c717f..24da2e04 100644 --- a/man/resource_object_eic.Rd +++ b/man/resource_object_eic.Rd @@ -8,10 +8,10 @@ resource_object_eic() } \value{ A tibble of accordingly filtered EIC codes, which contains such columns as -\code{EicCode}, \code{EicDisplayName}, \code{EicLongName}, \code{EicParent}, -\code{EicResponsibleParty}, \code{EicStatus}, \code{MarketParticipantPostalCode}, -\code{MarketParticipantIsoCountryCode}, \code{MarketParticipantVatCode}, -\code{EicTypeFunctionList} and \code{type}. +\code{eic_code}, \code{eic_display_name}, \code{eic_long_name}, \code{eic_parent}, +\code{eic_responsible_party}, \code{eic_status}, \code{market_participant_postal_code}, +\code{market_participant_iso_country_code}, \code{market_participant_vat_code}, +\code{eic_type_function_list} and \code{type}. } \description{ This function downloads approved resource object W diff --git a/man/substation_eic.Rd b/man/substation_eic.Rd index ad5e777c..d1d4c3dc 100644 --- a/man/substation_eic.Rd +++ b/man/substation_eic.Rd @@ -8,10 +8,10 @@ substation_eic() } \value{ A tibble of accordingly filtered EIC codes, which contains such columns as -\code{EicCode}, \code{EicDisplayName}, \code{EicLongName}, \code{EicParent}, -\code{EicResponsibleParty}, \code{EicStatus}, \code{MarketParticipantPostalCode}, -\code{MarketParticipantIsoCountryCode}, \code{MarketParticipantVatCode}, -\code{EicTypeFunctionList} and \code{type}. +\code{eic_code}, \code{eic_display_name}, \code{eic_long_name}, \code{eic_parent}, +\code{eic_responsible_party}, \code{eic_status}, \code{market_participant_postal_code}, +\code{market_participant_iso_country_code}, \code{market_participant_vat_code}, +\code{eic_type_function_list} and \code{type}. } \description{ This function downloads all approved substation A diff --git a/man/tie_line_eic.Rd b/man/tie_line_eic.Rd index e887e005..194cf504 100644 --- a/man/tie_line_eic.Rd +++ b/man/tie_line_eic.Rd @@ -8,10 +8,10 @@ tie_line_eic() } \value{ A tibble of accordingly filtered EIC codes, which contains such columns as -\code{EicCode}, \code{EicDisplayName}, \code{EicLongName}, \code{EicParent}, -\code{EicResponsibleParty}, \code{EicStatus}, \code{MarketParticipantPostalCode}, -\code{MarketParticipantIsoCountryCode}, \code{MarketParticipantVatCode}, -\code{EicTypeFunctionList} and \code{type}. +\code{eic_code}, \code{eic_display_name}, \code{eic_long_name}, \code{eic_parent}, +\code{eic_responsible_party}, \code{eic_status}, \code{market_participant_postal_code}, +\code{market_participant_iso_country_code}, \code{market_participant_vat_code}, +\code{eic_type_function_list} and \code{type}. } \description{ This function downloads approved tie line T diff --git a/tests/testthat/fixtures/eiccodes.csv b/tests/testthat/fixtures/eiccodes.csv new file mode 100644 index 00000000..809c36a9 --- /dev/null +++ b/tests/testthat/fixtures/eiccodes.csv @@ -0,0 +1,3 @@ +"EicCode";"EicDisplayName";"EicLongName";"EicParent";"EicResponsibleParty";"EicStatus";"MarketParticipantPostalCode";"MarketParticipantIsoCountryCode";"MarketParticipantVatCode";"EicTypeFunctionList";"Type" +"10Y000-0000-0001";"AreaOne";"Area One Long";"";"";"";"";"";"";"";"X" +"10Y000-0000-0002";"AreaTwo";"Area Two Long";"";"";"";"";"";"";"";"X" diff --git a/tests/testthat/fixtures/entsoe_gen_min.xml b/tests/testthat/fixtures/entsoe_gen_min.xml new file mode 100644 index 00000000..80d94ada --- /dev/null +++ b/tests/testthat/fixtures/entsoe_gen_min.xml @@ -0,0 +1,41 @@ + + + FAKE_DOC_ID + 1 + A73 + A16 + 10X1001A1001A450 + A32 + 10X1001A1001A450 + A33 + 2024-01-01T00:00:00Z + + 2024-01-01T23:00Z + 2024-01-02T23:00Z + + + 1 + A01 + 10YDE-VE-------2 + MAW + A01 + + B16 + + + + 2024-01-01T23:00Z + 2024-01-02T23:00Z + + PT60M + + 1 + 100 + + + 2 + 110 + + + + diff --git a/tests/testthat/fixtures/merge_date_and_time.xml b/tests/testthat/fixtures/merge_date_and_time.xml new file mode 100644 index 00000000..7b5ff7a2 --- /dev/null +++ b/tests/testthat/fixtures/merge_date_and_time.xml @@ -0,0 +1,25 @@ + + +FAKE1 +1 +A77 +A16 +2024-01-01T00:00:00Z + + 2024-01-01T23:00Z + 2024-01-02T23:00Z + + + 1 + A53 + + 2024-01-01 + + + + 2024-01-02 + + + B02 + + diff --git a/tests/testthat/fixtures/no_data.xml b/tests/testthat/fixtures/no_data.xml new file mode 100644 index 00000000..64ce102a --- /dev/null +++ b/tests/testthat/fixtures/no_data.xml @@ -0,0 +1 @@ +FAKE999Internal error: no data found diff --git a/tests/testthat/fixtures/offset_response.xml b/tests/testthat/fixtures/offset_response.xml new file mode 100644 index 00000000..f4088b36 --- /dev/null +++ b/tests/testthat/fixtures/offset_response.xml @@ -0,0 +1 @@ +FAKE999The number of instances (400) exceeds the allowed maximum (200) diff --git a/tests/testthat/fixtures/test_df_list.rds b/tests/testthat/fixtures/test_df_list.rds index 2c7c67507282cc95feb943650454fd1cb87bb14b..0842983d3aed88cb03bd17bfc5b867f04a83262f 100644 GIT binary patch literal 2593 zcmV++3f}b}iwFP!000001MOQ|Z`{Tep1tXAXDwTfEMKCw4&Yu^mE>FeQfnpImXX>P zEIEn&LQve%mI;?!le2PV6h(hRp8~Z1BtM}*`_z~Etw3LkKt+S1MICR!<@sjGv*fNE ztewOS0pW1YIdg7v&de-l^wES6q9BT;f+&=P5Tf*8`)1`mA;fVZ#Iz8F5Eg|HWg$dP z6vcQ5f5{R19PyMRo(NIQ#}FmUF@u1(3WOX{JC0G?rB*@hIP^MEGnKip>zfV9Q+LWp*|-R26xRPK00W|?@|!Hb2Lnh@dzMW96erXXx{d+G9>Z(1X1 zV_|i1>FawHg`=S@)n_+<{VO5FtAc!x)l<)vEcXfzw$~!QT$@OFB8_g|+q(UcrI3G} zriun$eBNQ~$~kIzjizZS!**35A2Vuk#|$Llj&$%53?+r3D6CxQ*ek9dBw>taYUO-{ zSh+;-X9S0YXJL5xy34m&nSBxA3lLeNo<~$*_%iUEma;t;5$qt%z;g}Dt4YG1RDq%F zh798>{XNq$0%iIblVd6{nx5?{qv-`U6GjBzwq#1RqRLC#TZ=k72R2yWm#e@|))x<# zwZ-;u6SdTi;7Ge~8kPs9VKFnU)?ZZ`JF`onb3b-Q{WT6xH2Bsv(=;{;R5`FIl#X z!lh&#g)_9(^7o{n_M0+>?8&D76ZDB5s&sX&W))kP@VI5V%2xYq{tjdI>B@=S&a-m- zcj5ERfakUz`phhKnNFUvc$=a}EHi_4j1 ze(3RJc?LMk@{Y$Ba?UWnF&^hw9i3%ItyK?4Dry5r-c60#9e&y8f@IpN3yV@~=mma-s46jr!|0 zr=tz{pU5sv{|B}INpipkeOwRdynVp%FQ^~%0do7Y=vjWiPHrEM5850;5A5T1WW=$% z-=%TG`i=P>`!vwOkMRecuLqcy%d8*j3F`>tmYE*N!@jZ1?1Mb)tMxvd+I(Ni=XK2A z&~t+O$?S%Fz3vcQ`@!&tkB$R_uzQU8kNpGe!G4qPOXrxqe4mDWivArzcZ8f!gf%mY%o%Ky@?- zJ|p;Ns%K9BETi9N8T4lvayjJuX#bV!JHk@Z)dF+=nuVU^Z0Ok0bvidvHoNI zSrNqdob7vnho8?GANCOp!yY~PCM!ZY?{u(&!t;ezrfK%g!|C0 zY1GuFR6T4FF3vW()s&VUp5dpOGx)>!$FXnBlP`U4Hpb@sa z<44s66)ZG;uhz1{;|$}ztlNQ-zO3Dsf!FdaxzOCYACvk0)v(8AzaGT-?pnxc27y$A z#hzUcnX4Jh#B~0~LeqO9{jL2#$p(l)=fKBk27dhH=lsou&BOARZ;_b{|E@1BY41tj zxMTXCNVRGD%C_vL>8gcB2Xo(Z%-RRw~=TU%K?LvZ$Y{TdDY^ie^rLtblxMUF4 zvh5l*uVLD5{JO!k3JkBMQYfdx`NOW&Y`1QN*Y{Fb&P7rOaJ@q+2C&Uqo~wM%F-%{Y z8TR;kN$p&R2$w>-Of!U98~HY_G{aDx$e0miR?V}*3ni)*7<;DE!enn?9YF{s3P;|^Bx z3RCskHM%O5tN!Kh7o$%XL%$k@&jlSlE4T5J=2c&q>w7CT^&-^JFQtyM!1PY&-+FrL zf>6$wWoN_kwjQ@^Kb)$2>8HX`@mx2o?^K2}v>ECrJDfWvlOtq=+ z!rGt3)s_rnnh@+mP%^I$ z>Z7~!Kb>EFRMj1X7^ft7J?+TA+{27dBxBOH5_uA~Yj)6d%>5|#G*yOp$8+m(s3{UC+Q4m`v1TCVc<sGK!)cg zsDhe^;LjOxz=-FJc&1b#*M%rLH9HK2D=)}Vvs1IGyVA>>otiW!tG2NhcLTewNzO#z zKU?(dx{hR>QcC51rIc#5S}j%xrc&D@G0R3{2Mq^}s#5BeM4%|+rXg%&d-=WfZ(ApA zWB$(4@;BF1`O}dtl^6GZ`3t4gNkN`u^W66|yG))$VK zwT0Gj6Sdfi;b`l~G%O8F!$M|St({aFz063XsU5d!nb4{SZWRe3sGjUv5JGk?%?d}~ ze40rUDW`HYSE(g;gfeK@(P>e1a)UyV3R}mCF*50xwE*^fW$9W*ljLq}-&k5dq7&Ci zzVhPU^DpDNNWs@Ef+LEl?K*V*x)ke3!Qtv^Pg`EjjPO6r^qHGz1 zOX)g_R%oXg>}$&$G;|lTC!3C5pwIVEwU^XtRI`jMJ_lMOP!Jn5{&Vo+(vx3KX@SVHX{w46Nz_$d>i5~F74&c#edZHh8i#*tq zK*)hV0>Pii75toxgCCH?__JgW_+}^`i5+Yw`7ulOUlMphxV#sUDywi6i6-{R+h~$q&(gh3sbi@RR2Y z^vlwJTOjB>&#dPH%@gc`e)QoV=LOFz{D!@fcgeanE%b4L6C!_H_@@P)5qVPt#{`1^ zl#B;`oaC3Nz9AQOoR+u%LJs7@o=KuZ{uIeWpZx;9ByviE2Oa#71HD;#aw3Pv!H;q3 zgAaa95}xga{854!m#6tC%6LWb9})Z*@sE>#7!Upe~ep3ESWcbH=Cy0)`fj=XZC!80M&w0i3k<~v< z@a~2YsvubnYJ#{*{b_K0vlFi=O2N>}2~mKIk)q9@xirWW=#^-j#X7{*Cn> z=QPm4kNF3k_XDiUB^rl%!af4ICDH?VI5(EaKFGtlIyr|+pU^Cq857sy^dr{SEE{2w8BoDcbY&U8MvBHn={-TIx>(IEIj;2)))nf`gk zxX&}_FEZpZWPbGjEcKpc=W+eXvirFHW!d`|=?{toNEYrVuecu082IV3sg^E%9W zc^vkgm$W_)TIaL&qeGH=NOE|8;eOVBf$`9bKF5dc1%y4)$NrD~XH^N`OFH)e4?kZL zAI=e~zr5sJjB}@)4}0|F(({y@BNfTVII_3LF3@S8P2`PG+_AqxZ$86c_{ILbqVa{a zA3gdh4oc;t4|bo)cfvQ}FZYK0<=>3I)UD`fP4DYk&t-e4jUVCyd~#n0q3ifHKfulU zz8mbhp6l53i8>LxYdgjd;t#idZ*Qizbi=MK{#bi^=4ZH?h;bje)dV%Yp-m54jO%6_ z+iGaXjqdRKnlt#r_$OW8n5SO*-fW!K{Pew9cVtH@Xxu^L?tfq1{~}8&3#X7?jlg$w z7%tW~AFko@c-yV(EgiTz-0s|dEHpiP-*#*Ej$3ohffX@X8#-`(Txfj1vS`A^M&MVQ zPIR4NZR$NYG&<1LO&$8pz|o71t<5f(-@6ly*f?s0aK3Xl;DTnvuHUb^>UX^7ZgP1gX|CK%nm77fVlH=@oiRO^nBOF0>M_kqr+Ffb zsiGODqUoOAGbXfb$>Q#8Frl^63|)`d3tjEmc=|1SFVMQKJ=4t?T?Y2er$}M_(;jqm zAK6uc33V8Gl{<3II(c<%<+zi(oN;;ogRr^tiFS-7p=orA1*pKUrEX{Oeqp!fKeMWC zpxXf$ir@S+ptOABN#)V~$Cb5*l@BZB@;30-uRkd-CBK_neeugHKmEVFZ@IkXkJhf= z|6skma(BJFeDhW}{^m~}Rz6&LP+l%y`=A^D{)0ykR#qOA%jLC7#v_BMmR--P`gPm& zx}O`&n9%Z@rVr&}w0^kNs_X4p(eu4NELUQw1GwH66$9Aj9p5v7U$g8$+Zpx*$(GuF z4iRmI@|b1_wKn=)+-ZiPI+Zb_$gHaGL=Q?#Gqm>YS`&-ixvt&Dv5nsIgM+Rlqct!l zO!dAl?EmI)HcFLv`L*}<0=;JsZ6zH!^3~M!PV+qqNTRN@y$!{nB8|oytn?G6%B@@S zRBEL1r@vl{KV1y{X%s#ewDqh$#J@Br{b26MSE+p;LJj><>KFy4cR~No)BA1+rHoZ} zJ}PhLY10j&rMj1XA(|E6^P>9h%Wz2!Lq`d@EIdaFn(9Tp>-b)10y~<>=nU$6uJNPI zpkb=JDG^_{KwEvzoVm{0kXk}}sHyd&|LL;-vR6uDEq<$deEXw - - - Empire Burlesque - Bob Dylan - USA - Columbia - 10.90 - 1985 - - - Hide your heart - Bonnie Tylor - UK - CBS Records - 9.90 - 1988 - - - Greatest Hits - Dolly Parton - USA - RCA - 9.90 - 1982 - - - Still got the blues - Gary More - UK - Virgin redords - 10.20 - 1990 - - - Eros - Eros Ramazzotti - EU - BMG - 9.90 - 1997 - - - One night only - Bee Gees - UK - Polydor - 10.90 - 1998 - - - Sylvias Mother - Dr.Hook - UK - CBS - 8.10 - 1973 - - - Maggie May - Rod Stewart - UK - Pickwick - 8.50 - 1990 - - - Romanza - Andrea Bocelli - EU - Polydor - 10.80 - 1996 - - - When a man loves a woman - Percy Sledge - USA - Atlantic - 8.70 - 1987 - - - Black angel - Savage Rose - EU - Mega - 10.90 - 1995 - - - 1999 Grammy Nominees - Many - USA - Grammy - 10.20 - 1999 - - - For the good times - Kenny Rogers - UK - Mucik Master - 8.70 - 1995 - - - Big Willie style - Will Smith - USA - Columbia - 9.90 - 1997 - - - Tupelo Honey - Van Morrison - UK - Polydor - 8.20 - 1971 - - - Soulsville - Jorn Hoel - Norway - WEA - 7.90 - 1996 - - - The very best of - Cat Stevens - UK - Island - 8.90 - 1990 - - - Stop - Sam Brown - UK - A and M - 8.90 - 1988 - - - Bridge of Spies - T`Pau - UK - Siren - 7.90 - 1987 - - - Private Dancer - Tina Turner - UK - Capitol - 8.90 - 1983 - - - Midt om natten - Kim Larsen - EU - Medley - 7.80 - 1983 - - - Pavarotti Gala Concert - Luciano Pavarotti - UK - DECCA - 9.90 - 1991 - - - The dock of the bay - Otis Redding - USA - Atlantic - 7.90 - 1987 - - - Picture book - Simply Red - EU - Elektra - 7.20 - 1985 - - - Red - The Communards - UK - London - 7.80 - 1987 - - - Unchain my heart - Joe Cocker - USA - EMI - 8.20 - 1987 - - diff --git a/tests/testthat/fixtures/tests/testthat/fixtures/mtcars.csv b/tests/testthat/fixtures/tests/testthat/fixtures/mtcars.csv deleted file mode 100644 index a8e39514..00000000 --- a/tests/testthat/fixtures/tests/testthat/fixtures/mtcars.csv +++ /dev/null @@ -1,33 +0,0 @@ -"mpg";"cyl";"disp";"hp";"drat";"wt";"qsec";"vs";"am";"gear";"carb";"make" -21;6;160;110;3.9;2.62;16.46;0;1;4;4;"Mazda RX4" -21;6;160;110;3.9;2.875;17.02;0;1;4;4;"Mazda RX4 Wag" -22.8;4;108;93;3.85;2.32;18.61;1;1;4;1;"Datsun 710" -21.4;6;258;110;3.08;3.215;19.44;1;0;3;1;"Hornet 4 Drive" -18.7;8;360;175;3.15;3.44;17.02;0;0;3;2;"Hornet Sportabout" -18.1;6;225;105;2.76;3.46;20.22;1;0;3;1;"Valiant" -14.3;8;360;245;3.21;3.57;15.84;0;0;3;4;"Duster 360" -24.4;4;146.7;62;3.69;3.19;20;1;0;4;2;"Merc 240D" -22.8;4;140.8;95;3.92;3.15;22.9;1;0;4;2;"Merc 230" -19.2;6;167.6;123;3.92;3.44;18.3;1;0;4;4;"Merc 280" -17.8;6;167.6;123;3.92;3.44;18.9;1;0;4;4;"Merc 280C" -16.4;8;275.8;180;3.07;4.07;17.4;0;0;3;3;"Merc 450SE" -17.3;8;275.8;180;3.07;3.73;17.6;0;0;3;3;"Merc 450SL" -15.2;8;275.8;180;3.07;3.78;18;0;0;3;3;"Merc 450SLC" -10.4;8;472;205;2.93;5.25;17.98;0;0;3;4;"Cadillac Fleetwood" -10.4;8;460;215;3;5.424;17.82;0;0;3;4;"Lincoln Continental" -14.7;8;440;230;3.23;5.345;17.42;0;0;3;4;"Chrysler Imperial" -32.4;4;78.7;66;4.08;2.2;19.47;1;1;4;1;"Fiat 128" -30.4;4;75.7;52;4.93;1.615;18.52;1;1;4;2;"Honda Civic" -33.9;4;71.1;65;4.22;1.835;19.9;1;1;4;1;"Toyota Corolla" -21.5;4;120.1;97;3.7;2.465;20.01;1;0;3;1;"Toyota Corona" -15.5;8;318;150;2.76;3.52;16.87;0;0;3;2;"Dodge Challenger" -15.2;8;304;150;3.15;3.435;17.3;0;0;3;2;"AMC Javelin" -13.3;8;350;245;3.73;3.84;15.41;0;0;3;4;"Camaro Z28" -19.2;8;400;175;3.08;3.845;17.05;0;0;3;2;"Pontiac Firebird" -27.3;4;79;66;4.08;1.935;18.9;1;1;4;1;"Fiat X1-9" -26;4;120.3;91;4.43;2.14;16.7;0;1;5;2;"Porsche 914-2" -30.4;4;95.1;113;3.77;1.513;16.9;1;1;5;2;"Lotus Europa" -15.8;8;351;264;4.22;3.17;14.5;0;1;5;4;"Ford Pantera L" -19.7;6;145;175;3.62;2.77;15.5;0;1;5;6;"Ferrari Dino" -15;8;301;335;3.54;3.57;14.6;0;1;5;8;"Maserati Bora" -21.4;4;121;109;4.11;2.78;18.6;1;1;4;2;"Volvo 142E" diff --git a/tests/testthat/test-en_balancing.R b/tests/testthat/test-en_balancing.R index 5ca4dadc..2908807a 100644 --- a/tests/testthat/test-en_balancing.R +++ b/tests/testthat/test-en_balancing.R @@ -5,84 +5,43 @@ testthat::test_that( object = elastic_demands( eic = NULL, process_type = "A47", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "One control area EIC should be provided!" + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = elastic_demands( eic = c("10YHU-MAVIR----U", "10Y1001A1001A83F"), process_type = "A47", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), - tidy_output = TRUE, - security_token = "dummy_token" - ), - info = "This wrapper only supports one control area EIC per request!" - ) - testthat::expect_error( - object = elastic_demands( - eic = "10YHU-MAVIR----U", - process_type = "A47", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2021-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "One year range limit should be applied!" + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = elastic_demands( eic = "10YHU-MAVIR----U", process_type = "A47", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, security_token = "" ), - info = "Valid security token should be provided!" + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = elastic_demands( eic = "10YHU-MAVIR----U", process_type = NULL, - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = paste0( "Assertion on 'process_type' failed: ", @@ -93,16 +52,10 @@ testthat::test_that( object = elastic_demands( eic = "10YHU-MAVIR----U", process_type = "INVALID", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = paste0( "Assertion on 'process_type' failed: ", @@ -127,14 +80,8 @@ testthat::test_that( result_full <- tryCatch( elastic_demands( eic = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2024-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-12-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-12-01", tz = "CET"), process_type = "A47", tidy_output = TRUE ), @@ -147,21 +94,17 @@ testthat::test_that( expected = c( "bid_ts_mrid", "bid_ts_auction_mrid", - "bid_ts_flow_direction" + "bid_ts_flow_direction", + "bid_ts_point_quantity", + "bid_ts_point_energy_price_amount" ) ) tryCatch( elastic_demands( eic = "10YCZ-CEPS-----N", process_type = "A47", - period_start = lubridate::ymd( - x = "2024-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE ), error = function(e) { @@ -178,66 +121,42 @@ testthat::test_that( testthat::expect_error( object = netted_volumes( eic = NULL, - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-02-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-02-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "One control area EIC should be provided!" + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = netted_volumes( eic = c("10YHU-MAVIR----U", "10Y1001A1001A83F"), - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-02-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-02-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "This wrapper only supports one control area EIC per request!" + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = netted_volumes( eic = "10YHU-MAVIR----U", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2021-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2021-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "One day range limit should be applied!" + regexp = "1 day range limit should be applied" ) testthat::expect_error( object = netted_volumes( eic = "10YHU-MAVIR----U", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-02-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-02-02", tz = "CET"), tidy_output = TRUE, security_token = "" ), - info = "Valid security token should be provided!" + regexp = "should comply with the UUID v4 format" ) } ) @@ -257,28 +176,16 @@ testthat::test_that( testthat::expect_no_error( object = netted_volumes( eic = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2024-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE ) ) testthat::expect_contains( object = netted_volumes( eic = "10YDE-VE-------2", - period_start = lubridate::ymd( - x = "2024-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE ) |> names(), @@ -298,101 +205,67 @@ testthat::test_that( testthat::expect_error( object = exchanged_volumes( eic = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2024-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Must be a subset of \\{'A51','A60','A61'\\}" ) testthat::expect_error( object = exchanged_volumes( eic = "10YCZ-CEPS-----N", process_type = "A264537254", - period_start = lubridate::ymd( - x = "2024-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Must be element of set \\{'A51','A60','A61'\\}" ) testthat::expect_error( object = exchanged_volumes( eic = NULL, process_type = "A51", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-02-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-02-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "One control area EIC should be provided!" + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = exchanged_volumes( eic = c("10YHU-MAVIR----U", "10Y1001A1001A83F"), process_type = "A61", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-02-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-02-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "This wrapper only supports one control area EIC per request!" + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = exchanged_volumes( eic = "10YHU-MAVIR----U", process_type = "A60", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2021-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2021-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "One day range limit should be applied!" + regexp = "1 day range limit should be applied" ) testthat::expect_error( object = exchanged_volumes( eic = "10YHU-MAVIR----U", process_type = "A60", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-02-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-02-02", tz = "CET"), tidy_output = TRUE, security_token = "" ), - info = "Valid security token should be provided!" + regexp = "should comply with the UUID v4 format" ) } ) @@ -413,14 +286,8 @@ testthat::test_that( object = exchanged_volumes( eic = "10YCZ-CEPS-----N", process_type = "A51", - period_start = lubridate::ymd( - x = "2024-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE ) ) @@ -428,14 +295,8 @@ testthat::test_that( object = exchanged_volumes( eic = "10YCZ-CEPS-----N", process_type = "A60", - period_start = lubridate::ymd( - x = "2024-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE ) ) @@ -443,14 +304,8 @@ testthat::test_that( object = exchanged_volumes( eic = "10YCZ-CEPS-----N", process_type = "A60", - period_start = lubridate::ymd( - x = "2024-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE ) |> names(), @@ -472,16 +327,14 @@ testthat::test_that( eic_in = "10YDE-RWENET---I", eic_out = "10YBE----------2", process_type = "A264537254", - period_start = lubridate::ymd( - x = "2024-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token + ), + regexp = paste( + "Assertion on 'process_type' failed:", + "Must be element of set \\{'A47','A51','A63'\\}" ) ) testthat::expect_error( @@ -489,94 +342,48 @@ testthat::test_that( eic_in = c("10YDE-RWENET---I", "10Y1001A1001A83F"), eic_out = "10YBE----------2", process_type = "A51", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-02-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-02-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "This wrapper only supports one in and one out EIC per request." + regexp = "Assertion on 'eic_in' failed: Must have length 1" ) testthat::expect_error( object = balancing_border_cap_limit( eic_in = "10YDE-RWENET---I", eic_out = c("10YBE----------2", "10Y1001A1001A83F"), process_type = "A51", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-02-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-02-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "This wrapper only supports one in and one out EIC per request." + regexp = "Assertion on 'eic_out' failed: Must have length 1" ) testthat::expect_error( object = balancing_border_cap_limit( eic_in = "10YDE-RWENET---I", eic_out = "10YBE----------2", - eic_interconnector = c("AAA", "BBB"), process_type = "A51", - period_start = lubridate::ymd( - x = "2024-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = "ABC" ), - info = paste( - "None or one Transmission Asset (eic_interconnector)", - "should be provided." - ) + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = balancing_border_cap_limit( eic_in = "10YDE-RWENET---I", eic_out = "10YBE----------2", process_type = "A51", - period_start = lubridate::ymd( - x = "2024-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, security_token = "" ), - info = "Valid security token should be provided!" - ) - testthat::expect_error( - object = balancing_border_cap_limit( - eic_in = "10YDE-RWENET---I", - eic_out = "10YBE----------2", - process_type = "A51", - period_start = lubridate::ymd( - x = "2024-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2025-12-02", - tz = "CET" - ), - tidy_output = TRUE, - security_token = "dummy_token" - ), - info = "One year range limit should be applied!" + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = balancing_border_cap_limit( @@ -586,7 +393,7 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = paste0( "Assertion on 'eic_in' failed: ", @@ -601,7 +408,7 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = paste0( "Assertion on 'eic_out' failed: ", @@ -629,14 +436,8 @@ testthat::test_that( eic_in = "10YDE-RWENET---I", eic_out = "10YBE----------2", process_type = "A51", - period_start = lubridate::ymd( - x = "2024-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE ) ) @@ -646,14 +447,8 @@ testthat::test_that( eic_in = "10YDE-RWENET---I", eic_out = "10YBE----------2", process_type = "A47", - period_start = lubridate::ymd( - x = "2024-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE ) ) @@ -662,14 +457,8 @@ testthat::test_that( eic_in = "10YDE-RWENET---I", eic_out = "10YBE----------2", process_type = "A51", - period_start = lubridate::ymd( - x = "2024-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE ) ) @@ -678,14 +467,8 @@ testthat::test_that( eic_in = "10YDE-RWENET---I", eic_out = "10YBE----------2", process_type = "A51", - period_start = lubridate::ymd( - x = "2024-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE ) |> names(), @@ -710,7 +493,7 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = paste0( "Assertion on 'acquiring_eic' failed: ", @@ -725,7 +508,7 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Assertion on 'acquiring_eic' failed: Must have length 1" ) @@ -737,9 +520,12 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "The 'process_type' should be 'A51', 'A60' or 'A61'." + regexp = paste( + "Assertion on 'process_type' failed:", + "Must be element of set \\{'A51','A60','A61'\\}" + ) ) testthat::expect_error( object = exchanged_volumes_per_border( @@ -749,9 +535,9 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-05", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - regexp = "One day range limit should be applied" + regexp = "1 day range limit should be applied" ) testthat::expect_error( object = exchanged_volumes_per_border( @@ -763,7 +549,7 @@ testthat::test_that( tidy_output = TRUE, security_token = "" ), - info = "Valid security token should be provided." + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = exchanged_volumes_per_border( @@ -773,7 +559,7 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = paste( "Assertion on 'connecting_eic' failed:", @@ -788,7 +574,7 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Assertion on 'connecting_eic' failed: Must have length 1" ) @@ -831,7 +617,7 @@ testthat::test_that( period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = paste0( "Assertion on 'eic_in' failed: ", @@ -845,7 +631,7 @@ testthat::test_that( period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = paste0( "Assertion on 'eic_out' failed: ", @@ -859,21 +645,10 @@ testthat::test_that( period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Assertion on 'eic_in' failed: Must have length 1" ) - testthat::expect_error( - object = hvdc_link_constrains( - eic_in = "10YAT-APG------L", - eic_out = "10YDE-RWENET---I", - period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2023-05-01", tz = "CET"), - tidy_output = TRUE, - security_token = "dummy_token" - ), - regexp = "One year range limit should be applied" - ) testthat::expect_error( object = hvdc_link_constrains( eic_in = "10YAT-APG------L", @@ -883,11 +658,7 @@ testthat::test_that( tidy_output = TRUE, security_token = "" ), - regexp = paste( - "Assertion on 'security_token' failed:", - "All elements must have at least 1 characters,", - "but element 1 has 0 characters" - ) + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = hvdc_link_constrains( @@ -897,7 +668,7 @@ testthat::test_that( period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Assertion on 'eic_ic' failed: Must have length 1." ) @@ -909,7 +680,7 @@ testthat::test_that( period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = paste( "Assertion on 'process_type' failed:", @@ -953,7 +724,7 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) @@ -963,7 +734,7 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Assertion on 'eic' failed: Must have length 1" ) @@ -974,7 +745,7 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = paste( "Assertion on 'business_type' failed: Must be element of set", @@ -989,21 +760,7 @@ testthat::test_that( tidy_output = TRUE, security_token = "" ), - regexp = paste( - "Assertion on 'security_token' failed:", - "All elements must have at least 1 characters,", - "but element 1 has 0 characters" - ) - ) - testthat::expect_error( - object = changes_to_bid_availability( - eic = "10YCZ-CEPS-----N", - period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2025-05-01", tz = "CET"), - tidy_output = TRUE, - security_token = "dummy_token" - ), - regexp = "One year range limit should be applied" + regexp = "should comply with the UUID v4 format" ) } ) @@ -1053,9 +810,9 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "One control area EIC should be provided." + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = current_balancing_state( @@ -1063,9 +820,9 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "This wrapper only supports one control area EIC per request." + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = current_balancing_state( @@ -1073,9 +830,9 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-06-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "100 day range limit should be applied!" + regexp = "100 days range limit should be applied" ) testthat::expect_error( object = current_balancing_state( @@ -1085,7 +842,7 @@ testthat::test_that( tidy_output = TRUE, security_token = "" ), - info = "Valid security token should be provided." + regexp = "should comply with the UUID v4 format" ) } ) @@ -1123,9 +880,9 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "One connecting domain EIC should be provided." + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = balancing_energy_bids( @@ -1133,9 +890,9 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "This wrapper only supports one connecting domain EIC per request." + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = balancing_energy_bids( @@ -1145,7 +902,7 @@ testthat::test_that( tidy_output = TRUE, security_token = "" ), - info = "Valid security token should be provided." + regexp = "should comply with the UUID v4 format" ) } ) @@ -1184,9 +941,9 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "One control area EIC should be provided." + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = aggregated_balancing_energy_bids( @@ -1195,9 +952,9 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "This wrapper only supports one control area EIC per request." + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = aggregated_balancing_energy_bids( @@ -1206,20 +963,12 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ), - info = "The 'process_type' should be 'A51', 'A46', 'A47', 'A60' or 'A61'." - ) - testthat::expect_error( - object = aggregated_balancing_energy_bids( - eic = "10YCZ-CEPS-----N", - process_type = "A51", - period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2025-05-01", tz = "CET"), - tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "One year range limit should be applied!" + regexp = paste( + "Assertion on 'process_type' failed: Must be element of set", + "\\{'A51','A46','A47','A60','A61','A67','A68'\\}" + ) ) testthat::expect_error( object = aggregated_balancing_energy_bids( @@ -1230,7 +979,7 @@ testthat::test_that( tidy_output = TRUE, security_token = "" ), - info = "Valid security token should be provided." + regexp = "should comply with the UUID v4 format" ) } ) @@ -1270,9 +1019,9 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "One control area EIC should be provided." + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = procured_balancing_capacity( @@ -1281,9 +1030,9 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "This wrapper only supports one control area EIC per request." + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = procured_balancing_capacity( @@ -1292,9 +1041,12 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "The 'process_type' should be 'A51', 'A52' or 'A47'." + regexp = paste( + "Assertion on 'process_type' failed:", + "Must be element of set \\{'A51','A52','A47'\\}" + ) ) testthat::expect_error( object = procured_balancing_capacity( @@ -1304,9 +1056,12 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "None or one 'market_agreement_type' should be provided." + regexp = paste( + "Assertion on 'market_agreement_type' failed: Must be element of set", + "\\{'A01','A02','A03','A04','A05','A06','A07','A13'\\}" + ) ) testthat::expect_error( object = procured_balancing_capacity( @@ -1317,7 +1072,7 @@ testthat::test_that( tidy_output = TRUE, security_token = "" ), - info = "Valid security token should be provided." + regexp = "should comply with the UUID v4 format" ) } ) @@ -1367,9 +1122,12 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "One acquiring domain EIC should be provided." + regexp = paste( + "Assertion on 'eic_acquiring' failed:", + "Must be of type 'string', not 'NULL'" + ) ) testthat::expect_error( object = allocation_of_cross_zonal_balancing_cap( @@ -1378,9 +1136,12 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "One connecting domain EIC should be provided." + regexp = paste( + "Assertion on 'eic_connecting' failed:", + "Must be of type 'string', not 'NULL'" + ) ) testthat::expect_error( object = allocation_of_cross_zonal_balancing_cap( @@ -1389,12 +1150,9 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = paste( - "This wrapper only supports one acquiring and", - "one connecting EIC per request." - ) + regexp = "Assertion on 'eic_acquiring' failed: Must have length 1" ) testthat::expect_error( object = allocation_of_cross_zonal_balancing_cap( @@ -1404,9 +1162,12 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "None or one 'market_agreement_type' should be provided." + regexp = paste( + "Assertion on 'market_agreement_type' failed:", + "Must be element of set \\{'A01','A02','A06'\\}" + ) ) testthat::expect_error( object = allocation_of_cross_zonal_balancing_cap( @@ -1417,7 +1178,7 @@ testthat::test_that( tidy_output = TRUE, security_token = "" ), - info = "Valid security token should be provided." + regexp = "should comply with the UUID v4 format" ) } ) @@ -1467,9 +1228,9 @@ testthat::test_that( period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "One control area EIC should be provided." + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = contracted_reserves( @@ -1478,9 +1239,9 @@ testthat::test_that( period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "This wrapper only supports one control area EIC per request." + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = contracted_reserves( @@ -1489,9 +1250,12 @@ testthat::test_that( period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "A 'market_agreement_type' value should be provided." + regexp = paste( + "Assertion on 'market_agreement_type' failed: Must be a subset of", + "\\{'A01','A02','A03','A04','A06','A13'\\}" + ) ) testthat::expect_error( object = contracted_reserves( @@ -1500,9 +1264,12 @@ testthat::test_that( period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "Only one 'market_agreement_type' value should be provided." + regexp = paste( + "Assertion on 'market_agreement_type' failed: Must be element of set", + "\\{'A01','A02','A03','A04','A06','A13'\\}" + ) ) testthat::expect_error( object = contracted_reserves( @@ -1513,7 +1280,7 @@ testthat::test_that( tidy_output = TRUE, security_token = "" ), - info = "Valid security token should be provided." + regexp = "should comply with the UUID v4 format" ) } ) @@ -1572,9 +1339,9 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "One control area EIC should be provided." + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = activated_balancing_prices( @@ -1582,19 +1349,9 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "This wrapper only supports one control area EIC per request." - ) - testthat::expect_error( - object = activated_balancing_prices( - eic = "10YCZ-CEPS-----N", - period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2025-05-01", tz = "CET"), - tidy_output = TRUE, - security_token = "dummy_token" - ), - info = "One year range limit should be applied!" + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = activated_balancing_prices( @@ -1604,7 +1361,7 @@ testthat::test_that( tidy_output = TRUE, security_token = "" ), - info = "Valid security token should be provided." + regexp = "should comply with the UUID v4 format" ) } ) @@ -1658,7 +1415,7 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -1675,9 +1432,9 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "One control area EIC should be provided." + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = imbalance_prices( @@ -1685,19 +1442,9 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ), - info = "This wrapper only supports one control area EIC per request." - ) - testthat::expect_error( - object = imbalance_prices( - eic = "10YCZ-CEPS-----N", - period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2025-05-01", tz = "CET"), - tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "One year range limit should be applied!" + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = imbalance_prices( @@ -1707,7 +1454,7 @@ testthat::test_that( tidy_output = TRUE, security_token = "" ), - info = "Valid security token should be provided." + regexp = "should comply with the UUID v4 format" ) } ) @@ -1745,9 +1492,9 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "One control area EIC should be provided." + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = imbalance_volumes( @@ -1755,19 +1502,9 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ), - info = "This wrapper only supports one control area EIC per request." - ) - testthat::expect_error( - object = imbalance_volumes( - eic = "10YCZ-CEPS-----N", - period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2025-05-01", tz = "CET"), - tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "One year range limit should be applied!" + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = imbalance_volumes( @@ -1777,7 +1514,7 @@ testthat::test_that( tidy_output = TRUE, security_token = "" ), - info = "Valid security token should be provided." + regexp = "should comply with the UUID v4 format" ) } ) @@ -1815,9 +1552,9 @@ testthat::test_that( period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "One control area EIC should be provided." + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = financial_expenses_and_income( @@ -1825,19 +1562,9 @@ testthat::test_that( period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ), - info = "This wrapper only supports one control area EIC per request." - ) - testthat::expect_error( - object = financial_expenses_and_income( - eic = "10YCZ-CEPS-----N", - period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2023-05-01", tz = "CET"), - tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "One year range limit should be applied!" + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = financial_expenses_and_income( @@ -1847,7 +1574,7 @@ testthat::test_that( tidy_output = TRUE, security_token = "" ), - info = "Valid security token should be provided." + regexp = "should comply with the UUID v4 format" ) } ) @@ -1885,7 +1612,7 @@ testthat::test_that( period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) @@ -1895,20 +1622,10 @@ testthat::test_that( period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Assertion on 'eic' failed: Must have length 1" ) - testthat::expect_error( - object = fcr_total_capacity( - eic = "10YEU-CONT-SYNC0", - period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2023-05-01", tz = "CET"), - tidy_output = TRUE, - security_token = "dummy_token" - ), - regexp = "One year range limit should be applied" - ) testthat::expect_error( object = fcr_total_capacity( eic = "10YEU-CONT-SYNC0", @@ -1917,11 +1634,7 @@ testthat::test_that( tidy_output = TRUE, security_token = "" ), - regexp = paste( - "Assertion on 'security_token' failed:", - "All elements must have at least 1 characters,", - "but element 1 has 0 characters." - ) + regexp = "should comply with the UUID v4 format" ) } ) @@ -1956,57 +1669,32 @@ testthat::test_that( testthat::expect_error( object = shares_of_fcr_capacity( eic = NULL, - business_type = "C23", period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "One area EIC should be provided." + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = shares_of_fcr_capacity( eic = c("10YDE-VE-------2", "10YDE-RWENET---I"), - business_type = "C23", - period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), - tidy_output = TRUE, - security_token = "dummy_token" - ), - info = "This wrapper only supports one area EIC per request." - ) - testthat::expect_error( - object = shares_of_fcr_capacity( - eic = "10YDE-VE-------2", - business_type = "INVALID", period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ), - info = "The 'business_type' should be 'C23' or 'B95'." - ) - testthat::expect_error( - object = shares_of_fcr_capacity( - eic = "10YDE-VE-------2", - business_type = "C23", - period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2023-05-01", tz = "CET"), - tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "One year range limit should be applied!" + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = shares_of_fcr_capacity( eic = "10YDE-VE-------2", - business_type = "C23", period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE, security_token = "" ), - info = "Valid security token should be provided." + regexp = "should comply with the UUID v4 format" ) } ) @@ -2045,9 +1733,9 @@ testthat::test_that( period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-04-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "One area EIC should be provided." + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = rr_and_frr_actual_capacity( @@ -2056,9 +1744,9 @@ testthat::test_that( period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-04-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "This wrapper only supports one area EIC per request." + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = rr_and_frr_actual_capacity( @@ -2067,9 +1755,12 @@ testthat::test_that( period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-04-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "The 'process_type' should be 'A56' (FRR) or 'A46' (RR)." + regexp = paste( + "Assertion on 'process_type' failed:", + "Must be element of set \\{'A56','A46'\\}" + ) ) testthat::expect_error( object = rr_and_frr_actual_capacity( @@ -2080,7 +1771,7 @@ testthat::test_that( tidy_output = TRUE, security_token = "" ), - info = "Valid security token should be provided." + regexp = "should comply with the UUID v4 format" ) } ) @@ -2124,9 +1815,12 @@ testthat::test_that( period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "One acquiring domain EIC should be provided." + regexp = paste( + "Assertion on 'eic_acquiring' failed:", + "Must be of type 'string', not 'NULL'" + ) ) testthat::expect_error( object = sharing_of_rr_and_frr_capacity( @@ -2136,11 +1830,14 @@ testthat::test_that( period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "One connecting domain EIC should be provided." - ) - testthat::expect_error( + regexp = paste( + "Assertion on 'eic_connecting' failed:", + "Must be of type 'string', not 'NULL'" + ) + ) + testthat::expect_error( object = sharing_of_rr_and_frr_capacity( eic_acquiring = c("10YCB-GERMANY--8", "10YDE-VE-------2"), eic_connecting = "10YAT-APG------L", @@ -2148,12 +1845,9 @@ testthat::test_that( period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = paste( - "This wrapper only supports one acquiring and", - "one connecting EIC per request." - ) + regexp = "Assertion on 'eic_acquiring' failed: Must have length 1" ) testthat::expect_error( object = sharing_of_rr_and_frr_capacity( @@ -2163,9 +1857,12 @@ testthat::test_that( period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), - info = "The 'process_type' should be 'A56' (FRR) or 'A46' (RR)." + regexp = paste( + "Assertion on 'process_type' failed:", + "Must be element of set \\{'A56','A46'\\}" + ) ) testthat::expect_error( object = sharing_of_rr_and_frr_capacity( @@ -2173,23 +1870,173 @@ testthat::test_that( eic_connecting = "10YAT-APG------L", process_type = "A56", period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2023-05-01", tz = "CET"), + period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = "" ), - info = "One year range limit should be applied!" + regexp = "should comply with the UUID v4 format" ) + } +) + + +testthat::test_that( + desc = "netted_volumes_per_border() validates inputs", + code = { testthat::expect_error( - object = sharing_of_rr_and_frr_capacity( - eic_acquiring = "10YCB-GERMANY--8", - eic_connecting = "10YAT-APG------L", - process_type = "A56", + object = netted_volumes_per_border( + acquiring_eic = NULL, + connecting_eic = "10YFR-RTE------C", + process_type = "A63", + period_start = lubridate::ymd(x = "2025-03-01", tz = "CET"), + period_end = lubridate::ymd(x = "2025-03-02", tz = "CET"), + tidy_output = TRUE, + security_token = .test_token + ), + regexp = paste0( + "Assertion on 'acquiring_eic' failed: ", + "Must be of type 'string', not 'NULL'" + ) + ) + testthat::expect_error( + object = netted_volumes_per_border( + acquiring_eic = c("10YBE----------2", "10YDE-VE-------2"), + connecting_eic = "10YFR-RTE------C", + process_type = "A63", + period_start = lubridate::ymd(x = "2025-03-01", tz = "CET"), + period_end = lubridate::ymd(x = "2025-03-02", tz = "CET"), + tidy_output = TRUE, + security_token = .test_token + ), + regexp = "Assertion on 'acquiring_eic' failed: Must have length 1" + ) + testthat::expect_error( + object = netted_volumes_per_border( + acquiring_eic = "10YBE----------2", + connecting_eic = NULL, + process_type = "A63", + period_start = lubridate::ymd(x = "2025-03-01", tz = "CET"), + period_end = lubridate::ymd(x = "2025-03-02", tz = "CET"), + tidy_output = TRUE, + security_token = .test_token + ), + regexp = paste( + "Assertion on 'connecting_eic' failed:", + "Must be of type 'string', not 'NULL'." + ) + ) + testthat::expect_error( + object = netted_volumes_per_border( + acquiring_eic = "10YBE----------2", + connecting_eic = c("10YFR-RTE------C", "10YDE-VE-------2"), + process_type = "A63", + period_start = lubridate::ymd(x = "2025-03-01", tz = "CET"), + period_end = lubridate::ymd(x = "2025-03-02", tz = "CET"), + tidy_output = TRUE, + security_token = .test_token + ), + regexp = "Assertion on 'connecting_eic' failed: Must have length 1" + ) + testthat::expect_error( + object = netted_volumes_per_border( + acquiring_eic = "10YBE----------2", + connecting_eic = "10YFR-RTE------C", + process_type = "INVALID", + period_start = lubridate::ymd(x = "2025-03-01", tz = "CET"), + period_end = lubridate::ymd(x = "2025-03-02", tz = "CET"), + tidy_output = TRUE, + security_token = .test_token + ), + regexp = paste( + "Assertion on 'process_type' failed: Must be element of set", + "\\{'A51','A60','A61','A63'\\}" + ) + ) + testthat::expect_error( + object = netted_volumes_per_border( + acquiring_eic = "10YBE----------2", + connecting_eic = "10YFR-RTE------C", + process_type = "A63", + period_start = lubridate::ymd(x = "2025-03-01", tz = "CET"), + period_end = lubridate::ymd(x = "2025-03-05", tz = "CET"), + tidy_output = TRUE, + security_token = .test_token + ), + regexp = "1 day range limit should be applied" + ) + testthat::expect_error( + object = netted_volumes_per_border( + acquiring_eic = "10YBE----------2", + connecting_eic = "10YFR-RTE------C", + process_type = "A63", + period_start = lubridate::ymd(x = "2025-03-01", tz = "CET"), + period_end = lubridate::ymd(x = "2025-03-02", tz = "CET"), + tidy_output = TRUE, + security_token = "" + ), + regexp = "should comply with the UUID v4 format" + ) + } +) + + +testthat::test_that( + desc = "netted_volumes_per_border() works", + code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) + testthat::expect_no_error( + object = netted_volumes_per_border( + acquiring_eic = "10YBE----------2", + connecting_eic = "10YFR-RTE------C", + process_type = "A63", + period_start = lubridate::ymd(x = "2025-03-01", tz = "CET"), + period_end = lubridate::ymd(x = "2025-03-02", tz = "CET"), + tidy_output = TRUE + ) + ) + } +) + + +testthat::test_that( + desc = "shares_of_fcr_capacity() validates inputs (corrected)", + code = { + testthat::expect_error( + object = shares_of_fcr_capacity( + eic = NULL, + period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), + tidy_output = TRUE, + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" + ) + testthat::expect_error( + object = shares_of_fcr_capacity( + eic = c("10YCB-GERMANY--8", "10YDE-VE-------2"), + period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), + tidy_output = TRUE, + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must have length 1" + ) + testthat::expect_error( + object = shares_of_fcr_capacity( + eic = "10YCB-GERMANY--8", period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE, security_token = "" ), - info = "Valid security token should be provided." + regexp = "should comply with the UUID v4 format" ) } ) @@ -2221,7 +2068,7 @@ testthat::test_that( period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -2253,7 +2100,7 @@ testthat::test_that( process_type = "A47", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -2284,7 +2131,7 @@ testthat::test_that( eic = "10YCZ-CEPS-----N", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -2316,7 +2163,7 @@ testthat::test_that( process_type = "A51", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -2349,7 +2196,7 @@ testthat::test_that( process_type = "A51", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -2382,7 +2229,7 @@ testthat::test_that( process_type = "A60", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -2415,7 +2262,7 @@ testthat::test_that( process_type = "A63", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -2447,7 +2294,7 @@ testthat::test_that( business_type = "C46", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -2478,7 +2325,7 @@ testthat::test_that( eic = "10YCZ-CEPS-----N", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -2510,7 +2357,7 @@ testthat::test_that( process_type = "A47", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -2542,7 +2389,7 @@ testthat::test_that( process_type = "A47", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -2572,9 +2419,10 @@ testthat::test_that( object = procured_balancing_capacity( eic = "10YCZ-CEPS-----N", process_type = "A51", + market_agreement_type = "A13", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -2604,9 +2452,10 @@ testthat::test_that( object = allocation_of_cross_zonal_balancing_cap( eic_acquiring = "10YCB-GERMANY--8", eic_connecting = "10YAT-APG------L", + market_agreement_type = "A01", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -2638,7 +2487,7 @@ testthat::test_that( market_agreement_type = "A01", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "503" ) @@ -2669,7 +2518,7 @@ testthat::test_that( eic = "10YCZ-CEPS-----N", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -2700,7 +2549,7 @@ testthat::test_that( eic = "10YCZ-CEPS-----N", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -2734,7 +2583,7 @@ testthat::test_that( eic = "10YCZ-CEPS-----N", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -2765,7 +2614,7 @@ testthat::test_that( eic = "10YCZ-CEPS-----N", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -2796,7 +2645,7 @@ testthat::test_that( eic = "10YCZ-CEPS-----N", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -2805,7 +2654,7 @@ testthat::test_that( testthat::test_that( - desc = "rr_and_frr_actual_capacity() covers happy path with mock", + desc = "shares_of_fcr_capacity() covers happy path with mock (corrected)", code = { httr2::local_mocked_responses( mock = function(req) { @@ -2823,12 +2672,11 @@ testthat::test_that( } ) testthat::expect_error( - object = rr_and_frr_actual_capacity( + object = shares_of_fcr_capacity( eic = "10YCZ-CEPS-----N", - process_type = "A56", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -2836,138 +2684,8 @@ testthat::test_that( ) -# ---- netted_volumes_per_border ---- - -testthat::test_that( - desc = "netted_volumes_per_border() validates inputs", - code = { - testthat::expect_error( - object = netted_volumes_per_border( - acquiring_eic = NULL, - connecting_eic = "10YFR-RTE------C", - process_type = "A63", - period_start = lubridate::ymd(x = "2025-03-01", tz = "CET"), - period_end = lubridate::ymd(x = "2025-03-02", tz = "CET"), - tidy_output = TRUE, - security_token = "dummy_token" - ), - regexp = paste0( - "Assertion on 'acquiring_eic' failed: ", - "Must be of type 'string', not 'NULL'" - ) - ) - testthat::expect_error( - object = netted_volumes_per_border( - acquiring_eic = c("10YBE----------2", "10YDE-VE-------2"), - connecting_eic = "10YFR-RTE------C", - process_type = "A63", - period_start = lubridate::ymd(x = "2025-03-01", tz = "CET"), - period_end = lubridate::ymd(x = "2025-03-02", tz = "CET"), - tidy_output = TRUE, - security_token = "dummy_token" - ), - regexp = "Assertion on 'acquiring_eic' failed: Must have length 1" - ) - testthat::expect_error( - object = netted_volumes_per_border( - acquiring_eic = "10YBE----------2", - connecting_eic = NULL, - process_type = "A63", - period_start = lubridate::ymd(x = "2025-03-01", tz = "CET"), - period_end = lubridate::ymd(x = "2025-03-02", tz = "CET"), - tidy_output = TRUE, - security_token = "dummy_token" - ), - regexp = paste( - "Assertion on 'connecting_eic' failed:", - "Must be of type 'string', not 'NULL'." - ) - ) - testthat::expect_error( - object = netted_volumes_per_border( - acquiring_eic = "10YBE----------2", - connecting_eic = c("10YFR-RTE------C", "10YDE-VE-------2"), - process_type = "A63", - period_start = lubridate::ymd(x = "2025-03-01", tz = "CET"), - period_end = lubridate::ymd(x = "2025-03-02", tz = "CET"), - tidy_output = TRUE, - security_token = "dummy_token" - ), - regexp = "Assertion on 'connecting_eic' failed: Must have length 1" - ) - testthat::expect_error( - object = netted_volumes_per_border( - acquiring_eic = "10YBE----------2", - connecting_eic = "10YFR-RTE------C", - process_type = "INVALID", - period_start = lubridate::ymd(x = "2025-03-01", tz = "CET"), - period_end = lubridate::ymd(x = "2025-03-02", tz = "CET"), - tidy_output = TRUE, - security_token = "dummy_token" - ), - info = "The 'process_type' should be 'A51', 'A60', 'A61' or 'A63'." - ) - testthat::expect_error( - object = netted_volumes_per_border( - acquiring_eic = "10YBE----------2", - connecting_eic = "10YFR-RTE------C", - process_type = "A63", - period_start = lubridate::ymd(x = "2025-03-01", tz = "CET"), - period_end = lubridate::ymd(x = "2025-03-05", tz = "CET"), - tidy_output = TRUE, - security_token = "dummy_token" - ), - regexp = "One day range limit should be applied" - ) - testthat::expect_error( - object = netted_volumes_per_border( - acquiring_eic = "10YBE----------2", - connecting_eic = "10YFR-RTE------C", - process_type = "A63", - period_start = lubridate::ymd(x = "2025-03-01", tz = "CET"), - period_end = lubridate::ymd(x = "2025-03-02", tz = "CET"), - tidy_output = TRUE, - security_token = "" - ), - info = "Valid security token should be provided." - ) - } -) - - testthat::test_that( - desc = "netted_volumes_per_border() works", - code = { - testthat::skip_if_not( - condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, - message = "No ENTSOE_PAT environment variable set" - ) - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) - testthat::expect_no_error( - object = netted_volumes_per_border( - acquiring_eic = "10YBE----------2", - connecting_eic = "10YFR-RTE------C", - process_type = "A63", - period_start = lubridate::ymd( - x = "2025-03-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2025-03-02", - tz = "CET" - ), - tidy_output = TRUE - ) - ) - } -) - - -testthat::test_that( - desc = "netted_volumes_per_border() covers happy path with mock", + desc = "rr_and_frr_actual_capacity() covers happy path with mock", code = { httr2::local_mocked_responses( mock = function(req) { @@ -2985,13 +2703,12 @@ testthat::test_that( } ) testthat::expect_error( - object = netted_volumes_per_border( - acquiring_eic = "10YBE----------2", - connecting_eic = "10YFR-RTE------C", - process_type = "A63", - period_start = lubridate::ymd(x = "2025-03-01", tz = "CET"), - period_end = lubridate::ymd(x = "2025-03-02", tz = "CET"), - security_token = "dummy_token" + object = rr_and_frr_actual_capacity( + eic = "10YCZ-CEPS-----N", + process_type = "A56", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = .test_token ), regexp = "HTTP 503" ) @@ -3000,51 +2717,7 @@ testthat::test_that( testthat::test_that( - desc = "shares_of_fcr_capacity() validates inputs (corrected)", - code = { - testthat::expect_error( - object = shares_of_fcr_capacity( - eic = NULL, - period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), - tidy_output = TRUE, - security_token = "dummy_token" - ) - ) - testthat::expect_error( - object = shares_of_fcr_capacity( - eic = c("10YCB-GERMANY--8", "10YDE-VE-------2"), - period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), - tidy_output = TRUE, - security_token = "dummy_token" - ) - ) - testthat::expect_error( - object = shares_of_fcr_capacity( - eic = "10YCB-GERMANY--8", - period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), - tidy_output = TRUE, - security_token = "" - ) - ) - testthat::expect_error( - object = shares_of_fcr_capacity( - eic = "10YCB-GERMANY--8", - period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2023-05-01", tz = "CET"), - tidy_output = TRUE, - security_token = "dummy_token" - ), - regexp = "One year range limit should be applied" - ) - } -) - - -testthat::test_that( - desc = "shares_of_fcr_capacity() covers happy path with mock (corrected)", + desc = "netted_volumes_per_border() covers happy path with mock", code = { httr2::local_mocked_responses( mock = function(req) { @@ -3062,11 +2735,13 @@ testthat::test_that( } ) testthat::expect_error( - object = shares_of_fcr_capacity( - eic = "10YCB-GERMANY--8", - period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + object = netted_volumes_per_border( + acquiring_eic = "10YBE----------2", + connecting_eic = "10YFR-RTE------C", + process_type = "A63", + period_start = lubridate::ymd(x = "2025-03-01", tz = "CET"), + period_end = lubridate::ymd(x = "2025-03-02", tz = "CET"), + security_token = .test_token ), regexp = "HTTP 503" ) diff --git a/tests/testthat/test-en_generation.R b/tests/testthat/test-en_generation.R index 0fae963b..61205807 100644 --- a/tests/testthat/test-en_generation.R +++ b/tests/testthat/test-en_generation.R @@ -6,31 +6,35 @@ testthat::test_that( eic = "10YFR-RTE------C", year = lubridate::year(x = Sys.Date()) - 3.4, psr_type = NULL, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Must be of type 'integerish'" ) testthat::expect_error( object = gen_installed_capacity_per_pt( eic = NULL, year = lubridate::year(x = Sys.Date()), psr_type = NULL, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = gen_installed_capacity_per_pt( eic = "10YFR-RTE------C", year = lubridate::year(x = Sys.Date()), security_token = "" - ) + ), + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = gen_installed_capacity_per_pt( eic = c("10YFR-RTE------C", "10YDE-VE-------2"), year = lubridate::year(x = Sys.Date()), psr_type = NULL, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = gen_installed_capacity_per_pt( @@ -40,8 +44,9 @@ testthat::test_that( lubridate::year(x = Sys.Date()) - 1L ), psr_type = NULL, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Must have length 1" ) } ) @@ -84,8 +89,9 @@ testthat::test_that( eic = "10YFR-RTE------C", year = lubridate::year(x = Sys.Date()) + 1.4, psr_type = NULL, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Must be of type 'integerish'" ) testthat::expect_error( object = gen_installed_capacity_per_pu( @@ -95,39 +101,44 @@ testthat::test_that( lubridate::year(x = Sys.Date()) - 1L ), psr_type = NULL, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Must have length 1" ) testthat::expect_error( object = gen_installed_capacity_per_pu( eic = "10YFR-RTE------C", year = lubridate::year(x = Sys.Date()) + 4L, psr_type = NULL, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Cannot be shown more than 3 years ahead" ) testthat::expect_error( object = gen_installed_capacity_per_pu( eic = NULL, year = lubridate::year(x = Sys.Date()), psr_type = NULL, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = gen_installed_capacity_per_pu( eic = "10YFR-RTE------C", year = lubridate::year(x = Sys.Date()), security_token = "" - ) + ), + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = gen_installed_capacity_per_pu( eic = c("10YFR-RTE------C", "10YDE-VE-------2"), year = lubridate::year(x = Sys.Date()), psr_type = NULL, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must have length 1" ) } ) @@ -182,61 +193,41 @@ testthat::test_that( testthat::expect_error( object = gen_storage_mean_filling_rate( eic = c("10YFR-RTE------C", "10YDE-VE-------2"), - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = gen_storage_mean_filling_rate( eic = NULL, - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = gen_storage_mean_filling_rate( eic = "10YFR-RTE------C", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), security_token = "" - ) + ), + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = gen_storage_mean_filling_rate( eic = "10YFR-RTE------C", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2022-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2022-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "380 days range limit should be applied" ) } ) @@ -256,42 +247,24 @@ testthat::test_that( testthat::expect_no_error( object = gen_storage_mean_filling_rate( eic = "10YFR-RTE------C", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE ) ) testthat::expect_no_error( object = gen_storage_mean_filling_rate( eic = "10YFR-RTE------C", - period_start = lubridate::ymd_hms( - x = "2024-03-31 00:00:00", - tz = "CET" - ), - period_end = lubridate::ymd_hms( - x = "2024-03-31 16:00:00", - tz = "CET" - ), + period_start = lubridate::ymd_hm(x = "2024-03-31 00:00", tz = "CET"), + period_end = lubridate::ymd_hm(x = "2024-03-31 16:00", tz = "CET"), tidy_output = TRUE ) ) testthat::expect_no_error( object = gen_storage_mean_filling_rate( eic = "10YFR-RTE------C", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = FALSE ) ) @@ -305,64 +278,44 @@ testthat::test_that( testthat::expect_error( object = gen_per_prod_type( eic = c("10YFR-RTE------C", "10YDE-VE-------2"), - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), gen_type = NULL, tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = gen_per_prod_type( eic = NULL, - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), gen_type = NULL, tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = gen_per_prod_type( eic = "10YFR-RTE------C", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), security_token = "" - ) + ), + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = gen_per_prod_type( eic = "10YFR-RTE------C", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2022-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2022-03-01", tz = "CET"), gen_type = NULL, tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "1 year range limit should be applied" ) } ) @@ -382,14 +335,8 @@ testthat::test_that( testthat::expect_no_error( object = gen_per_prod_type( eic = "10YFR-RTE------C", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), gen_type = NULL, tidy_output = TRUE ) @@ -397,14 +344,8 @@ testthat::test_that( testthat::expect_no_error( object = gen_per_prod_type( eic = "10YFR-RTE------C", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), gen_type = "B01", tidy_output = TRUE ) @@ -419,66 +360,46 @@ testthat::test_that( testthat::expect_error( object = gen_per_gen_unit( eic = "10YDE-VE-------2", - period_start = lubridate::ymd( - x = "2020-01-31", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-01-31", tz = "CET"), + period_end = lubridate::ymd(x = "2020-02-01", tz = "CET"), gen_type = NULL, tidy_output = TRUE, security_token = "" - ) + ), + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = gen_per_gen_unit( eic = NULL, - period_start = lubridate::ymd( - x = "2020-01-31", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-01-31", tz = "CET"), + period_end = lubridate::ymd(x = "2020-02-01", tz = "CET"), gen_type = NULL, tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = gen_per_gen_unit( eic = c("10YDE-VE-------2", "10YFR-RTE------C"), - period_start = lubridate::ymd( - x = "2020-01-31", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-01-31", tz = "CET"), + period_end = lubridate::ymd(x = "2020-02-01", tz = "CET"), gen_type = NULL, tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = gen_per_gen_unit( eic = "10YDE-VE-------2", - period_start = lubridate::ymd( - x = "2020-01-31", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-01-31", tz = "CET"), + period_end = lubridate::ymd(x = "2020-02-01", tz = "CET"), gen_type = NULL, tidy_output = TRUE, security_token = NULL - ) + ), + regexp = "should comply with the UUID v4 format" ) } ) @@ -498,14 +419,8 @@ testthat::test_that( testthat::expect_no_error( object = gen_per_gen_unit( eic = "10YDE-VE-------2", - period_start = lubridate::ymd( - x = "2020-01-31", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-01-31", tz = "CET"), + period_end = lubridate::ymd(x = "2020-02-01", tz = "CET"), gen_type = NULL, tidy_output = TRUE ) @@ -513,14 +428,8 @@ testthat::test_that( testthat::expect_no_error( object = gen_per_gen_unit( eic = "10YFR-RTE------C", - period_start = lubridate::ymd_hm( - x = "2020-01-31 02:00", - tz = "CET" - ), - period_end = lubridate::ymd_hm( - x = "2020-02-01 03:00", - tz = "CET" - ), + period_start = lubridate::ymd_hm(x = "2020-01-31 02:00", tz = "CET"), + period_end = lubridate::ymd_hm(x = "2020-02-01 03:00", tz = "CET"), gen_type = NULL, tidy_output = TRUE ) @@ -528,14 +437,8 @@ testthat::test_that( testthat::expect_no_error( object = gen_per_gen_unit( eic = "10YDE-VE-------2", - period_start = lubridate::ymd( - x = "2020-01-31", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-02-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-01-31", tz = "CET"), + period_end = lubridate::ymd(x = "2020-02-02", tz = "CET"), gen_type = c("B04", "B05"), tidy_output = TRUE ) @@ -543,14 +446,8 @@ testthat::test_that( testthat::expect_no_error( object = gen_per_gen_unit( eic = "10YDE-VE-------2", - period_start = lubridate::ymd( - x = "2020-01-31", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-02-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-01-31", tz = "CET"), + period_end = lubridate::ymd(x = "2020-02-02", tz = "CET"), gen_type = c("B03"), tidy_output = TRUE ) @@ -565,62 +462,42 @@ testthat::test_that( testthat::expect_error( object = gen_day_ahead_forecast( eic = "10YFR-RTE------C", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, security_token = "" - ) + ), + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = gen_day_ahead_forecast( eic = NULL, - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = gen_day_ahead_forecast( eic = c("10YFR-RTE------C", "10YDE-VE-------2"), - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = gen_day_ahead_forecast( eic = "10YFR-RTE------C", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2021-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2021-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "1 year range limit should be applied" ) } ) @@ -640,14 +517,8 @@ testthat::test_that( testthat::expect_no_error( object = gen_day_ahead_forecast( eic = "10YFR-RTE------C", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE ) ) @@ -661,62 +532,42 @@ testthat::test_that( testthat::expect_error( object = gen_wind_solar_forecasts( eic = c("10YFR-RTE------C", "10YDE-VE-------2"), - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = gen_wind_solar_forecasts( eic = NULL, - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = gen_wind_solar_forecasts( eic = "10YFR-RTE------C", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, security_token = "" - ) + ), + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = gen_wind_solar_forecasts( eic = "10YFR-RTE------C", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2021-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2021-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "1 year range limit should be applied" ) } ) @@ -736,14 +587,8 @@ testthat::test_that( testthat::expect_no_error( gen_wind_solar_forecasts( eic = "10YFR-RTE------C", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE ) ) @@ -773,7 +618,7 @@ testthat::test_that( object = gen_installed_capacity_per_pt( eic = "10YFR-RTE------C", year = 2020L, - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -803,7 +648,7 @@ testthat::test_that( object = gen_installed_capacity_per_pu( eic = "10YDE-VE-------2", year = 2020L, - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -835,7 +680,7 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -867,7 +712,7 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -899,7 +744,7 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -931,7 +776,7 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -963,7 +808,7 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) diff --git a/tests/testthat/test-en_helpers.R b/tests/testthat/test-en_helpers.R index 4b94d71d..ba330d24 100644 --- a/tests/testthat/test-en_helpers.R +++ b/tests/testthat/test-en_helpers.R @@ -1,3 +1,51 @@ +testthat::test_that( + desc = "fetch_eic_csv() works", + code = { + m$reset() + fake_eic <- data.frame( + eic_code = "10YDE-VE-------2", + eic_display_name = "DE(50HzT)", + eic_long_name = "50Hertz Transmission", + eic_parent = NA_character_, + eic_responsible_party = NA_character_, + eic_status = "Active", + market_participant_postal_code = NA_character_, + market_participant_iso_country_code = "DE", + market_participant_vat_code = NA_character_, + eic_type_function_list = NA_character_, + type = "T", + stringsAsFactors = FALSE + ) |> as_tbl() + testthat::local_mocked_bindings( + get_eiccodes = function(...) fake_eic, + .package = "entsoeapi" + ) + testthat::expect_no_error( + object = result <- fetch_eic_csv(csv_file = "T_eicCodes.csv") + ) + testthat::expect_s3_class( + object = result, + class = "tbl_df" + ) + testthat::expect_contains( + object = names(result), + expected = c("eic_code", "eic_display_name", "eic_long_name") + ) + } +) + + +testthat::test_that( + desc = "fetch_eic_csv() validates inputs", + code = { + testthat::expect_error( + object = fetch_eic_csv(csv_file = "foo.csv"), + regexp = "Assertion on 'csv_file' failed\\: Must be element of set" + ) + } +) + + testthat::test_that( desc = "all_approved_eic() validates inputs", code = { @@ -12,11 +60,35 @@ testthat::test_that( testthat::test_that( desc = "all_approved_eic() works", code = { - testthat::skip_if_not( - condition = curl::nslookup(host = .pd_domain, error = FALSE) |> - is.null() |> - isFALSE(), - message = "The Entso-e download site cannot be reached" + m$reset() + make_fake_eic <- function(type_val) { + data.frame( + eic_code = paste0("10Y-FAKE-", type_val), + eic_display_name = paste("Fake", type_val), + eic_long_name = paste("Fake Long", type_val), + eic_parent = NA_character_, + eic_responsible_party = NA_character_, + eic_status = "Active", + market_participant_iso_country_code = "DE", + market_participant_postal_code = NA_character_, + market_participant_vat_code = NA_character_, + eic_type_function_list = NA_character_, + type = type_val, + stringsAsFactors = FALSE + ) |> as_tbl() + } + testthat::local_mocked_bindings( + get_eiccodes = function(f, ...) { + type_val <- switch( + f, + "X_eicCodes.csv" = "X", "Y_eicCodes.csv" = "Y", + "Z_eicCodes.csv" = "Z", "T_eicCodes.csv" = "T", + "V_eicCodes.csv" = "V", "W_eicCodes.csv" = "W", + "A_eicCodes.csv" = "A" + ) + make_fake_eic(type_val) + }, + .package = "entsoeapi" ) testthat::expect_no_error(object = tbl <- all_approved_eic()) testthat::expect_s3_class(object = tbl, class = "tbl_df", exact = FALSE) @@ -55,11 +127,24 @@ testthat::test_that( testthat::test_that( desc = "party_eic() works", code = { - testthat::skip_if_not( - condition = curl::nslookup(host = .pd_domain, error = FALSE) |> - is.null() |> - isFALSE(), - message = "The Entso-e download site cannot be reached" + m$reset() + fake_eic <- data.frame( + eic_code = "10X-FAKE-PARTY-1", + eic_display_name = "Fake Party", + eic_long_name = "Fake Party Long", + eic_parent = NA_character_, + eic_responsible_party = NA_character_, + eic_status = "Active", + market_participant_iso_country_code = "DE", + market_participant_postal_code = NA_character_, + market_participant_vat_code = NA_character_, + eic_type_function_list = NA_character_, + type = "X", + stringsAsFactors = FALSE + ) |> as_tbl() + testthat::local_mocked_bindings( + get_eiccodes = function(...) fake_eic, + .package = "entsoeapi" ) testthat::expect_no_error(object = tbl <- party_eic()) testthat::expect_s3_class(object = tbl, class = "tbl_df", exact = FALSE) @@ -99,11 +184,24 @@ testthat::test_that( testthat::test_that( desc = "area_eic() works", code = { - testthat::skip_if_not( - condition = curl::nslookup(host = .pd_domain, error = FALSE) |> - is.null() |> - isFALSE(), - message = "The Entso-e download site cannot be reached" + m$reset() + fake_eic <- data.frame( + eic_code = "10Y-FAKE-AREA--1", + eic_display_name = "Fake Area", + eic_long_name = "Fake Area Long", + eic_parent = NA_character_, + eic_responsible_party = NA_character_, + eic_status = "Active", + market_participant_iso_country_code = "DE", + market_participant_postal_code = NA_character_, + market_participant_vat_code = NA_character_, + eic_type_function_list = NA_character_, + type = "Y", + stringsAsFactors = FALSE + ) |> as_tbl() + testthat::local_mocked_bindings( + get_eiccodes = function(...) fake_eic, + .package = "entsoeapi" ) testthat::expect_no_error(object = tbl <- area_eic()) testthat::expect_s3_class(object = tbl, class = "tbl_df", exact = FALSE) @@ -143,11 +241,24 @@ testthat::test_that( testthat::test_that( desc = "accounting_point_eic() works", code = { - testthat::skip_if_not( - condition = curl::nslookup(host = .pd_domain, error = FALSE) |> - is.null() |> - isFALSE(), - message = "The Entso-e download site cannot be reached" + m$reset() + fake_eic <- data.frame( + eic_code = "10Z-FAKE-ACCP-01", + eic_display_name = "Fake AccPt", + eic_long_name = "Fake AccPt Long", + eic_parent = NA_character_, + eic_responsible_party = NA_character_, + eic_status = "Active", + market_participant_iso_country_code = "DE", + market_participant_postal_code = NA_character_, + market_participant_vat_code = NA_character_, + eic_type_function_list = NA_character_, + type = "Z", + stringsAsFactors = FALSE + ) |> as_tbl() + testthat::local_mocked_bindings( + get_eiccodes = function(...) fake_eic, + .package = "entsoeapi" ) testthat::expect_no_error(object = tbl <- accounting_point_eic()) testthat::expect_s3_class(object = tbl, class = "tbl_df", exact = FALSE) @@ -187,11 +298,24 @@ testthat::test_that( testthat::test_that( desc = "tie_line_eic() works", code = { - testthat::skip_if_not( - condition = curl::nslookup(host = .pd_domain, error = FALSE) |> - is.null() |> - isFALSE(), - message = "The Entso-e download site cannot be reached" + m$reset() + fake_eic <- data.frame( + eic_code = "10T-FAKE-TIE---1", + eic_display_name = "Fake Tie", + eic_long_name = "Fake Tie Long", + eic_parent = NA_character_, + eic_responsible_party = NA_character_, + eic_status = "Active", + market_participant_iso_country_code = "DE", + market_participant_postal_code = NA_character_, + market_participant_vat_code = NA_character_, + eic_type_function_list = NA_character_, + type = "T", + stringsAsFactors = FALSE + ) |> as_tbl() + testthat::local_mocked_bindings( + get_eiccodes = function(...) fake_eic, + .package = "entsoeapi" ) testthat::expect_no_error(object = tbl <- tie_line_eic()) testthat::expect_s3_class(object = tbl, class = "tbl_df", exact = FALSE) @@ -231,11 +355,24 @@ testthat::test_that( testthat::test_that( desc = "location_eic() works", code = { - testthat::skip_if_not( - condition = curl::nslookup(host = .pd_domain, error = FALSE) |> - is.null() |> - isFALSE(), - message = "The Entso-e download site cannot be reached" + m$reset() + fake_eic <- data.frame( + eic_code = "10V-FAKE-LOC---1", + eic_display_name = "Fake Loc", + eic_long_name = "Fake Loc Long", + eic_parent = NA_character_, + eic_responsible_party = NA_character_, + eic_status = "Active", + market_participant_iso_country_code = "DE", + market_participant_postal_code = NA_character_, + market_participant_vat_code = NA_character_, + eic_type_function_list = NA_character_, + type = "V", + stringsAsFactors = FALSE + ) |> as_tbl() + testthat::local_mocked_bindings( + get_eiccodes = function(...) fake_eic, + .package = "entsoeapi" ) testthat::expect_no_error(object = tbl <- location_eic()) testthat::expect_s3_class(object = tbl, class = "tbl_df", exact = FALSE) @@ -275,11 +412,24 @@ testthat::test_that( testthat::test_that( desc = "resource_object_eic() works", code = { - testthat::skip_if_not( - condition = curl::nslookup(host = .pd_domain, error = FALSE) |> - is.null() |> - isFALSE(), - message = "The Entso-e download site cannot be reached" + m$reset() + fake_eic <- data.frame( + eic_code = "10W-FAKE-RESRC-1", + eic_display_name = "Fake Resource", + eic_long_name = "Fake Resource Long", + eic_parent = NA_character_, + eic_responsible_party = NA_character_, + eic_status = "Active", + market_participant_iso_country_code = "DE", + market_participant_postal_code = NA_character_, + market_participant_vat_code = NA_character_, + eic_type_function_list = NA_character_, + type = "W", + stringsAsFactors = FALSE + ) |> as_tbl() + testthat::local_mocked_bindings( + get_eiccodes = function(...) fake_eic, + .package = "entsoeapi" ) testthat::expect_no_error(object = tbl <- resource_object_eic()) testthat::expect_s3_class(object = tbl, class = "tbl_df", exact = FALSE) @@ -322,11 +472,24 @@ testthat::test_that( testthat::test_that( desc = "substation_eic() works", code = { - testthat::skip_if_not( - condition = curl::nslookup(host = .pd_domain, error = FALSE) |> - is.null() |> - isFALSE(), - message = "The Entso-e download site cannot be reached" + m$reset() + fake_eic <- data.frame( + eic_code = "10A-FAKE-SUBST-1", + eic_display_name = "Fake Sub", + eic_long_name = "Fake Sub Long", + eic_parent = NA_character_, + eic_responsible_party = NA_character_, + eic_status = "Active", + market_participant_iso_country_code = "DE", + market_participant_postal_code = NA_character_, + market_participant_vat_code = NA_character_, + eic_type_function_list = NA_character_, + type = "A", + stringsAsFactors = FALSE + ) |> as_tbl() + testthat::local_mocked_bindings( + get_eiccodes = function(...) fake_eic, + .package = "entsoeapi" ) testthat::expect_no_error(object = tbl <- substation_eic()) testthat::expect_s3_class(object = tbl, class = "tbl_df", exact = FALSE) @@ -390,115 +553,22 @@ testthat::test_that( testthat::test_that( - desc = "get_news() respects n parameter", - code = { - xml_fixture <- readLines( - con = testthat::test_path("fixtures", "news_feed.xml"), - encoding = "UTF-8" - ) |> - paste(collapse = "\n") |> - charToRaw() - httr2::local_mocked_responses( - mock = function(req) { - httr2::response( - status_code = 200L, - url = req$url, - headers = list("content-type" = "application/xml"), - body = xml_fixture - ) - } - ) - tbl <- get_news(n = 1L) - testthat::expect_equal(object = nrow(tbl), expected = 1L) - testthat::expect_equal( - object = tbl$title[[1L]], - expected = "TP PROD data publication delays" - ) - } -) - - -testthat::test_that( - desc = "get_news() handles n larger than available items", - code = { - xml_fixture <- readLines( - con = testthat::test_path("fixtures", "news_feed.xml"), - encoding = "UTF-8" - ) |> - paste(collapse = "\n") |> - charToRaw() - httr2::local_mocked_responses( - mock = function(req) { - httr2::response( - status_code = 200L, - url = req$url, - headers = list("content-type" = "application/xml"), - body = xml_fixture - ) - } - ) - tbl <- get_news(n = 100L) - testthat::expect_equal(object = nrow(tbl), expected = 3L) - } -) - - -testthat::test_that( - desc = "get_news() handles empty feed", - code = { - empty_rss <- paste( - '', - '', - "", - "Empty", - "", - "", - sep = "\n" - ) |> - charToRaw() - httr2::local_mocked_responses( - mock = function(req) { - httr2::response( - status_code = 200L, - url = req$url, - headers = list("content-type" = "application/xml"), - body = empty_rss - ) - } - ) - tbl <- get_news() - testthat::expect_s3_class(object = tbl, class = "tbl_df", exact = FALSE) - testthat::expect_equal(object = nrow(tbl), expected = 0L) - } -) - - -testthat::test_that( - desc = "get_news() errors on HTTP failure", + desc = "all_allocated_eic() validates inputs", code = { - httr2::local_mocked_responses( - mock = function(req) { - httr2::response( - status_code = 500L, - url = req$url, - headers = list("content-type" = "text/html"), - body = charToRaw("Internal Server Error") - ) - } - ) testthat::expect_error( - object = get_news(), - regexp = "500" + object = all_allocated_eic(url = "foo"), + regexp = 'unused argument \\(url = "foo"\\)' ) } ) testthat::test_that( - desc = "get_news() returns result invisibly", + desc = "all_allocated_eic() responses got and appended into a tibble", code = { + m$reset() xml_fixture <- readLines( - con = testthat::test_path("fixtures", "news_feed.xml"), + con = testthat::test_path("fixtures", "allocated_eic_min.xml"), encoding = "UTF-8" ) |> paste(collapse = "\n") |> @@ -513,55 +583,18 @@ testthat::test_that( ) } ) - testthat::expect_invisible(get_news()) - } -) - - -testthat::test_that( - desc = "all_allocated_eic() validates inputs", - code = { - testthat::expect_error( - object = all_allocated_eic(url = "foo"), - regexp = 'unused argument \\(url = "foo"\\)' - ) - } -) - - -testthat::test_that( - desc = "all_allocated_eic() responses got and appended into a tibble", - code = { - testthat::skip_if_not( - condition = curl::nslookup(host = .pd_domain, error = FALSE) |> - is.null() |> - isFALSE(), - message = "The Entso-e download site cannot be reached" - ) - m$reset() testthat::expect_no_error(object = tbl <- all_allocated_eic()) testthat::expect_s3_class(object = tbl, class = "tbl_df", exact = FALSE) testthat::expect_false(object = anyNA(tbl$created_date_time)) - testthat::expect_setequal( + testthat::expect_contains( object = names(tbl), expected = c( - "revision_number", - "created_date_time", "eic_code", - "doc_status_value", "doc_status", - "instance_component_attribute", - "long_name", - "display_name", + "created_date_time", "last_request_date", - "deactivation_requested_date_and_or_time_date", - "eic_code_market_participant_street_address", - "market_participant_vat_code_name", - "market_participant_acer_code_name", - "description", - "responsible_market_participant_mrid", - "function_names", - "parent_market_document_mrid" + "instance_component_attribute", + "function_names" ) ) } @@ -663,36 +696,6 @@ testthat::test_that( ) -testthat::test_that( - desc = "all_allocated_eic() parses ZIP/octet-stream content-type response", - code = { - m$reset() - xml_fixture <- readLines( - con = testthat::test_path("fixtures", "allocated_eic_min.xml"), - encoding = "UTF-8" - ) |> - paste(collapse = "\n") |> - charToRaw() - httr2::local_mocked_responses( - mock = function(req) { - httr2::response( - status_code = 200L, - url = req$url, - headers = list("content-type" = "application/zip"), - body = xml_fixture - ) - } - ) - testthat::expect_s3_class( - object = tbl <- all_allocated_eic(), - class = "tbl_df", - exact = FALSE - ) - testthat::expect_gt(object = nrow(tbl), expected = 0L) - } -) - - testthat::test_that( desc = "all_allocated_eic() stops on XML with unexpected structure", code = { @@ -790,29 +793,6 @@ testthat::test_that( ) -testthat::test_that( - desc = "all_allocated_eic() stops on HTML error response", - code = { - m$reset() - httr2::local_mocked_responses( - mock = function(req) { - httr2::response( - status_code = 403L, - url = req$url, - headers = list("content-type" = "text/html"), - body = "Access Denied" |> - charToRaw() - ) - } - ) - testthat::expect_error( - object = all_allocated_eic(), - regexp = "403" - ) - } -) - - testthat::test_that( desc = "all_allocated_eic() returns correct number of rows", code = { @@ -861,22 +841,19 @@ testthat::test_that( ) tbl <- all_allocated_eic() testthat::expect_true( - object = grepl( - pattern = " - ", - x = tbl$function_names[[1L]], - fixed = TRUE - ) + object = tbl$function_names[[1L]] |> + str_detect(pattern = " - ") ) } ) testthat::test_that( - desc = "all_allocated_eic() collapses Function_Names correctly", + desc = "all_allocated_eic() stops when bind_cols fails", code = { m$reset() xml_fixture <- readLines( - con = testthat::test_path("fixtures", "get_allocated_eic_dupl.xml"), + con = testthat::test_path("fixtures", "get_allocated_eic_min.xml"), encoding = "UTF-8" ) |> paste(collapse = "\n") |> @@ -891,18 +868,23 @@ testthat::test_that( ) } ) - tbl <- all_allocated_eic() - testthat::expect_equal(object = nrow(tbl), expected = 1L) + testthat::local_mocked_bindings( + bind_cols = function(...) stop("mocked bind_cols error"), + .package = "entsoeapi" + ) + testthat::expect_error( + object = all_allocated_eic(), + regexp = "unexpected tree structure" + ) } ) testthat::test_that( - desc = "all_allocated_eic() stops when bind_cols fails", + desc = "get_news() falls back to raw text when read_html() fails", code = { - m$reset() xml_fixture <- readLines( - con = testthat::test_path("fixtures", "get_allocated_eic_min.xml"), + con = testthat::test_path("fixtures", "news_feed.xml"), encoding = "UTF-8" ) |> paste(collapse = "\n") |> @@ -918,12 +900,17 @@ testthat::test_that( } ) testthat::local_mocked_bindings( - bind_cols = function(...) stop("mocked bind_cols error"), + read_html = function(...) stop("mocked read_html failure"), .package = "entsoeapi" ) - testthat::expect_error( - object = all_allocated_eic(), - regexp = "unexpected tree structure" + tbl <- testthat::expect_no_error( + object = suppressMessages(get_news(n = 1L)) + ) + testthat::expect_s3_class(object = tbl, class = "tbl_df", exact = FALSE) + testthat::expect_equal(object = nrow(tbl), expected = 1L) + testthat::expect_equal( + object = tbl$description[[1L]], + expected = "

Some data publications are delayed.

" ) } ) diff --git a/tests/testthat/test-en_load.R b/tests/testthat/test-en_load.R index 5e8a6a87..194a7290 100644 --- a/tests/testthat/test-en_load.R +++ b/tests/testthat/test-en_load.R @@ -4,62 +4,42 @@ testthat::test_that( testthat::expect_error( object = load_actual_total( eic = NULL, - period_start = lubridate::ymd( - x = Sys.Date() - lubridate::days(x = 30), - tz = "CET" - ), - period_end = lubridate::ymd( - x = Sys.Date(), - tz = "CET" - ), + period_start = lubridate::ymd(x = "2026-03-01", tz = "CET"), + period_end = lubridate::ymd(x = "2026-06-31", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = load_actual_total( eic = c("10Y1001A1001A83F", "10YCZ-CEPS-----N"), - period_start = lubridate::ymd( - x = Sys.Date() - lubridate::days(x = 30), - tz = "CET" - ), - period_end = lubridate::ymd( - x = Sys.Date(), - tz = "CET" - ), + period_start = lubridate::ymd(x = "2026-03-01", tz = "CET"), + period_end = lubridate::ymd(x = "2026-03-31", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = load_actual_total( eic = "10Y1001A1001A83F", - period_start = lubridate::ymd( - x = Sys.Date() - lubridate::days(x = 30), - tz = "CET" - ), - period_end = lubridate::ymd( - x = Sys.Date(), - tz = "CET" - ), + period_start = lubridate::ymd(x = "2026-03-01", tz = "CET"), + period_end = lubridate::ymd(x = "2026-03-31", tz = "CET"), tidy_output = TRUE, security_token = "" - ) + ), + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = load_actual_total( eic = "10Y1001A1001A83F", - period_start = lubridate::ymd( - x = Sys.Date() - lubridate::days(x = 390), - tz = "CET" - ), - period_end = lubridate::ymd( - x = Sys.Date(), - tz = "CET" - ), + period_start = lubridate::ymd(x = "2025-03-01", tz = "CET"), + period_end = lubridate::ymd(x = "2026-03-31", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "1 year range limit should be applied" ) } ) @@ -79,14 +59,8 @@ testthat::test_that( result <- testthat::expect_no_error( object = load_actual_total( eic = "10Y1001A1001A83F", - period_start = lubridate::ymd( - x = Sys.Date() - lubridate::days(x = 30), - tz = "CET" - ), - period_end = lubridate::ymd( - x = Sys.Date(), - tz = "CET" - ), + period_start = lubridate::ymd(x = "2025-03-01", tz = "CET"), + period_end = lubridate::ymd(x = "2025-03-31", tz = "CET"), tidy_output = TRUE ) ) @@ -103,62 +77,42 @@ testthat::test_that( testthat::expect_error( object = load_day_ahead_total_forecast( eic = NULL, - period_start = lubridate::ymd( - x = Sys.Date() - lubridate::days(x = 30), - tz = "CET" - ), - period_end = lubridate::ymd( - x = Sys.Date(), - tz = "CET" - ), + period_start = lubridate::ymd(x = "2025-03-01", tz = "CET"), + period_end = lubridate::ymd(x = "2025-03-31", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = load_day_ahead_total_forecast( eic = c("10Y1001A1001A83F", "10YCZ-CEPS-----N"), - period_start = lubridate::ymd( - x = Sys.Date() - lubridate::days(x = 30), - tz = "CET" - ), - period_end = lubridate::ymd( - x = Sys.Date(), - tz = "CET" - ), + period_start = lubridate::ymd(x = "2025-03-01", tz = "CET"), + period_end = lubridate::ymd(x = "2025-03-31", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = load_day_ahead_total_forecast( eic = "10Y1001A1001A83F", - period_start = lubridate::ymd( - x = Sys.Date() - lubridate::days(x = 30), - tz = "CET" - ), - period_end = lubridate::ymd( - x = Sys.Date(), - tz = "CET" - ), + period_start = lubridate::ymd(x = "2025-03-01", tz = "CET"), + period_end = lubridate::ymd(x = "2025-03-31", tz = "CET"), tidy_output = TRUE, security_token = "" - ) + ), + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = load_day_ahead_total_forecast( eic = "10Y1001A1001A83F", - period_start = lubridate::ymd( - x = Sys.Date() - lubridate::days(x = 390), - tz = "CET" - ), - period_end = lubridate::ymd( - x = Sys.Date(), - tz = "CET" - ), + period_start = lubridate::ymd(x = "2025-03-01", tz = "CET"), + period_end = lubridate::ymd(x = "2026-03-31", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "1 year range limit should be applied" ) } ) @@ -178,14 +132,8 @@ testthat::test_that( result <- testthat::expect_no_error( object = load_day_ahead_total_forecast( eic = "10Y1001A1001A83F", - period_start = lubridate::ymd( - x = Sys.Date() - lubridate::days(x = 30), - tz = "CET" - ), - period_end = lubridate::ymd( - x = Sys.Date(), - tz = "CET" - ), + period_start = lubridate::ymd(x = "2026-03-01", tz = "CET"), + period_end = lubridate::ymd(x = "2026-03-31", tz = "CET"), tidy_output = TRUE ) ) @@ -202,62 +150,42 @@ testthat::test_that( testthat::expect_error( object = load_week_ahead_total_forecast( eic = NULL, - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-11-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-11-30", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = load_week_ahead_total_forecast( eic = c("10Y1001A1001A83F", "10YCZ-CEPS-----N"), - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-11-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-11-30", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = load_week_ahead_total_forecast( eic = "10Y1001A1001A83F", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-11-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-11-30", tz = "CET"), tidy_output = TRUE, security_token = "" - ) + ), + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = load_week_ahead_total_forecast( eic = "10Y1001A1001A83F", - period_start = lubridate::ymd( - x = "2018-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-11-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2018-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-11-30", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "1 year range limit should be applied" ) } ) @@ -277,14 +205,8 @@ testthat::test_that( result <- testthat::expect_no_error( object = load_week_ahead_total_forecast( eic = "10Y1001A1001A83F", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-11-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-11-30", tz = "CET"), tidy_output = TRUE ) ) @@ -301,62 +223,42 @@ testthat::test_that( testthat::expect_error( object = load_month_ahead_total_forecast( eic = NULL, - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-11-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-11-30", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = load_month_ahead_total_forecast( eic = c("10Y1001A1001A83F", "10YCZ-CEPS-----N"), - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-11-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-11-30", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = load_month_ahead_total_forecast( eic = "10Y1001A1001A82H", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-11-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-11-30", tz = "CET"), tidy_output = TRUE, security_token = "" - ) + ), + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = load_month_ahead_total_forecast( eic = "10Y1001A1001A82H", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-11-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-11-30", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "1 year range limit should be applied" ) } ) @@ -376,14 +278,8 @@ testthat::test_that( result <- testthat::expect_no_error( object = load_month_ahead_total_forecast( eic = "10Y1001A1001A82H", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-11-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-11-30", tz = "CET"), tidy_output = TRUE ) ) @@ -400,62 +296,42 @@ testthat::test_that( testthat::expect_error( object = load_year_ahead_total_forecast( eic = NULL, - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-11-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-11-30", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = load_year_ahead_total_forecast( eic = c("10Y1001A1001A83F", "10YCZ-CEPS-----N"), - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-11-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-11-30", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = load_year_ahead_total_forecast( eic = "10Y1001A1001A82H", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-11-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-11-30", tz = "CET"), tidy_output = TRUE, security_token = "" - ) + ), + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = load_year_ahead_total_forecast( eic = "10Y1001A1001A82H", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-11-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-11-30", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "1 year range limit should be applied" ) } ) @@ -475,14 +351,8 @@ testthat::test_that( result <- testthat::expect_no_error( object = load_year_ahead_total_forecast( eic = "10Y1001A1001A83F", - period_start = lubridate::ymd( - x = "2024-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-11-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-11-30", tz = "CET"), tidy_output = TRUE ) ) @@ -499,62 +369,42 @@ testthat::test_that( testthat::expect_error( object = load_year_ahead_forecast_margin( eic = NULL, - period_start = lubridate::ymd( - x = "2019-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-12-31", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-12-31", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = load_year_ahead_forecast_margin( eic = c("10Y1001A1001A83F", "10YCZ-CEPS-----N"), - period_start = lubridate::ymd( - x = "2019-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-12-31", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-12-31", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = load_year_ahead_forecast_margin( eic = "10Y1001A1001A83F", - period_start = lubridate::ymd( - x = "2019-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-12-31", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-12-31", tz = "CET"), tidy_output = TRUE, security_token = "" - ) + ), + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = load_year_ahead_forecast_margin( eic = "10Y1001A1001A83F", - period_start = lubridate::ymd( - x = "2019-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-12-31", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-12-31", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "1 year range limit should be applied" ) } ) @@ -574,14 +424,8 @@ testthat::test_that( result <- testthat::expect_no_error( object = load_year_ahead_forecast_margin( eic = "10Y1001A1001A83F", - period_start = lubridate::ymd( - x = "2019-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-12-31", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-12-31", tz = "CET"), tidy_output = TRUE ) ) @@ -616,7 +460,7 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -648,7 +492,7 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -680,7 +524,7 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -712,7 +556,7 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -744,7 +588,7 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -776,7 +620,7 @@ testthat::test_that( period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) diff --git a/tests/testthat/test-en_market.R b/tests/testthat/test-en_market.R index 02dc6030..d19eb9c2 100644 --- a/tests/testthat/test-en_market.R +++ b/tests/testthat/test-en_market.R @@ -4,62 +4,42 @@ testthat::test_that( testthat::expect_error( object = energy_prices( eic = NULL, - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-12-01", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ) + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-12-01", tz = "CET"), + tidy_output = FALSE, + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = energy_prices( eic = c("10YCZ-CEPS-----N", "10Y1001A1001A82H"), - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-12-01", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ) + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-12-01", tz = "CET"), + tidy_output = FALSE, + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = energy_prices( eic = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-12-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-12-01", tz = "CET"), tidy_output = FALSE, security_token = "" - ) + ), + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = energy_prices( eic = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-12-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-12-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "1 year range limit should be applied" ) } ) @@ -79,14 +59,8 @@ testthat::test_that( testthat::expect_no_error( object = energy_prices( eic = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-12-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-12-01", tz = "CET"), tidy_output = FALSE ) ) @@ -101,33 +75,21 @@ testthat::test_that( object = total_nominated_capacity( eic_in = "10YDE-VE-------2", eic_out = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2019-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-03-01", tz = "CET"), tidy_output = TRUE, security_token = "" ), - regexp = "All elements must have at least 1 characters" + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = total_nominated_capacity( eic_in = NULL, eic_out = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2019-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be of type 'string', not 'NULL'" ) @@ -135,16 +97,10 @@ testthat::test_that( object = total_nominated_capacity( eic_in = "10YDE-VE-------2", eic_out = NULL, - period_start = lubridate::ymd( - x = "2019-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be of type 'string', not 'NULL'" ) @@ -152,36 +108,13 @@ testthat::test_that( object = total_nominated_capacity( eic_in = c("10YDE-VE-------2", "10YCZ-CEPS-----N"), eic_out = c("10YDE-VE-------2", "10YCZ-CEPS-----N"), - period_start = lubridate::ymd( - x = "2019-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must have length 1" ) - testthat::expect_error( - object = total_nominated_capacity( - eic_in = "10YDE-VE-------2", - eic_out = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2019-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), - tidy_output = TRUE, - security_token = "dummy_token" - ), - regexp = "One year range limit should be applied" - ) } ) @@ -201,14 +134,8 @@ testthat::test_that( object = total_nominated_capacity( eic_in = "10YDE-VE-------2", eic_out = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2019-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-03-01", tz = "CET"), tidy_output = TRUE ) ) @@ -223,18 +150,12 @@ testthat::test_that( object = already_allocated_total_capacity( eic_in = NULL, eic_out = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2019-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-02-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-02-02", tz = "CET"), auction_category = "A04", contract_type = "A01", tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be of type 'string', not 'NULL'" ) @@ -242,18 +163,12 @@ testthat::test_that( object = already_allocated_total_capacity( eic_in = "10YDE-VE-------2", eic_out = NULL, - period_start = lubridate::ymd( - x = "2019-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-02-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-02-02", tz = "CET"), auction_category = "A04", contract_type = "A01", tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be of type 'string', not 'NULL'" ) @@ -261,18 +176,12 @@ testthat::test_that( object = already_allocated_total_capacity( eic_in = c("10YCZ-CEPS-----N", "10YDE-VE-------2"), eic_out = c("10YCZ-CEPS-----N", "10YDE-VE-------2"), - period_start = lubridate::ymd( - x = "2019-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-02-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-02-02", tz = "CET"), auction_category = "A04", contract_type = "A01", tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must have length 1" ) @@ -280,39 +189,14 @@ testthat::test_that( object = already_allocated_total_capacity( eic_in = "10YDE-VE-------2", eic_out = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2019-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-02-02", - tz = "CET" - ), - auction_category = "A04", - contract_type = "A01", - tidy_output = FALSE, - security_token = "All elements must have at least 1 characters" - ), - regexp = "" - ) - testthat::expect_error( - object = already_allocated_total_capacity( - eic_in = "10YDE-VE-------2", - eic_out = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2019-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2021-02-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-02-02", tz = "CET"), auction_category = "A04", contract_type = "A01", tidy_output = FALSE, - security_token = "dummy_token" + security_token = rep(x = "z", 36L) |> paste(collapse = "") ), - regexp = "One year range limit should be applied" + regexp = "The `security_token` should comply with the UUID v4 format" ) } ) @@ -333,14 +217,8 @@ testthat::test_that( object = already_allocated_total_capacity( eic_in = "10YDE-VE-------2", eic_out = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2024-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-02-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-02-02", tz = "CET"), auction_category = "A04", contract_type = "A01", tidy_output = FALSE @@ -357,16 +235,10 @@ testthat::test_that( object = implicit_offered_transfer_capacity( eic_in = NULL, eic_out = "10YDK-1--------W", - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be of type 'string', not 'NULL'" ) @@ -374,16 +246,10 @@ testthat::test_that( object = implicit_offered_transfer_capacity( eic_in = "10Y1001A1001A82H", eic_out = NULL, - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be of type 'string', not 'NULL'" ) @@ -391,16 +257,10 @@ testthat::test_that( object = implicit_offered_transfer_capacity( eic_in = c("10Y1001A1001A82H", "10YDK-1--------W"), eic_out = c("10YDK-1--------W", "10Y1001A1001A82H"), - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must have length 1" ) @@ -408,17 +268,11 @@ testthat::test_that( object = implicit_offered_transfer_capacity( eic_in = "10Y1001A1001A82H", eic_out = "10YDK-1--------W", - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), contract_type = "A99", tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be element of set" ) @@ -426,35 +280,12 @@ testthat::test_that( object = implicit_offered_transfer_capacity( eic_in = "10Y1001A1001A82H", eic_out = "10YDK-1--------W", - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), tidy_output = FALSE, security_token = "" ), - regexp = "All elements must have at least 1 characters" - ) - testthat::expect_error( - object = implicit_offered_transfer_capacity( - eic_in = "10Y1001A1001A82H", - eic_out = "10YDK-1--------W", - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-08-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "One year range limit should be applied" + regexp = "should comply with the UUID v4 format" ) } ) @@ -475,18 +306,12 @@ testthat::test_that( object = implicit_offered_transfer_capacity( eic_in = "10Y1001A1001A82H", eic_out = "10YDK-1--------W", - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), tidy_output = FALSE, security_token = "ABC" ), - regexp = "Missing or invalid security token" + regexp = "should comply with the UUID v4 format" ) } ) @@ -507,14 +332,8 @@ testthat::test_that( object = implicit_offered_transfer_capacity( eic_in = "10Y1001A1001A82H", eic_out = "10YDK-1--------W", - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), contract_type = "A01", tidy_output = FALSE ) @@ -530,16 +349,10 @@ testthat::test_that( object = explicit_offered_transfer_capacity( eic_in = NULL, eic_out = "10YGB----------A", - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be of type 'string', not 'NULL'" ) @@ -547,16 +360,10 @@ testthat::test_that( object = explicit_offered_transfer_capacity( eic_in = "10YBE----------2", eic_out = NULL, - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be of type 'string', not 'NULL'" ) @@ -564,16 +371,10 @@ testthat::test_that( object = explicit_offered_transfer_capacity( eic_in = c("10YBE----------2", "10YGB----------A"), eic_out = c("10YGB----------A", "10YBE----------2"), - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must have length 1" ) @@ -581,17 +382,11 @@ testthat::test_that( object = explicit_offered_transfer_capacity( eic_in = "10YBE----------2", eic_out = "10YGB----------A", - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), contract_type = "A99", tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be element of set" ) @@ -599,35 +394,12 @@ testthat::test_that( object = explicit_offered_transfer_capacity( eic_in = "10YBE----------2", eic_out = "10YGB----------A", - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), tidy_output = FALSE, security_token = "" ), - regexp = "All elements must have at least 1 characters" - ) - testthat::expect_error( - object = explicit_offered_transfer_capacity( - eic_in = "10YBE----------2", - eic_out = "10YGB----------A", - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-08-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "One year range limit should be applied!" + regexp = "should comply with the UUID v4 format" ) } ) @@ -648,18 +420,12 @@ testthat::test_that( object = explicit_offered_transfer_capacity( eic_in = "10YBE----------2", eic_out = "10YGB----------A", - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), tidy_output = FALSE, security_token = "ABC" ), - regexp = "Missing or invalid security token" + regexp = "should comply with the UUID v4 format" ) } ) @@ -680,14 +446,8 @@ testthat::test_that( object = explicit_offered_transfer_capacity( eic_in = "10YBE----------2", eic_out = "10YGB----------A", - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-18", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-18", tz = "CET"), contract_type = "A01", tidy_output = FALSE ) @@ -703,16 +463,10 @@ testthat::test_that( object = continuous_offered_transfer_capacity( eic_in = NULL, eic_out = "10YBE----------2", - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-05-17", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), + period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be of type 'string', not 'NULL'" ) @@ -720,16 +474,10 @@ testthat::test_that( object = continuous_offered_transfer_capacity( eic_in = "10YNL----------L", eic_out = NULL, - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-05-17", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), + period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be of type 'string', not 'NULL'" ) @@ -737,16 +485,10 @@ testthat::test_that( object = continuous_offered_transfer_capacity( eic_in = c("10YNL----------L", "10YBE----------2"), eic_out = c("10YBE----------2", "10YNL----------L"), - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-05-17", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), + period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must have length 1" ) @@ -754,35 +496,12 @@ testthat::test_that( object = continuous_offered_transfer_capacity( eic_in = "10YNL----------L", eic_out = "10YBE----------2", - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-05-17", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), + period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), tidy_output = FALSE, security_token = "" ), - regexp = "All elements must have at least 1 characters" - ) - testthat::expect_error( - object = continuous_offered_transfer_capacity( - eic_in = "10YNL----------L", - eic_out = "10YBE----------2", - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2025-05-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "One year range limit should be applied" + regexp = "should comply with the UUID v4 format" ) } ) @@ -803,18 +522,12 @@ testthat::test_that( object = continuous_offered_transfer_capacity( eic_in = "10YNL----------L", eic_out = "10YBE----------2", - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-05-17", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), + period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), tidy_output = FALSE, security_token = "ABC" ), - regexp = "Missing or invalid security token" + regexp = "should comply with the UUID v4 format" ) } ) @@ -835,14 +548,8 @@ testthat::test_that( object = continuous_offered_transfer_capacity( eic_in = "10YNL----------L", eic_out = "10YBE----------2", - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-05-17", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), + period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), tidy_output = FALSE ) ) @@ -856,84 +563,54 @@ testthat::test_that( testthat::expect_error( object = flow_based_allocations( eic = NULL, - period_start = lubridate::ymd( - x = "2018-12-31", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-01-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2018-12-31", tz = "CET"), + period_end = lubridate::ymd(x = "2019-01-01", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = flow_based_allocations( eic = c("10YDOM-REGION-1V", "10Y1001A1001A91G"), - period_start = lubridate::ymd( - x = "2018-12-31", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-01-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2018-12-31", tz = "CET"), + period_end = lubridate::ymd(x = "2019-01-01", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must have length 1" ) testthat::expect_error( object = flow_based_allocations( eic = "10YDOM-REGION-1V", - period_start = lubridate::ymd( - x = "2018-12-31", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-01-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2018-12-31", tz = "CET"), + period_end = lubridate::ymd(x = "2019-01-01", tz = "CET"), process_type = "A99", tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be element of set" ) testthat::expect_error( object = flow_based_allocations( eic = "10YDOM-REGION-1V", - period_start = lubridate::ymd( - x = "2018-12-31", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-01-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2018-12-31", tz = "CET"), + period_end = lubridate::ymd(x = "2019-01-01", tz = "CET"), archive = "yes", tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be of type 'logical flag', not 'character'" ) testthat::expect_error( object = flow_based_allocations( eic = "10YDOM-REGION-1V", - period_start = lubridate::ymd( - x = "2018-12-31", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-01-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2018-12-31", tz = "CET"), + period_end = lubridate::ymd(x = "2019-01-01", tz = "CET"), tidy_output = FALSE, security_token = "" ), - regexp = "All elements must have at least 1 characters" + regexp = "should comply with the UUID v4 format" ) } ) @@ -953,18 +630,12 @@ testthat::test_that( testthat::expect_error( object = flow_based_allocations( eic = "10YDOM-REGION-1V", - period_start = lubridate::ymd( - x = "2018-12-31", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-01-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2018-12-31", tz = "CET"), + period_end = lubridate::ymd(x = "2019-01-01", tz = "CET"), tidy_output = FALSE, security_token = "ABC" ), - regexp = "Missing or invalid security token" + regexp = "should comply with the UUID v4 format" ) } ) @@ -984,14 +655,8 @@ testthat::test_that( testthat::expect_no_error( object = flow_based_allocations( eic = "10YDOM-REGION-1V", - period_start = lubridate::ymd( - x = "2018-12-31", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-01-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2018-12-31", tz = "CET"), + period_end = lubridate::ymd(x = "2019-01-01", tz = "CET"), process_type = "A32", archive = TRUE, tidy_output = FALSE @@ -1008,16 +673,10 @@ testthat::test_that( object = auction_revenue( eic_in = NULL, eic_out = "10YHR-HEP------M", - period_start = lubridate::ymd( - x = "2023-08-25", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-26", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-08-25", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-26", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be of type 'string', not 'NULL'" ) @@ -1025,16 +684,10 @@ testthat::test_that( object = auction_revenue( eic_in = "10YBA-JPCC-----D", eic_out = NULL, - period_start = lubridate::ymd( - x = "2023-08-25", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-26", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-08-25", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-26", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be of type 'string', not 'NULL'" ) @@ -1042,16 +695,10 @@ testthat::test_that( object = auction_revenue( eic_in = c("10YBA-JPCC-----D", "10YHR-HEP------M"), eic_out = c("10YHR-HEP------M", "10YBA-JPCC-----D"), - period_start = lubridate::ymd( - x = "2023-08-25", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-26", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-08-25", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-26", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must have length 1" ) @@ -1059,17 +706,11 @@ testthat::test_that( object = auction_revenue( eic_in = "10YBA-JPCC-----D", eic_out = "10YHR-HEP------M", - period_start = lubridate::ymd( - x = "2023-08-25", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-26", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-08-25", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-26", tz = "CET"), contract_type = "A99", tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be element of set" ) @@ -1077,35 +718,12 @@ testthat::test_that( object = auction_revenue( eic_in = "10YBA-JPCC-----D", eic_out = "10YHR-HEP------M", - period_start = lubridate::ymd( - x = "2023-08-25", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-26", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-08-25", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-26", tz = "CET"), tidy_output = FALSE, security_token = "" ), - regexp = "All elements must have at least 1 characters" - ) - testthat::expect_error( - object = auction_revenue( - eic_in = "10YBA-JPCC-----D", - eic_out = "10YHR-HEP------M", - period_start = lubridate::ymd( - x = "2023-08-25", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-08-26", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "One year range limit should be applied" + regexp = "should comply with the UUID v4 format" ) } ) @@ -1126,18 +744,12 @@ testthat::test_that( object = auction_revenue( eic_in = "10YBA-JPCC-----D", eic_out = "10YHR-HEP------M", - period_start = lubridate::ymd( - x = "2023-08-25", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-26", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-08-25", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-26", tz = "CET"), tidy_output = FALSE, security_token = "ABC" ), - regexp = "Missing or invalid security token" + regexp = "should comply with the UUID v4 format" ) } ) @@ -1158,14 +770,8 @@ testthat::test_that( object = auction_revenue( eic_in = "10YBA-JPCC-----D", eic_out = "10YHR-HEP------M", - period_start = lubridate::ymd( - x = "2023-08-25", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-26", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-08-25", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-26", tz = "CET"), contract_type = "A01", tidy_output = FALSE ) @@ -1180,83 +786,43 @@ testthat::test_that( testthat::expect_error( object = net_positions( eic = NULL, - period_start = lubridate::ymd( - x = "2015-12-31", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2016-01-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2015-12-31", tz = "CET"), + period_end = lubridate::ymd(x = "2016-01-01", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = net_positions( eic = c("10YCZ-CEPS-----N", "10Y1001A1001A82H"), - period_start = lubridate::ymd( - x = "2015-12-31", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2016-01-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2015-12-31", tz = "CET"), + period_end = lubridate::ymd(x = "2016-01-01", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must have length 1" ) testthat::expect_error( object = net_positions( eic = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2015-12-31", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2016-01-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2015-12-31", tz = "CET"), + period_end = lubridate::ymd(x = "2016-01-01", tz = "CET"), contract_type = "A99", tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be element of set" ) testthat::expect_error( object = net_positions( eic = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2015-12-31", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2016-01-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2015-12-31", tz = "CET"), + period_end = lubridate::ymd(x = "2016-01-01", tz = "CET"), tidy_output = FALSE, security_token = "" ), - regexp = "All elements must have at least 1 characters" - ) - testthat::expect_error( - object = net_positions( - eic = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2015-12-31", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2016-12-31", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "One year range limit should be applied" + regexp = "should comply with the UUID v4 format" ) } ) @@ -1276,18 +842,12 @@ testthat::test_that( testthat::expect_error( object = net_positions( eic = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2015-12-31", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2016-01-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2015-12-31", tz = "CET"), + period_end = lubridate::ymd(x = "2016-01-01", tz = "CET"), tidy_output = FALSE, security_token = "ABC" ), - regexp = "Missing or invalid security token" + regexp = "should comply with the UUID v4 format" ) } ) @@ -1307,14 +867,8 @@ testthat::test_that( testthat::expect_no_error( object = net_positions( eic = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2015-12-31", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2016-01-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2015-12-31", tz = "CET"), + period_end = lubridate::ymd(x = "2016-01-01", tz = "CET"), contract_type = "A01", tidy_output = FALSE ) @@ -1326,69 +880,34 @@ testthat::test_that( testthat::test_that( desc = "congestion_income() validates inputs", code = { - testthat::expect_error( - object = congestion_income( - eic = "10YDOM-1001A083J", - period_start = lubridate::ymd( - x = "2015-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2016-01-02", - tz = "CET" - ), - contract_type = "A01", - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "One year range limit should be applied" - ) testthat::expect_error( object = congestion_income( eic = NULL, - period_start = lubridate::ymd( - x = "2016-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2016-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2016-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2016-01-02", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = congestion_income( eic = c("10YDOM-1001A083J", "10YCZ-CEPS-----N"), - period_start = lubridate::ymd( - x = "2016-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2016-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2016-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2016-01-02", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must have length 1" ) testthat::expect_error( object = congestion_income( eic = "10YDOM-1001A083J", - period_start = lubridate::ymd( - x = "2016-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2016-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2016-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2016-01-02", tz = "CET"), contract_type = "A99", tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be element of set" ) @@ -1400,7 +919,7 @@ testthat::test_that( tidy_output = FALSE, security_token = "" ), - regexp = "All elements must have at least 1 characters" + regexp = "should comply with the UUID v4 format" ) } ) @@ -1425,7 +944,7 @@ testthat::test_that( tidy_output = FALSE, security_token = "ABC" ), - info = "Unauthorized. Missing or invalid security token!" + regexp = "should comply with the UUID v4 format" ) } ) @@ -1465,7 +984,7 @@ testthat::test_that( period_start = lubridate::ymd(x = "2016-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2016-01-02", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = paste0( "Assertion on 'eic_in' failed: ", @@ -1476,16 +995,10 @@ testthat::test_that( object = allocated_transfer_capacities_3rd_countries( eic_in = "10YSK-SEPS-----K", eic_out = NULL, - period_start = lubridate::ymd( - x = "2016-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2016-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2016-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2016-01-02", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = paste( "Assertion on 'eic_out' failed:", @@ -1496,16 +1009,10 @@ testthat::test_that( object = allocated_transfer_capacities_3rd_countries( eic_in = c("10YSK-SEPS-----K", "10YUA-WEPS-----0"), eic_out = c("10YUA-WEPS-----0", "10YSK-SEPS-----K"), - period_start = lubridate::ymd( - x = "2016-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2016-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2016-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2016-01-02", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Assertion on 'eic_in' failed: Must have length 1." ) @@ -1513,17 +1020,11 @@ testthat::test_that( object = allocated_transfer_capacities_3rd_countries( eic_in = "10YSK-SEPS-----K", eic_out = "10YUA-WEPS-----0", - period_start = lubridate::ymd( - x = "2016-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2016-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2016-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2016-01-02", tz = "CET"), contract_type = "A99", tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = paste( "Assertion on 'contract_type' failed:", @@ -1535,17 +1036,11 @@ testthat::test_that( object = allocated_transfer_capacities_3rd_countries( eic_in = "10YSK-SEPS-----K", eic_out = "10YUA-WEPS-----0", - period_start = lubridate::ymd( - x = "2016-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2016-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2016-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2016-01-02", tz = "CET"), auction_category = "A99", tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = paste( "Assertion on 'auction_category'", @@ -1557,17 +1052,11 @@ testthat::test_that( object = allocated_transfer_capacities_3rd_countries( eic_in = "10YSK-SEPS-----K", eic_out = "10YUA-WEPS-----0", - period_start = lubridate::ymd( - x = "2016-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2016-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2016-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2016-01-02", tz = "CET"), position = 0L, tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Assertion on 'position' failed: Must be >= 1" ) @@ -1575,22 +1064,12 @@ testthat::test_that( object = allocated_transfer_capacities_3rd_countries( eic_in = "10YSK-SEPS-----K", eic_out = "10YUA-WEPS-----0", - period_start = lubridate::ymd( - x = "2016-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2016-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2016-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2016-01-02", tz = "CET"), tidy_output = FALSE, security_token = "" ), - regexp = paste( - "Assertion on 'security_token' failed:", - "All elements must have at least 1 characters,", - "but element 1 has 0 characters." - ) + regexp = "should comply with the UUID v4 format" ) } ) @@ -1611,18 +1090,12 @@ testthat::test_that( object = allocated_transfer_capacities_3rd_countries( eic_in = "10YSK-SEPS-----K", eic_out = "10YUA-WEPS-----0", - period_start = lubridate::ymd( - x = "2016-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2016-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2016-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2016-01-02", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = "ABC" ), - regexp = "Missing or invalid security token" + regexp = "should comply with the UUID v4 format" ) } ) @@ -1642,14 +1115,8 @@ testthat::test_that( df <- allocated_transfer_capacities_3rd_countries( eic_in = "10YSK-SEPS-----K", eic_out = "10YUA-WEPS-----0", - period_start = lubridate::ymd( - x = "2016-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2016-01-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2016-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2016-01-01", tz = "CET"), contract_type = "A01", auction_category = "A04", position = 2L, @@ -1663,14 +1130,8 @@ testthat::test_that( object = allocated_transfer_capacities_3rd_countries( eic_in = "10YSK-SEPS-----K", eic_out = "10YUA-WEPS-----0", - period_start = lubridate::ymd( - x = "2016-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2016-01-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2016-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2016-01-01", tz = "CET"), contract_type = ct, auction_category = at, position = 1L, @@ -1687,14 +1148,8 @@ testthat::test_that( object = allocated_transfer_capacities_3rd_countries( eic_in = "10YSK-SEPS-----K", eic_out = "10YUA-WEPS-----0", - period_start = lubridate::ymd( - x = "2015-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2015-05-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2015-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2015-05-01", tz = "CET"), contract_type = "A01", auction_category = "A04", position = 1L, @@ -1707,108 +1162,404 @@ testthat::test_that( testthat::test_that( - desc = "implicit_offered_transfer_capacity() covers happy path with mock", + desc = "implicit_offered_transfer_capacities() validates inputs", code = { - httr2::local_mocked_responses( - mock = function(req) { - httr2::response( - status_code = 503L, - url = req$url, - headers = list("content-type" = "application/xml"), - body = charToRaw( - paste0( - '', - "Service Unavailable" - ) - ) - ) - } + testthat::expect_error( + object = implicit_offered_transfer_capacities( + eic_in = NULL, + eic_out = "10YDK-1--------W", + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), + tidy_output = FALSE, + security_token = .test_token + ), + regexp = "Must be of type 'string', not 'NULL'" ) testthat::expect_error( - object = implicit_offered_transfer_capacity( - eic_in = "10YDE-VE-------2", - eic_out = "10YCZ-CEPS-----N", - period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" - ) + object = implicit_offered_transfer_capacities( + eic_in = "10Y1001A1001A82H", + eic_out = NULL, + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), + tidy_output = FALSE, + security_token = .test_token + ), + regexp = "Must be of type 'string', not 'NULL'" ) - } -) - - -testthat::test_that( - desc = "explicit_offered_transfer_capacity() covers happy path with mock", - code = { - httr2::local_mocked_responses( - mock = function(req) { - httr2::response( - status_code = 503L, - url = req$url, - headers = list("content-type" = "application/xml"), - body = charToRaw( - paste0( - '', - "Service Unavailable" - ) - ) - ) - } + testthat::expect_error( + object = implicit_offered_transfer_capacities( + eic_in = c("10Y1001A1001A82H", "10YDK-1--------W"), + eic_out = c("10YDK-1--------W", "10Y1001A1001A82H"), + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), + tidy_output = FALSE, + security_token = .test_token + ), + regexp = "Must have length 1" ) testthat::expect_error( - object = explicit_offered_transfer_capacity( - eic_in = "10YDE-VE-------2", - eic_out = "10YCZ-CEPS-----N", - period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + object = implicit_offered_transfer_capacities( + eic_in = "10Y1001A1001A82H", + eic_out = "10YDK-1--------W", + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), + tidy_output = FALSE, + security_token = "" ), - regexp = "HTTP 503" + regexp = "should comply with the UUID v4 format" ) } ) testthat::test_that( - desc = "continuous_offered_transfer_capacity() covers happy path with mock", + desc = "implicit_offered_transfer_capacities() validates inputs 2", code = { - httr2::local_mocked_responses( - mock = function(req) { - httr2::response( - status_code = 503L, - url = req$url, - headers = list("content-type" = "application/xml"), - body = charToRaw( - paste0( - '', - "Service Unavailable" - ) - ) - ) - } + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" ) testthat::expect_error( - object = continuous_offered_transfer_capacity( - eic_in = "10YNL----------L", - eic_out = "10YBE----------2", - period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + object = implicit_offered_transfer_capacities( + eic_in = "10Y1001A1001A82H", + eic_out = "10YDK-1--------W", + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), + tidy_output = FALSE, + security_token = "ABC" ), - regexp = "HTTP 503" + regexp = "should comply with the UUID v4 format" ) } ) testthat::test_that( - desc = "flow_based_allocations() covers happy path with mock", + desc = "implicit_offered_transfer_capacities() works", code = { - httr2::local_mocked_responses( - mock = function(req) { - httr2::response( - status_code = 503L, - url = req$url, + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) + testthat::expect_no_error( + object = implicit_offered_transfer_capacities( + eic_in = "10Y1001A1001A82H", + eic_out = "10YDK-1--------W", + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), + tidy_output = TRUE + ) + ) + } +) + + +testthat::test_that( + desc = "explicit_offered_transfer_capacities() validates inputs", + code = { + testthat::expect_error( + object = explicit_offered_transfer_capacities( + eic_in = NULL, + eic_out = "10YGB----------A", + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), + tidy_output = FALSE, + security_token = .test_token + ), + regexp = "Must be of type 'string', not 'NULL'" + ) + testthat::expect_error( + object = explicit_offered_transfer_capacities( + eic_in = "10YBE----------2", + eic_out = NULL, + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), + tidy_output = FALSE, + security_token = .test_token + ), + regexp = "Must be of type 'string', not 'NULL'" + ) + testthat::expect_error( + object = explicit_offered_transfer_capacities( + eic_in = c("10YBE----------2", "10YGB----------A"), + eic_out = c("10YGB----------A", "10YBE----------2"), + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), + tidy_output = FALSE, + security_token = .test_token + ), + regexp = "Must have length 1" + ) + testthat::expect_error( + object = explicit_offered_transfer_capacities( + eic_in = "10YBE----------2", + eic_out = "10YGB----------A", + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), + tidy_output = FALSE, + security_token = "" + ), + regexp = "should comply with the UUID v4 format" + ) + } +) + + +testthat::test_that( + desc = "explicit_offered_transfer_capacities() validates inputs 2", + code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) + testthat::expect_error( + object = explicit_offered_transfer_capacities( + eic_in = "10YBE----------2", + eic_out = "10YGB----------A", + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), + tidy_output = FALSE, + security_token = "ABC" + ), + regexp = "should comply with the UUID v4 format" + ) + } +) + + +testthat::test_that( + desc = "explicit_offered_transfer_capacities() works", + code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) + testthat::expect_no_error( + object = explicit_offered_transfer_capacities( + eic_in = "10YBE----------2", + eic_out = "10YGB----------A", + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), + tidy_output = TRUE + ) + ) + } +) + + +testthat::test_that( + desc = "continuous_offered_transfer_capacities() validates inputs", + code = { + testthat::expect_error( + object = continuous_offered_transfer_capacities( + eic_in = NULL, + eic_out = "10YBE----------2", + period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), + period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), + tidy_output = FALSE, + security_token = .test_token + ), + regexp = "Must be of type 'string', not 'NULL'" + ) + testthat::expect_error( + object = continuous_offered_transfer_capacities( + eic_in = "10YNL----------L", + eic_out = NULL, + period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), + period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), + tidy_output = FALSE, + security_token = .test_token + ), + regexp = "Must be of type 'string', not 'NULL'" + ) + testthat::expect_error( + object = continuous_offered_transfer_capacities( + eic_in = c("10YNL----------L", "10YBE----------2"), + eic_out = c("10YBE----------2", "10YNL----------L"), + period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), + period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), + tidy_output = FALSE, + security_token = .test_token + ), + regexp = "Must have length 1" + ) + testthat::expect_error( + object = continuous_offered_transfer_capacities( + eic_in = "10YNL----------L", + eic_out = "10YBE----------2", + period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), + period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), + tidy_output = FALSE, + security_token = "" + ), + regexp = "should comply with the UUID v4 format" + ) + } +) + + +testthat::test_that( + desc = "continuous_offered_transfer_capacities() validates inputs 2", + code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) + testthat::expect_error( + object = continuous_offered_transfer_capacities( + eic_in = "10YNL----------L", + eic_out = "10YBE----------2", + period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), + period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), + tidy_output = FALSE, + security_token = "ABC" + ), + regexp = "should comply with the UUID v4 format" + ) + } +) + + +testthat::test_that( + desc = "continuous_offered_transfer_capacities() works", + code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) + testthat::expect_no_error( + object = continuous_offered_transfer_capacities( + eic_in = "10YNL----------L", + eic_out = "10YBE----------2", + period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), + period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), + tidy_output = TRUE + ) + ) + } +) + + +testthat::test_that( + desc = "intraday_prices() validates inputs", + code = { + testthat::expect_error( + object = intraday_prices( + eic = NULL, + period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), + period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), + tidy_output = FALSE, + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" + ) + testthat::expect_error( + object = intraday_prices( + eic = c("10YPL-AREA-----S", "10YCZ-CEPS-----N"), + period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), + period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), + tidy_output = FALSE, + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must have length 1" + ) + testthat::expect_error( + object = intraday_prices( + eic = "10YPL-AREA-----S", + period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), + period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), + tidy_output = FALSE, + security_token = "ABC" + ), + regexp = "should comply with the UUID v4 format" + ) + } +) + + +testthat::test_that( + desc = "aggregated_bids() validates inputs", + code = { + testthat::expect_error( + object = aggregated_bids( + eic = NULL, + process_type = "A51", + period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), + period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), + tidy_output = FALSE, + security_token = .test_token + ), + regexp = "Must be of type 'string', not 'NULL'" + ) + testthat::expect_error( + object = aggregated_bids( + eic = c("10YPL-AREA-----S", "10YCZ-CEPS-----N"), + process_type = "A51", + period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), + period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), + tidy_output = FALSE, + security_token = .test_token + ), + regexp = "Must have length 1" + ) + testthat::expect_error( + object = aggregated_bids( + eic = "10YPL-AREA-----S", + process_type = "INVALID", + period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), + period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), + tidy_output = FALSE, + security_token = .test_token + ), + regexp = "Must be element of set" + ) + testthat::expect_error( + object = aggregated_bids( + eic = "10YPL-AREA-----S", + process_type = "A51", + period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), + period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), + tidy_output = FALSE, + security_token = "" + ), + regexp = "should comply with the UUID v4 format" + ) + } +) + + +testthat::test_that( + desc = "intraday_prices() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, headers = list("content-type" = "application/xml"), body = charToRaw( paste0( @@ -1820,12 +1571,12 @@ testthat::test_that( } ) testthat::expect_error( - object = flow_based_allocations( - eic = "10Y1001A1001A91G", - period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - process_type = "A43", - security_token = "dummy_token" + object = intraday_prices( + eic = "10YCZ-CEPS-----N", + period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), + period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), + tidy_output = FALSE, + security_token = .test_token ), regexp = "HTTP 503" ) @@ -1834,7 +1585,7 @@ testthat::test_that( testthat::test_that( - desc = "auction_revenue() covers happy path with mock", + desc = "aggregated_bids() covers happy path with mock", code = { httr2::local_mocked_responses( mock = function(req) { @@ -1852,12 +1603,13 @@ testthat::test_that( } ) testthat::expect_error( - object = auction_revenue( - eic_in = "10YBA-JPCC-----D", - eic_out = "10YHR-HEP------M", - period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + object = aggregated_bids( + eic = "10YCZ-CEPS-----N", + process_type = "A51", + period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), + period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), + tidy_output = FALSE, + security_token = .test_token ), regexp = "HTTP 503" ) @@ -1866,7 +1618,7 @@ testthat::test_that( testthat::test_that( - desc = "total_nominated_capacity() covers happy path with mock", + desc = "implicit_offered_transfer_capacity() covers happy path with mock", code = { httr2::local_mocked_responses( mock = function(req) { @@ -1884,21 +1636,20 @@ testthat::test_that( } ) testthat::expect_error( - object = total_nominated_capacity( + object = implicit_offered_transfer_capacity( eic_in = "10YDE-VE-------2", eic_out = "10YCZ-CEPS-----N", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" - ), - regexp = "HTTP 503" + security_token = .test_token + ) ) } ) testthat::test_that( - desc = "already_allocated_total_capacity() covers happy path with mock", + desc = "explicit_offered_transfer_capacity() covers happy path with mock", code = { httr2::local_mocked_responses( mock = function(req) { @@ -1916,12 +1667,12 @@ testthat::test_that( } ) testthat::expect_error( - object = already_allocated_total_capacity( + object = explicit_offered_transfer_capacity( eic_in = "10YDE-VE-------2", eic_out = "10YCZ-CEPS-----N", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -1930,7 +1681,7 @@ testthat::test_that( testthat::test_that( - desc = "energy_prices() covers happy path with mock", + desc = "continuous_offered_transfer_capacity() covers happy path with mock", code = { httr2::local_mocked_responses( mock = function(req) { @@ -1948,21 +1699,21 @@ testthat::test_that( } ) testthat::expect_error( - object = energy_prices( - eic = "10YCZ-CEPS-----N", + object = continuous_offered_transfer_capacity( + eic_in = "10YNL----------L", + eic_out = "10YBE----------2", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - contract_type = "A01", - security_token = "dummy_token" + security_token = .test_token ), - regexp = "503" + regexp = "HTTP 503" ) } ) testthat::test_that( - desc = "net_positions() covers happy path with mock", + desc = "flow_based_allocations() covers happy path with mock", code = { httr2::local_mocked_responses( mock = function(req) { @@ -1980,11 +1731,12 @@ testthat::test_that( } ) testthat::expect_error( - object = net_positions( - eic = "10YCZ-CEPS-----N", + object = flow_based_allocations( + eic = "10Y1001A1001A91G", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + process_type = "A43", + security_token = .test_token ), regexp = "HTTP 503" ) @@ -1993,7 +1745,7 @@ testthat::test_that( testthat::test_that( - desc = "congestion_income() covers happy path with mock", + desc = "auction_revenue() covers happy path with mock", code = { httr2::local_mocked_responses( mock = function(req) { @@ -2011,11 +1763,12 @@ testthat::test_that( } ) testthat::expect_error( - object = congestion_income( - eic = "10YDOM-1001A083J", + object = auction_revenue( + eic_in = "10YBA-JPCC-----D", + eic_out = "10YHR-HEP------M", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -2024,10 +1777,7 @@ testthat::test_that( testthat::test_that( - desc = paste( - "allocated_transfer_capacities_3rd_countries()", - "covers happy path with mock" - ), + desc = "total_nominated_capacity() covers happy path with mock", code = { httr2::local_mocked_responses( mock = function(req) { @@ -2045,12 +1795,12 @@ testthat::test_that( } ) testthat::expect_error( - object = allocated_transfer_capacities_3rd_countries( - eic_in = "10YSK-SEPS-----K", - eic_out = "10YUA-WEPS-----0", + object = total_nominated_capacity( + eic_in = "10YDE-VE-------2", + eic_out = "10YCZ-CEPS-----N", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -2058,164 +1808,8 @@ testthat::test_that( ) -# ---- implicit_offered_transfer_capacities ---- - -testthat::test_that( - desc = "implicit_offered_transfer_capacities() validates inputs", - code = { - testthat::expect_error( - object = implicit_offered_transfer_capacities( - eic_in = NULL, - eic_out = "10YDK-1--------W", - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "Must be of type 'string', not 'NULL'" - ) - testthat::expect_error( - object = implicit_offered_transfer_capacities( - eic_in = "10Y1001A1001A82H", - eic_out = NULL, - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "Must be of type 'string', not 'NULL'" - ) - testthat::expect_error( - object = implicit_offered_transfer_capacities( - eic_in = c("10Y1001A1001A82H", "10YDK-1--------W"), - eic_out = c("10YDK-1--------W", "10Y1001A1001A82H"), - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "Must have length 1" - ) - testthat::expect_error( - object = implicit_offered_transfer_capacities( - eic_in = "10Y1001A1001A82H", - eic_out = "10YDK-1--------W", - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "" - ), - regexp = "All elements must have at least 1 characters" - ) - testthat::expect_error( - object = implicit_offered_transfer_capacities( - eic_in = "10Y1001A1001A82H", - eic_out = "10YDK-1--------W", - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-08-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "One year range limit should be applied" - ) - } -) - - -testthat::test_that( - desc = "implicit_offered_transfer_capacities() validates inputs 2", - code = { - testthat::skip_if_not( - condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, - message = "No ENTSOE_PAT environment variable set" - ) - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) - testthat::expect_error( - object = implicit_offered_transfer_capacities( - eic_in = "10Y1001A1001A82H", - eic_out = "10YDK-1--------W", - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "ABC" - ), - regexp = "Missing or invalid security token" - ) - } -) - - -testthat::test_that( - desc = "implicit_offered_transfer_capacities() works", - code = { - testthat::skip_if_not( - condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, - message = "No ENTSOE_PAT environment variable set" - ) - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) - testthat::expect_no_error( - object = implicit_offered_transfer_capacities( - eic_in = "10Y1001A1001A82H", - eic_out = "10YDK-1--------W", - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), - tidy_output = TRUE - ) - ) - } -) - - testthat::test_that( - desc = "implicit_offered_transfer_capacities() covers happy path with mock", + desc = "already_allocated_total_capacity() covers happy path with mock", code = { httr2::local_mocked_responses( mock = function(req) { @@ -2233,177 +1827,21 @@ testthat::test_that( } ) testthat::expect_error( - object = implicit_offered_transfer_capacities( - eic_in = "10Y1001A1001A82H", - eic_out = "10YDK-1--------W", - period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), - period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), - security_token = "dummy_token" - ), - regexp = "HTTP 503" - ) - } -) - - -# ---- explicit_offered_transfer_capacities ---- - -testthat::test_that( - desc = "explicit_offered_transfer_capacities() validates inputs", - code = { - testthat::expect_error( - object = explicit_offered_transfer_capacities( - eic_in = NULL, - eic_out = "10YGB----------A", - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "Must be of type 'string', not 'NULL'" - ) - testthat::expect_error( - object = explicit_offered_transfer_capacities( - eic_in = "10YBE----------2", - eic_out = NULL, - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "Must be of type 'string', not 'NULL'" - ) - testthat::expect_error( - object = explicit_offered_transfer_capacities( - eic_in = c("10YBE----------2", "10YGB----------A"), - eic_out = c("10YGB----------A", "10YBE----------2"), - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "Must have length 1" - ) - testthat::expect_error( - object = explicit_offered_transfer_capacities( - eic_in = "10YBE----------2", - eic_out = "10YGB----------A", - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "" - ), - regexp = "All elements must have at least 1 characters" - ) - testthat::expect_error( - object = explicit_offered_transfer_capacities( - eic_in = "10YBE----------2", - eic_out = "10YGB----------A", - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-08-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "One year range limit should be applied" - ) - } -) - - -testthat::test_that( - desc = "explicit_offered_transfer_capacities() validates inputs 2", - code = { - testthat::skip_if_not( - condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, - message = "No ENTSOE_PAT environment variable set" - ) - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) - testthat::expect_error( - object = explicit_offered_transfer_capacities( - eic_in = "10YBE----------2", - eic_out = "10YGB----------A", - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "ABC" - ), - regexp = "Missing or invalid security token" - ) - } -) - - -testthat::test_that( - desc = "explicit_offered_transfer_capacities() works", - code = { - testthat::skip_if_not( - condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, - message = "No ENTSOE_PAT environment variable set" - ) - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) - testthat::expect_no_error( - object = explicit_offered_transfer_capacities( - eic_in = "10YBE----------2", - eic_out = "10YGB----------A", - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), - tidy_output = TRUE - ) + object = already_allocated_total_capacity( + eic_in = "10YDE-VE-------2", + eic_out = "10YCZ-CEPS-----N", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = .test_token + ), + regexp = "HTTP 503" ) } ) testthat::test_that( - desc = "explicit_offered_transfer_capacities() covers happy path with mock", + desc = "energy_prices() covers happy path with mock", code = { httr2::local_mocked_responses( mock = function(req) { @@ -2421,177 +1859,52 @@ testthat::test_that( } ) testthat::expect_error( - object = explicit_offered_transfer_capacities( - eic_in = "10YBE----------2", - eic_out = "10YGB----------A", - period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), - period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), - security_token = "dummy_token" - ), - regexp = "HTTP 503" - ) - } -) - - -# ---- continuous_offered_transfer_capacities ---- - -testthat::test_that( - desc = "continuous_offered_transfer_capacities() validates inputs", - code = { - testthat::expect_error( - object = continuous_offered_transfer_capacities( - eic_in = NULL, - eic_out = "10YBE----------2", - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-05-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "Must be of type 'string', not 'NULL'" - ) - testthat::expect_error( - object = continuous_offered_transfer_capacities( - eic_in = "10YNL----------L", - eic_out = NULL, - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-05-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "Must be of type 'string', not 'NULL'" - ) - testthat::expect_error( - object = continuous_offered_transfer_capacities( - eic_in = c("10YNL----------L", "10YBE----------2"), - eic_out = c("10YBE----------2", "10YNL----------L"), - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-05-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "Must have length 1" - ) - testthat::expect_error( - object = continuous_offered_transfer_capacities( - eic_in = "10YNL----------L", - eic_out = "10YBE----------2", - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-05-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "" - ), - regexp = "All elements must have at least 1 characters" - ) - testthat::expect_error( - object = continuous_offered_transfer_capacities( - eic_in = "10YNL----------L", - eic_out = "10YBE----------2", - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2025-05-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" + object = energy_prices( + eic = "10YCZ-CEPS-----N", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + contract_type = "A01", + security_token = .test_token ), - regexp = "One year range limit should be applied" + regexp = "503" ) } ) testthat::test_that( - desc = "continuous_offered_transfer_capacities() validates inputs 2", + desc = "net_positions() covers happy path with mock", code = { - testthat::skip_if_not( - condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, - message = "No ENTSOE_PAT environment variable set" - ) - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } ) testthat::expect_error( - object = continuous_offered_transfer_capacities( - eic_in = "10YNL----------L", - eic_out = "10YBE----------2", - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-05-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "ABC" + object = net_positions( + eic = "10YCZ-CEPS-----N", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = .test_token ), - regexp = "Missing or invalid security token" - ) - } -) - - -testthat::test_that( - desc = "continuous_offered_transfer_capacities() works", - code = { - testthat::skip_if_not( - condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, - message = "No ENTSOE_PAT environment variable set" - ) - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) - testthat::expect_no_error( - object = continuous_offered_transfer_capacities( - eic_in = "10YNL----------L", - eic_out = "10YBE----------2", - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-05-17", - tz = "CET" - ), - tidy_output = TRUE - ) + regexp = "HTTP 503" ) } ) testthat::test_that( - desc = "continuous_offered_transfer_capacities() covers happy path with mock", + desc = "congestion_income() covers happy path with mock", code = { httr2::local_mocked_responses( mock = function(req) { @@ -2609,12 +1922,11 @@ testthat::test_that( } ) testthat::expect_error( - object = continuous_offered_transfer_capacities( - eic_in = "10YNL----------L", - eic_out = "10YBE----------2", - period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), - period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), - security_token = "dummy_token" + object = congestion_income( + eic = "10YDOM-1001A083J", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = .test_token ), regexp = "HTTP 503" ) @@ -2623,78 +1935,42 @@ testthat::test_that( testthat::test_that( - desc = "intraday_prices() validates inputs", + desc = paste( + "allocated_transfer_capacities_3rd_countries()", + "covers happy path with mock" + ), code = { - testthat::expect_error( - object = intraday_prices( - eic = NULL, - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-05-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "Must be of type 'string', not 'NULL'" - ) - testthat::expect_error( - object = intraday_prices( - eic = c("10YPL-AREA-----S", "10YCZ-CEPS-----N"), - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-05-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "Must have length 1" - ) - testthat::expect_error( - object = intraday_prices( - eic = "10YPL-AREA-----S", - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-05-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "All elements must have at least 1 characters" - ), - regexp = "" + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } ) testthat::expect_error( - object = intraday_prices( - eic = "10YPL-AREA-----S", - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2025-05-17", - tz = "CET" - ), - tidy_output = TRUE, - security_token = "dummy_token" + object = allocated_transfer_capacities_3rd_countries( + eic_in = "10YSK-SEPS-----K", + eic_out = "10YUA-WEPS-----0", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = .test_token ), - regexp = "One year range limit should be applied" + regexp = "HTTP 503" ) } ) testthat::test_that( - desc = "intraday_prices() covers happy path with mock", + desc = "implicit_offered_transfer_capacities() covers happy path with mock", code = { httr2::local_mocked_responses( mock = function(req) { @@ -2712,11 +1988,12 @@ testthat::test_that( } ) testthat::expect_error( - object = intraday_prices( - eic = "10YPL-AREA-----S", - period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), - period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), - security_token = "dummy_token" + object = implicit_offered_transfer_capacities( + eic_in = "10Y1001A1001A82H", + eic_out = "10YDK-1--------W", + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), + security_token = .test_token ), regexp = "HTTP 503" ) @@ -2725,99 +2002,39 @@ testthat::test_that( testthat::test_that( - desc = "aggregated_bids() validates inputs", + desc = "explicit_offered_transfer_capacities() covers happy path with mock", code = { - testthat::expect_error( - object = aggregated_bids( - eic = NULL, - process_type = "A51", - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-05-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "Must be of type 'string', not 'NULL'" - ) - testthat::expect_error( - object = aggregated_bids( - eic = c("10YPL-AREA-----S", "10YCZ-CEPS-----N"), - process_type = "A51", - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-05-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "Must have length 1" - ) - testthat::expect_error( - object = aggregated_bids( - eic = "10YPL-AREA-----S", - process_type = "INVALID", - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-05-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "Must be element of set" - ) - testthat::expect_error( - object = aggregated_bids( - eic = "10YPL-AREA-----S", - process_type = "A51", - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-05-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "" - ), - regexp = "All elements must have at least 1 characters" + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } ) testthat::expect_error( - object = aggregated_bids( - eic = "10YPL-AREA-----S", - process_type = "A51", - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2025-05-17", - tz = "CET" - ), - tidy_output = TRUE, - security_token = "dummy_token" + object = explicit_offered_transfer_capacities( + eic_in = "10YBE----------2", + eic_out = "10YGB----------A", + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), + security_token = .test_token ), - regexp = "One year range limit should be applied" + regexp = "HTTP 503" ) } ) testthat::test_that( - desc = "aggregated_bids() covers happy path with mock", + desc = "continuous_offered_transfer_capacities() covers happy path with mock", code = { httr2::local_mocked_responses( mock = function(req) { @@ -2835,12 +2052,12 @@ testthat::test_that( } ) testthat::expect_error( - object = aggregated_bids( - eic = "10YPL-AREA-----S", - process_type = "A51", + object = continuous_offered_transfer_capacities( + eic_in = "10YNL----------L", + eic_out = "10YBE----------2", period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) diff --git a/tests/testthat/test-en_outages.R b/tests/testthat/test-en_outages.R index 2a818d2c..538caea3 100644 --- a/tests/testthat/test-en_outages.R +++ b/tests/testthat/test-en_outages.R @@ -1,27 +1,3 @@ -testthat::test_that( - desc = "outages_both() validates inputs", - code = { - testthat::expect_error( - object = outages_both( - eic = "10YFR-RTE------C", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2025-11-24", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "One year range limit should be applied" - ) |> - testthat::expect_error() - } -) - - testthat::test_that( desc = "outages_both() works", code = { @@ -36,28 +12,16 @@ testthat::test_that( testthat::expect_no_error( object = outages_both( eic = "10YFR-RTE------C", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-24", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-24", tz = "CET"), tidy_output = FALSE ) ) testthat::expect_no_error( object = outages_both( eic = "ABCDEFGHIJKLMNOP", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-24", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-24", tz = "CET"), tidy_output = TRUE ) ) @@ -73,16 +37,10 @@ testthat::test_that( eic = "10YFR-RTE------C", doc_status = "ABC", event_nature = "A54", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-30", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be element of set" ) @@ -91,16 +49,10 @@ testthat::test_that( eic = "10YFR-RTE------C", doc_status = "A05", event_nature = "A33", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-30", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be element of set" ) @@ -109,79 +61,39 @@ testthat::test_that( eic = "10YFR-RTE------C", doc_status = "A05", event_nature = "A54", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-30", tz = "CET"), tidy_output = TRUE, security_token = "" ), - regexp = "All elements must have at least 1 characters" + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = outages_gen_units( eic = "10YFR-RTE------C", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2025-11-26", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "One year range limit should be applied" - ) - testthat::expect_error( - object = outages_gen_units( - eic = "10YFR-RTE------C", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-24", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-24", tz = "CET"), tidy_output = FALSE, security_token = "" ), - regexp = "All elements must have at least 1 characters" + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = outages_gen_units( eic = c("10YFR-RTE------C", "45Y000000000001C"), - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-24", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-24", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must have length 1" ) testthat::expect_error( object = outages_gen_units( - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-24", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-24", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be of type 'string', not 'NULL'" ) @@ -205,14 +117,8 @@ testthat::test_that( eic = "10YFR-RTE------C", doc_status = "A05", event_nature = "A54", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-30", tz = "CET"), tidy_output = TRUE ) ) @@ -221,14 +127,8 @@ testthat::test_that( eic = "10YFR-RTE------C", doc_status = "A05", event_nature = "A54", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-30", tz = "CET"), tidy_output = FALSE ) ) @@ -244,16 +144,10 @@ testthat::test_that( eic = "10YFR-RTE------C", doc_status = "ABC", event_nature = "A53", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-30", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be element of set" ) @@ -262,16 +156,10 @@ testthat::test_that( eic = "10YFR-RTE------C", doc_status = "A09", event_nature = "ABC", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-30", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be element of set" ) @@ -280,63 +168,29 @@ testthat::test_that( eic = "10YFR-RTE------C", doc_status = "A09", event_nature = "A53", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-30", tz = "CET"), tidy_output = FALSE, security_token = "" ), - regexp = "All elements must have at least 1 characters" - ) - testthat::expect_error( - object = outages_prod_units( - eic = "10YFR-RTE------C", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2025-11-26", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "One year range limit should be applied" + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = outages_prod_units( eic = c("10YFR-RTE------C", "45Y000000000001C"), - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-24", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-24", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must have length 1" ) testthat::expect_error( object = outages_prod_units( - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-24", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-24", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be of type 'string', not 'NULL'" ) @@ -358,18 +212,12 @@ testthat::test_that( testthat::expect_error( object = outages_prod_units( eic = "10YFR-RTE------C", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-24", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-24", tz = "CET"), tidy_output = FALSE, security_token = "ABC" ), - regexp = "Missing or invalid security token" + regexp = "should comply with the UUID v4 format" ) } ) @@ -391,14 +239,8 @@ testthat::test_that( eic = "10YFR-RTE------C", doc_status = "A09", event_nature = "A53", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-30", tz = "CET"), tidy_output = TRUE ) ) @@ -407,14 +249,8 @@ testthat::test_that( eic = "10YFR-RTE------C", doc_status = "A09", event_nature = "A53", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-30", tz = "CET"), tidy_output = FALSE ) ) @@ -429,16 +265,10 @@ testthat::test_that( object = outages_offshore_grid( eic = "10Y1001A1001A82H", doc_status = "ABC", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-30", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be element of set" ) @@ -446,63 +276,29 @@ testthat::test_that( object = outages_offshore_grid( eic = "10Y1001A1001A82H", doc_status = "A05", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-30", tz = "CET"), tidy_output = FALSE, security_token = "" ), - regexp = "All elements must have at least 1 characters" - ) - testthat::expect_error( - object = outages_offshore_grid( - eic = "10Y1001A1001A82H", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2025-11-26", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "One year range limit should be applied" + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = outages_offshore_grid( eic = c("10Y1001A1001A82H", "45Y000000000001C"), - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-24", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-24", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must have length 1" ) testthat::expect_error( object = outages_offshore_grid( - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-24", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-24", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be of type 'string', not 'NULL'" ) @@ -524,14 +320,8 @@ testthat::test_that( testthat::expect_error( object = outages_offshore_grid( eic = "10Y1001A1001A82H", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-24", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-24", tz = "CET"), tidy_output = FALSE, security_token = "ABC" ), @@ -556,14 +346,8 @@ testthat::test_that( object = outages_offshore_grid( eic = "10Y1001A1001A82H", doc_status = "A05", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-30", tz = "CET"), tidy_output = TRUE ) ) @@ -571,14 +355,8 @@ testthat::test_that( object = outages_offshore_grid( eic = "10Y1001A1001A82H", doc_status = "A05", - period_start = lubridate::ymd( - x = "2025-01-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2025-01-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2025-01-23", tz = "CET"), + period_end = lubridate::ymd(x = "2025-01-30", tz = "CET"), tidy_output = FALSE ) ) @@ -594,24 +372,12 @@ testthat::test_that( eic = "10YFI-1--------U", doc_status = "ABC", event_nature = "A53", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), - period_start_update = lubridate::ymd( - x = "2024-10-15", - tz = "CET" - ), - period_end_update = lubridate::ymd( - x = "2024-10-22", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-30", tz = "CET"), + period_start_update = lubridate::ymd(x = "2024-10-15", tz = "CET"), + period_end_update = lubridate::ymd(x = "2024-10-22", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be element of set" ) @@ -620,24 +386,12 @@ testthat::test_that( eic = "10YFI-1--------U", doc_status = "A09", event_nature = "ABC", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), - period_start_update = lubridate::ymd( - x = "2024-10-15", - tz = "CET" - ), - period_end_update = lubridate::ymd( - x = "2024-10-22", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-30", tz = "CET"), + period_start_update = lubridate::ymd(x = "2024-10-15", tz = "CET"), + period_end_update = lubridate::ymd(x = "2024-10-22", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be element of set" ) @@ -646,95 +400,35 @@ testthat::test_that( eic = "10YFI-1--------U", doc_status = "A09", event_nature = "A53", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), - period_start_update = lubridate::ymd( - x = "2024-10-15", - tz = "CET" - ), - period_end_update = lubridate::ymd( - x = "2024-10-22", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-30", tz = "CET"), + period_start_update = lubridate::ymd(x = "2024-10-15", tz = "CET"), + period_end_update = lubridate::ymd(x = "2024-10-22", tz = "CET"), tidy_output = FALSE, security_token = "" ), - regexp = "All elements must have at least 1 characters" - ) - testthat::expect_error( - object = outages_cons_units( - eic = "10YFI-1--------U", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2025-11-26", - tz = "CET" - ), - period_start_update = lubridate::ymd( - x = "2024-10-15", - tz = "CET" - ), - period_end_update = lubridate::ymd( - x = "2024-10-22", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "One year range limit should be applied" + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = outages_cons_units( eic = c("10YFI-1--------U", "45Y000000000001C"), - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-24", - tz = "CET" - ), - period_start_update = lubridate::ymd( - x = "2024-10-15", - tz = "CET" - ), - period_end_update = lubridate::ymd( - x = "2024-10-22", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-24", tz = "CET"), + period_start_update = lubridate::ymd(x = "2024-10-15", tz = "CET"), + period_end_update = lubridate::ymd(x = "2024-10-22", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must have length 1" ) testthat::expect_error( object = outages_cons_units( - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-24", - tz = "CET" - ), - period_start_update = lubridate::ymd( - x = "2024-10-15", - tz = "CET" - ), - period_end_update = lubridate::ymd( - x = "2024-10-22", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-24", tz = "CET"), + period_start_update = lubridate::ymd(x = "2024-10-15", tz = "CET"), + period_end_update = lubridate::ymd(x = "2024-10-22", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be of type 'string', not 'NULL'" ) @@ -756,26 +450,14 @@ testthat::test_that( testthat::expect_error( object = outages_cons_units( eic = "10YFI-1--------U", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-24", - tz = "CET" - ), - period_start_update = lubridate::ymd( - x = "2024-10-15", - tz = "CET" - ), - period_end_update = lubridate::ymd( - x = "2024-10-22", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-24", tz = "CET"), + period_start_update = lubridate::ymd(x = "2024-10-15", tz = "CET"), + period_end_update = lubridate::ymd(x = "2024-10-22", tz = "CET"), tidy_output = FALSE, security_token = "ABC" ), - regexp = "Missing or invalid security token" + regexp = "should comply with the UUID v4 format" ) } ) @@ -797,22 +479,10 @@ testthat::test_that( eic = "10YFI-1--------U", doc_status = "A09", event_nature = "A53", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), - period_start_update = lubridate::ymd( - x = "2024-10-15", - tz = "CET" - ), - period_end_update = lubridate::ymd( - x = "2024-10-22", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-30", tz = "CET"), + period_start_update = lubridate::ymd(x = "2024-10-15", tz = "CET"), + period_end_update = lubridate::ymd(x = "2024-10-22", tz = "CET"), tidy_output = TRUE ) ) @@ -821,22 +491,10 @@ testthat::test_that( eic = "10YFI-1--------U", doc_status = "A09", event_nature = "A53", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), - period_start_update = lubridate::ymd( - x = "2024-10-15", - tz = "CET" - ), - period_end_update = lubridate::ymd( - x = "2024-10-22", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-30", tz = "CET"), + period_start_update = lubridate::ymd(x = "2024-10-15", tz = "CET"), + period_end_update = lubridate::ymd(x = "2024-10-22", tz = "CET"), tidy_output = FALSE ) ) @@ -853,24 +511,12 @@ testthat::test_that( eic_out = "10Y1001A1001A82H", doc_status = "ABC", event_nature = "A53", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), - period_start_update = lubridate::ymd( - x = "2024-10-15", - tz = "CET" - ), - period_end_update = lubridate::ymd( - x = "2024-10-22", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-30", tz = "CET"), + period_start_update = lubridate::ymd(x = "2024-10-15", tz = "CET"), + period_end_update = lubridate::ymd(x = "2024-10-22", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be element of set" ) @@ -880,24 +526,12 @@ testthat::test_that( eic_out = "10Y1001A1001A82H", doc_status = "A09", event_nature = "ABC", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), - period_start_update = lubridate::ymd( - x = "2024-10-15", - tz = "CET" - ), - period_end_update = lubridate::ymd( - x = "2024-10-22", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-30", tz = "CET"), + period_start_update = lubridate::ymd(x = "2024-10-15", tz = "CET"), + period_end_update = lubridate::ymd(x = "2024-10-22", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be element of set" ) @@ -907,24 +541,12 @@ testthat::test_that( eic_out = NULL, doc_status = "A09", event_nature = "A53", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), - period_start_update = lubridate::ymd( - x = "2024-10-15", - tz = "CET" - ), - period_end_update = lubridate::ymd( - x = "2024-10-22", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-30", tz = "CET"), + period_start_update = lubridate::ymd(x = "2024-10-15", tz = "CET"), + period_end_update = lubridate::ymd(x = "2024-10-22", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be of type 'string', not 'NULL'" ) @@ -934,24 +556,12 @@ testthat::test_that( eic_out = "10Y1001A1001A82H", doc_status = "A09", event_nature = "A53", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), - period_start_update = lubridate::ymd( - x = "2024-10-15", - tz = "CET" - ), - period_end_update = lubridate::ymd( - x = "2024-10-22", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-30", tz = "CET"), + period_start_update = lubridate::ymd(x = "2024-10-15", tz = "CET"), + period_end_update = lubridate::ymd(x = "2024-10-22", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be of type 'string', not 'NULL'" ) @@ -961,74 +571,25 @@ testthat::test_that( eic_out = "10Y1001A1001A82H", doc_status = "A09", event_nature = "A53", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), - period_start_update = lubridate::ymd( - x = "2024-10-15", - tz = "CET" - ), - period_end_update = lubridate::ymd( - x = "2024-10-22", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-30", tz = "CET"), + period_start_update = lubridate::ymd(x = "2024-10-15", tz = "CET"), + period_end_update = lubridate::ymd(x = "2024-10-22", tz = "CET"), tidy_output = FALSE, security_token = "" ), - regexp = "All elements must have at least 1 characters" - ) - testthat::expect_error( - object = outages_transmission_grid( - eic_in = "10YFR-RTE------C", - eic_out = "10Y1001A1001A82H", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2025-11-26", - tz = "CET" - ), - period_start_update = lubridate::ymd( - x = "2024-10-15", - tz = "CET" - ), - period_end_update = lubridate::ymd( - x = "2024-10-22", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "One year range limit should be applied" + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = outages_transmission_grid( eic_in = c("10YFR-RTE------C", "45Y000000000001C"), eic_out = c("10Y1001A1001A82H"), - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-24", - tz = "CET" - ), - period_start_update = lubridate::ymd( - x = "2024-10-15", - tz = "CET" - ), - period_end_update = lubridate::ymd( - x = "2024-10-22", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-24", tz = "CET"), + period_start_update = lubridate::ymd(x = "2024-10-15", tz = "CET"), + period_end_update = lubridate::ymd(x = "2024-10-22", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must have length 1" ) @@ -1036,47 +597,23 @@ testthat::test_that( object = outages_transmission_grid( eic_in = c("10Y1001A1001A82H"), eic_out = c("10YFR-RTE------C", "45Y000000000001C"), - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-24", - tz = "CET" - ), - period_start_update = lubridate::ymd( - x = "2024-10-15", - tz = "CET" - ), - period_end_update = lubridate::ymd( - x = "2024-10-22", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-24", tz = "CET"), + period_start_update = lubridate::ymd(x = "2024-10-15", tz = "CET"), + period_end_update = lubridate::ymd(x = "2024-10-22", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must have length 1" ) testthat::expect_error( object = outages_transmission_grid( - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-24", - tz = "CET" - ), - period_start_update = lubridate::ymd( - x = "2024-10-15", - tz = "CET" - ), - period_end_update = lubridate::ymd( - x = "2024-10-22", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-24", tz = "CET"), + period_start_update = lubridate::ymd(x = "2024-10-15", tz = "CET"), + period_end_update = lubridate::ymd(x = "2024-10-22", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be of type 'string', not 'NULL'" ) @@ -1099,32 +636,19 @@ testthat::test_that( object = outages_transmission_grid( eic_in = "10YFR-RTE------C", eic_out = "10Y1001A1001A82H", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-24", - tz = "CET" - ), - period_start_update = lubridate::ymd( - x = "2024-10-15", - tz = "CET" - ), - period_end_update = lubridate::ymd( - x = "2024-10-22", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-24", tz = "CET"), + period_start_update = lubridate::ymd(x = "2024-10-15", tz = "CET"), + period_end_update = lubridate::ymd(x = "2024-10-22", tz = "CET"), tidy_output = FALSE, security_token = "ABC" ), - regexp = "Missing or invalid security token" + regexp = "should comply with the UUID v4 format" ) } ) - testthat::test_that( desc = "outages_transmission_grid() works", code = { @@ -1142,22 +666,10 @@ testthat::test_that( eic_out = "10Y1001A1001A82H", doc_status = "A09", event_nature = "A53", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), - period_start_update = lubridate::ymd( - x = "2024-10-15", - tz = "CET" - ), - period_end_update = lubridate::ymd( - x = "2024-10-22", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-30", tz = "CET"), + period_start_update = lubridate::ymd(x = "2024-10-15", tz = "CET"), + period_end_update = lubridate::ymd(x = "2024-10-22", tz = "CET"), tidy_output = FALSE ) ) @@ -1173,34 +685,22 @@ testthat::test_that( eic = "10YBE----------2", process_type = "A63", event_nature = "C47", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-30", tz = "CET"), tidy_output = FALSE, security_token = "" ), - regexp = "All elements must have at least 1 characters" + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = outages_fallbacks( eic = "10YBE----------2", process_type = "A01", event_nature = "C47", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-30", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be element of set" ) @@ -1209,63 +709,29 @@ testthat::test_that( eic = "10YBE----------2", process_type = "A63", event_nature = "C01", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-30", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be element of set" ) - testthat::expect_error( - object = outages_fallbacks( - eic = "10YBE----------2", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2025-11-26", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "One year range limit should be applied" - ) testthat::expect_error( object = outages_fallbacks( eic = c("10YBE----------2", "45Y000000000001C"), - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-24", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-24", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must have length 1" ) testthat::expect_error( object = outages_fallbacks( - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-24", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-24", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Must be of type 'string', not 'NULL'" ) @@ -1287,18 +753,12 @@ testthat::test_that( testthat::expect_error( object = outages_fallbacks( eic = "10YBE----------2", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-24", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-24", tz = "CET"), tidy_output = FALSE, security_token = "ABC" ), - regexp = "Missing or invalid security token" + regexp = "should comply with the UUID v4 format" ) } ) @@ -1320,14 +780,8 @@ testthat::test_that( eic = "10YBE----------2", process_type = "A63", event_nature = "C47", - period_start = lubridate::ymd( - x = "2024-10-23", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-10-30", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-10-23", tz = "CET"), + period_end = lubridate::ymd(x = "2024-10-30", tz = "CET"), tidy_output = FALSE ) ) @@ -1336,7 +790,7 @@ testthat::test_that( testthat::test_that( - desc = "outages_gen_units() covers happy path with mock", + desc = "outages_both() covers happy path with mock", code = { httr2::local_mocked_responses( mock = function(req) { @@ -1353,21 +807,20 @@ testthat::test_that( ) } ) - testthat::expect_error( - object = outages_gen_units( + testthat::expect_no_error( + object = outages_both( eic = "10YFR-RTE------C", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" - ), - regexp = "HTTP 503" + security_token = .test_token + ) ) } ) testthat::test_that( - desc = "outages_prod_units() covers happy path with mock", + desc = "outages_gen_units() covers happy path with mock", code = { httr2::local_mocked_responses( mock = function(req) { @@ -1385,11 +838,11 @@ testthat::test_that( } ) testthat::expect_error( - object = outages_prod_units( + object = outages_gen_units( eic = "10YFR-RTE------C", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -1398,7 +851,7 @@ testthat::test_that( testthat::test_that( - desc = "outages_both() covers happy path with mock", + desc = "outages_prod_units() covers happy path with mock", code = { httr2::local_mocked_responses( mock = function(req) { @@ -1415,13 +868,14 @@ testthat::test_that( ) } ) - testthat::expect_no_error( - object = outages_both( + testthat::expect_error( + object = outages_prod_units( eic = "10YFR-RTE------C", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "HTTP 503" ) } ) @@ -1450,7 +904,7 @@ testthat::test_that( eic = "10Y1001A1001A82H", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -1481,7 +935,9 @@ testthat::test_that( eic = "10YFI-1--------U", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + period_start_update = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end_update = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = .test_token ), regexp = "HTTP 503" ) @@ -1513,7 +969,9 @@ testthat::test_that( eic_out = "10Y1001A1001A82H", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + period_start_update = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end_update = lubridate::ymd(x = "2024-01-02", tz = "CET"), + security_token = .test_token ), regexp = "HTTP 503" ) @@ -1544,7 +1002,7 @@ testthat::test_that( eic = "10YBE----------2", period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) diff --git a/tests/testthat/test-en_transmission.R b/tests/testthat/test-en_transmission.R index 145e06c7..b4dbfd07 100644 --- a/tests/testthat/test-en_transmission.R +++ b/tests/testthat/test-en_transmission.R @@ -5,48 +5,30 @@ testthat::test_that( object = cross_border_physical_flows( eic_in = c("10Y1001A1001A83F", "10YCZ-CEPS-----N"), eic_out = c("10YCZ-CEPS-----N", "10Y1001A1001A83F"), - period_start = lubridate::ymd( - x = "2020-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-01-02", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Assertion on 'eic_in' failed: Must have length 1" ) testthat::expect_error( object = cross_border_physical_flows( eic_in = "10Y1001A1001A83F", - period_start = lubridate::ymd( - x = "2020-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-01-02", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Assertion on 'eic_out' failed: Must be of type 'string'" ) testthat::expect_error( object = cross_border_physical_flows( eic_out = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2020-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-01-02", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token ), regexp = "Assertion on 'eic_in' failed: Must be of type 'string'" ) @@ -54,51 +36,23 @@ testthat::test_that( object = cross_border_physical_flows( eic_in = "10Y1001A1001A83F", eic_out = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2020-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-01-02", tz = "CET"), tidy_output = FALSE, - security_token = "Assertion on 'security_token' failed" + security_token = "ABC" ), - regexp = "" + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = cross_border_physical_flows( eic_in = "10Y1001A1001A83F", eic_out = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2020-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-01-02", tz = "CET"), tidy_output = FALSE, security_token = "ABC" - ) - ) - testthat::expect_error( - object = cross_border_physical_flows( - eic_in = "10Y1001A1001A83F", - eic_out = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2020-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2021-01-02", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" ), - regexp = "One year range limit should be applied" + regexp = "should comply with the UUID v4 format" ) } ) @@ -119,14 +73,8 @@ testthat::test_that( object = cross_border_physical_flows( eic_in = "10Y1001A1001A83F", eic_out = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2020-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-01-02", tz = "CET"), tidy_output = FALSE ) ) @@ -140,96 +88,61 @@ testthat::test_that( testthat::expect_error( object = day_ahead_commercial_sched( eic_out = "10YSK-SEPS-----K", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-12-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-12-01", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token + ), + regexp = paste( + "Assertion on 'eic_in' failed:", + "Must be of type 'string', not 'NULL'" ) ) testthat::expect_error( object = day_ahead_commercial_sched( eic_in = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-12-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-12-01", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token + ), + regexp = paste( + "Assertion on 'eic_out' failed:", + "Must be of type 'string', not 'NULL'" ) ) testthat::expect_error( object = day_ahead_commercial_sched( eic_in = c("10YCZ-CEPS-----N", "10YSK-SEPS-----K"), eic_out = c("10YSK-SEPS-----K", "10YCZ-CEPS-----N"), - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-12-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-12-01", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" - ) - ) - testthat::expect_error( - object = day_ahead_commercial_sched( - eic_in = "10YCZ-CEPS-----N", - eic_out = "10YSK-SEPS-----K", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-12-01", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic_in' failed: Must have length 1" ) testthat::expect_error( object = day_ahead_commercial_sched( eic_in = "10YCZ-CEPS-----N", eic_out = "10YSK-SEPS-----K", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-12-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-12-01", tz = "CET"), tidy_output = FALSE, security_token = "ABC" - ) + ), + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = day_ahead_commercial_sched( eic_in = "10YCZ-CEPS-----N", eic_out = "10YSK-SEPS-----K", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-12-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-12-01", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "1 year range limit should be applied" ) } ) @@ -250,14 +163,8 @@ testthat::test_that( object = day_ahead_commercial_sched( eic_in = "10YCZ-CEPS-----N", eic_out = "10YSK-SEPS-----K", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-12-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-12-01", tz = "CET"), tidy_output = FALSE ) ) @@ -271,96 +178,61 @@ testthat::test_that( testthat::expect_error( object = total_commercial_sched( eic_in = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-12-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-12-01", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token + ), + regexp = paste( + "Assertion on 'eic_out' failed:", + "Must be of type 'string', not 'NULL'" ) ) testthat::expect_error( object = total_commercial_sched( eic_out = "10YSK-SEPS-----K", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-12-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-12-01", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token + ), + regexp = paste( + "Assertion on 'eic_in' failed:", + "Must be of type 'string', not 'NULL'" ) ) testthat::expect_error( object = total_commercial_sched( eic_in = c("10YCZ-CEPS-----N", "10YSK-SEPS-----K"), eic_out = c("10YSK-SEPS-----K", "10YCZ-CEPS-----N"), - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-12-01", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ) - ) - testthat::expect_error( - object = total_commercial_sched( - eic_in = "10YCZ-CEPS-----N", - eic_out = "10YSK-SEPS-----K", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-12-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-12-01", tz = "CET"), tidy_output = FALSE, - security_token = "" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic_in' failed: Must have length 1" ) testthat::expect_error( object = total_commercial_sched( eic_in = "10YCZ-CEPS-----N", eic_out = "10YSK-SEPS-----K", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-12-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-12-01", tz = "CET"), tidy_output = FALSE, security_token = "ABC" - ) + ), + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = total_commercial_sched( eic_in = "10YCZ-CEPS-----N", eic_out = "10YSK-SEPS-----K", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-12-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-12-01", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "1 year range limit should be applied" ) } ) @@ -381,14 +253,8 @@ testthat::test_that( object = total_commercial_sched( eic_in = "10YCZ-CEPS-----N", eic_out = "10YSK-SEPS-----K", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-12-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-12-01", tz = "CET"), tidy_output = FALSE ) ) @@ -402,96 +268,61 @@ testthat::test_that( testthat::expect_error( object = forecasted_transfer_capacities( eic_in = "10YCZ-CEPS-----N", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-12-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-12-01", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token + ), + regexp = paste( + "Assertion on 'eic_out' failed:", + "Must be of type 'string', not 'NULL'" ) ) testthat::expect_error( object = forecasted_transfer_capacities( eic_out = "10YSK-SEPS-----K", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-12-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-12-01", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token + ), + regexp = paste( + "Assertion on 'eic_in' failed:", + "Must be of type 'string', not 'NULL'" ) ) testthat::expect_error( object = forecasted_transfer_capacities( eic_in = c("10YCZ-CEPS-----N", "10YSK-SEPS-----K"), eic_out = c("10YSK-SEPS-----K", "10YCZ-CEPS-----N"), - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-12-01", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ) - ) - testthat::expect_error( - object = forecasted_transfer_capacities( - eic_in = "10YCZ-CEPS-----N", - eic_out = "10YSK-SEPS-----K", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-12-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-12-01", tz = "CET"), tidy_output = FALSE, - security_token = "" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic_in' failed: Must have length 1" ) testthat::expect_error( object = forecasted_transfer_capacities( eic_in = "10YCZ-CEPS-----N", eic_out = "10YSK-SEPS-----K", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-12-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-12-01", tz = "CET"), tidy_output = FALSE, security_token = "ABC" - ) + ), + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = forecasted_transfer_capacities( eic_in = "10YCZ-CEPS-----N", eic_out = "10YSK-SEPS-----K", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-12-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-12-01", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "1 year range limit should be applied" ) } ) @@ -512,14 +343,8 @@ testthat::test_that( object = forecasted_transfer_capacities( eic_in = "10YCZ-CEPS-----N", eic_out = "10YSK-SEPS-----K", - period_start = lubridate::ymd( - x = "2019-11-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2019-12-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2019-11-01", tz = "CET"), + period_end = lubridate::ymd(x = "2019-12-01", tz = "CET"), tidy_output = FALSE ) ) @@ -530,101 +355,66 @@ testthat::test_that( testthat::test_that( desc = "redispatching_cross_border() validates inputs", code = { - testthat::expect_error( - object = redispatching_cross_border( - eic_in = "10YDE-VE-------2", - eic_out = "10YDE-EON------1", - period_start = lubridate::ymd( - x = "2023-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2025-01-01", - tz = "CET" - ), - tidy_output = TRUE, - security_token = "dummy_token" - ) - ) testthat::expect_error( object = redispatching_cross_border( eic_in = NULL, eic_out = "10YDE-EON------1", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token + ), + regexp = paste( + "Assertion on 'eic_in' failed:", + "Must be of type 'string', not 'NULL'" ) ) testthat::expect_error( object = redispatching_cross_border( eic_in = "10YDE-VE-------2", eic_out = NULL, - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token + ), + regexp = paste( + "Assertion on 'eic_out' failed:", + "Must be of type 'string', not 'NULL'" ) ) testthat::expect_error( object = redispatching_cross_border( eic_in = c("10YNL----------L", "10YNO-0--------C"), eic_out = "10YDE-VE-------2", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic_in' failed: Must have length 1" ) testthat::expect_error( object = redispatching_cross_border( eic_in = "10YDE-VE-------2", eic_out = c("10YNL----------L", "10YNO-0--------C"), - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic_out' failed: Must have length 1" ) testthat::expect_error( object = redispatching_cross_border( eic_in = "10YDE-VE-------2", eic_out = "10YDE-EON------1", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "" - ) + security_token = "ABC" + ), + regexp = "should comply with the UUID v4 format" ) } ) @@ -645,14 +435,8 @@ testthat::test_that( object = redispatching_cross_border( eic_in = "10YDE-VE-------2", eic_out = "10YDE-EON------1", - period_start = lubridate::ymd( - x = "2024-03-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-03-11", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-03-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-03-11", tz = "CET"), tidy_output = TRUE ) ) @@ -660,14 +444,8 @@ testthat::test_that( object = redispatching_cross_border( eic_in = "10YNL----------L", eic_out = "10YNO-0--------C", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE ) ) @@ -678,65 +456,35 @@ testthat::test_that( testthat::test_that( desc = "redispatching_internal() validates inputs", code = { - testthat::expect_error( - object = redispatching_internal( - eic = "10YNO-0--------C", - period_start = lubridate::ymd( - x = "2023-05-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-04-01", - tz = "CET" - ), - tidy_output = TRUE, - security_token = "dummy_token" - ) - ) testthat::expect_error( object = redispatching_internal( eic = NULL, - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = redispatching_internal( eic = c("10YNL----------L", "10YNO-0--------C"), - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = redispatching_internal( eic = "10YNO-0--------C", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "" - ) + security_token = "ABC" + ), + regexp = "should comply with the UUID v4 format" ) } ) @@ -756,14 +504,8 @@ testthat::test_that( testthat::expect_no_error( object = redispatching_internal( eic = "10YNO-0--------C", - period_start = lubridate::ymd( - x = "2024-03-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-03-11", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-03-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-03-11", tz = "CET"), tidy_output = TRUE ) ) @@ -774,101 +516,66 @@ testthat::test_that( testthat::test_that( desc = "countertrading() validates inputs", code = { - testthat::expect_error( - object = countertrading( - eic_in = "10YFR-RTE------C", - eic_out = "10YES-REE------0", - period_start = lubridate::ymd( - x = "2024-03-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-08-01", - tz = "CET" - ), - tidy_output = TRUE, - security_token = "dummy_token" - ) - ) testthat::expect_error( object = countertrading( eic_in = NULL, eic_out = "10YDE-EON------1", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token + ), + regexp = paste( + "Assertion on 'eic_in' failed:", + "Must be of type 'string', not 'NULL'" ) ) testthat::expect_error( object = countertrading( eic_in = "10YDE-VE-------2", eic_out = NULL, - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" + security_token = .test_token + ), + regexp = paste( + "Assertion on 'eic_out' failed:", + "Must be of type 'string', not 'NULL'" ) ) testthat::expect_error( object = countertrading( eic_in = c("10YNL----------L", "10YNO-0--------C"), eic_out = "10YDE-VE-------2", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic_in' failed: Must have length 1" ) testthat::expect_error( object = countertrading( eic_in = "10YDE-VE-------2", eic_out = c("10YNL----------L", "10YNO-0--------C"), - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic_out' failed: Must have length 1" ) testthat::expect_error( object = countertrading( eic_in = "10YDE-VE-------2", eic_out = "10YDE-EON------1", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "" - ) + security_token = "ABC" + ), + regexp = "should comply with the UUID v4 format" ) } ) @@ -889,14 +596,8 @@ testthat::test_that( object = countertrading( eic_in = "10YFR-RTE------C", eic_out = "10YES-REE------0", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-02-15", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-02-15", tz = "CET"), tidy_output = TRUE ) ) @@ -914,53 +615,39 @@ testthat::test_that( period_end = lubridate::ymd(x = "2017-01-01", tz = "CET"), event_nature = "B99", tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Must be element of set" ) testthat::expect_error( object = costs_of_congestion_management( eic = NULL, - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = costs_of_congestion_management( eic = c("10YNL----------L", "10YNO-0--------C"), - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = costs_of_congestion_management( eic = "10YNO-0--------C", - period_start = lubridate::ymd( - x = "2020-02-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2020-03-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), + period_end = lubridate::ymd(x = "2020-03-01", tz = "CET"), tidy_output = TRUE, - security_token = "" - ) + security_token = "ABC" + ), + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = costs_of_congestion_management( @@ -968,8 +655,9 @@ testthat::test_that( period_start = lubridate::ymd(x = "2016-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2020-01-01", tz = "CET"), tidy_output = TRUE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "1 year range limit should be applied" ) } ) @@ -988,46 +676,34 @@ testthat::test_that( ) testthat::expect_no_error( object = costs_of_congestion_management( - eic = "10YBE----------2", + eic = "10YBE----------2", period_start = lubridate::ymd(x = "2016-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2016-12-31", tz = "CET"), - tidy_output = TRUE + period_end = lubridate::ymd(x = "2016-12-31", tz = "CET"), + tidy_output = TRUE ) ) testthat::expect_no_error( object = costs_of_congestion_management( - eic = "10YBE----------2", + eic = "10YBE----------2", period_start = lubridate::ymd(x = "2016-01-01", tz = "CET"), - period_end = lubridate::ymd(x = "2016-12-31", tz = "CET"), + period_end = lubridate::ymd(x = "2016-12-31", tz = "CET"), event_nature = "A46", - tidy_output = TRUE + tidy_output = TRUE ) ) testthat::expect_no_error( object = costs_of_congestion_management( eic = "10YNO-0--------C", - period_start = lubridate::ymd( - x = "2024-03-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-04-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-03-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-04-01", tz = "CET"), tidy_output = TRUE ) ) testthat::expect_no_error( object = costs_of_congestion_management( eic = "10YNO-0--------C", - period_start = lubridate::ymd( - x = "2024-03-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-04-01", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2024-03-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-04-01", tz = "CET"), tidy_output = TRUE ) ) @@ -1042,109 +718,85 @@ testthat::test_that( object = expansion_and_dismantling_project( eic_in = NULL, eic_out = "10YHU-MAVIR----U", - period_start = lubridate::ymd( - x = "2023-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2023-01-02", tz = "CET"), business_type = "B01", doc_status = "A05", tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token + ), + regexp = paste( + "Assertion on 'eic_in' failed:", + "Must be of type 'string', not 'NULL'" ) ) testthat::expect_error( object = expansion_and_dismantling_project( eic_in = "10YSK-SEPS-----K", eic_out = NULL, - period_start = lubridate::ymd( - x = "2023-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2023-01-02", tz = "CET"), business_type = "B01", doc_status = "A05", tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token + ), + regexp = paste( + "Assertion on 'eic_out' failed:", + "Must be of type 'string', not 'NULL'" ) ) testthat::expect_error( object = expansion_and_dismantling_project( eic_in = c("10YSK-SEPS-----K", "10YHU-MAVIR----U"), eic_out = c("10YHU-MAVIR----U", "10YSK-SEPS-----K"), - period_start = lubridate::ymd( - x = "2023-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2023-01-02", tz = "CET"), business_type = "B01", doc_status = "A05", tidy_output = FALSE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic_in' failed: Must have length 1" ) testthat::expect_error( object = expansion_and_dismantling_project( eic_in = "10YSK-SEPS-----K", eic_out = "10YHU-MAVIR----U", - period_start = lubridate::ymd( - x = "2023-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2023-01-02", tz = "CET"), business_type = "B01", doc_status = "A05", tidy_output = FALSE, - security_token = "" - ) + security_token = "ABC" + ), + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = expansion_and_dismantling_project( eic_in = "10YSK-SEPS-----K", eic_out = "10YHU-MAVIR----U", - period_start = lubridate::ymd( - x = "2023-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2023-01-02", tz = "CET"), business_type = "B99", doc_status = "A05", tidy_output = FALSE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Must be element of set" ) testthat::expect_error( object = expansion_and_dismantling_project( eic_in = "10YSK-SEPS-----K", eic_out = "10YHU-MAVIR----U", - period_start = lubridate::ymd( - x = "2023-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2023-01-02", tz = "CET"), business_type = "B01", doc_status = "X99", tidy_output = FALSE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "Must be element of set" ) } ) @@ -1165,14 +817,8 @@ testthat::test_that( object = expansion_and_dismantling_project( eic_in = "10YSK-SEPS-----K", eic_out = "10YHU-MAVIR----U", - period_start = lubridate::ymd( - x = "2023-01-01", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-01-02", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2023-01-02", tz = "CET"), business_type = "B01", doc_status = "A05", tidy_output = FALSE @@ -1189,97 +835,62 @@ testthat::test_that( object = intraday_cross_border_transfer_limits( eic_in = NULL, eic_out = "11Y0-0000-0265-K", - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token + ), + regexp = paste( + "Assertion on 'eic_in' failed:", + "Must be of type 'string', not 'NULL'" ) ) testthat::expect_error( object = intraday_cross_border_transfer_limits( eic_in = "10YFR-RTE------C", eic_out = NULL, - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" + security_token = .test_token + ), + regexp = paste( + "Assertion on 'eic_out' failed:", + "Must be of type 'string', not 'NULL'" ) ) testthat::expect_error( object = intraday_cross_border_transfer_limits( eic_in = c("10YFR-RTE------C", "11Y0-0000-0265-K"), eic_out = c("11Y0-0000-0265-K", "10YFR-RTE------C"), - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" - ) - ) - testthat::expect_error( - object = intraday_cross_border_transfer_limits( - eic_in = "10YFR-RTE------C", - eic_out = "11Y0-0000-0265-K", - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "" - ) + security_token = .test_token + ), + regexp = "Assertion on 'eic_in' failed: Must have length 1" ) testthat::expect_error( object = intraday_cross_border_transfer_limits( eic_in = "10YFR-RTE------C", eic_out = "11Y0-0000-0265-K", - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), tidy_output = FALSE, security_token = "ABC" - ) + ), + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( object = intraday_cross_border_transfer_limits( eic_in = "10YFR-RTE------C", eic_out = "11Y0-0000-0265-K", - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-08-17", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2024-08-17", tz = "CET"), tidy_output = FALSE, - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "1 year range limit should be applied" ) } ) @@ -1300,14 +911,8 @@ testthat::test_that( object = intraday_cross_border_transfer_limits( eic_in = "10YFR-RTE------C", eic_out = "11Y0-0000-0265-K", - period_start = lubridate::ymd( - x = "2023-08-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2023-08-17", - tz = "CET" - ), + period_start = lubridate::ymd(x = "2023-08-16", tz = "CET"), + period_end = lubridate::ymd(x = "2023-08-17", tz = "CET"), tidy_output = FALSE ) ) @@ -1315,6 +920,100 @@ testthat::test_that( ) +testthat::test_that( + desc = "net_transfer_capacities() validates inputs", + code = { + testthat::expect_error( + object = net_transfer_capacities( + eic_in = c("10YNL----------L", "10YBE----------2"), + eic_out = c("10YBE----------2", "10YNL----------L"), + period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), + period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), + tidy_output = FALSE, + security_token = .test_token + ), + regexp = "Assertion on 'eic_in' failed: Must have length 1" + ) + testthat::expect_error( + object = net_transfer_capacities( + eic_in = "10YNL----------L", + period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), + period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), + tidy_output = FALSE, + security_token = .test_token + ), + regexp = "Assertion on 'eic_out' failed: Must be of type 'string'" + ) + testthat::expect_error( + object = net_transfer_capacities( + eic_out = "10YBE----------2", + period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), + period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), + tidy_output = FALSE, + security_token = .test_token + ), + regexp = "Assertion on 'eic_in' failed: Must be of type 'string'" + ) + testthat::expect_error( + object = net_transfer_capacities( + eic_in = "10YNL----------L", + eic_out = "10YBE----------2", + contract_type = "INVALID", + period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), + period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), + tidy_output = FALSE, + security_token = .test_token + ), + regexp = "Must be element of set" + ) + testthat::expect_error( + object = net_transfer_capacities( + eic_in = "10YNL----------L", + eic_out = "10YBE----------2", + period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), + period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), + tidy_output = FALSE, + security_token = "ABC" + ), + regexp = "should comply with the UUID v4 format" + ) + } +) + + +testthat::test_that( + desc = "net_transfer_capacities() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = net_transfer_capacities( + eic_in = "10YNL----------L", + eic_out = "10YBE----------2", + period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), + period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), + tidy_output = FALSE, + security_token = .test_token + ), + regexp = "HTTP 503" + ) + } +) + + testthat::test_that( desc = "expansion_and_dismantling_project() covers happy path with mock", code = { @@ -1341,7 +1040,7 @@ testthat::test_that( period_end = lubridate::ymd("2020-01-02", tz = "CET"), business_type = "B01", doc_status = "A01", - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -1373,7 +1072,7 @@ testthat::test_that( eic_out = "10YDE-VE-------2", period_start = lubridate::ymd("2020-01-01", tz = "CET"), period_end = lubridate::ymd("2020-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -1405,7 +1104,7 @@ testthat::test_that( eic_out = "10YDE-VE-------2", period_start = lubridate::ymd("2020-01-01", tz = "CET"), period_end = lubridate::ymd("2020-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -1437,7 +1136,7 @@ testthat::test_that( eic_out = "10YDE-VE-------2", period_start = lubridate::ymd("2020-01-01", tz = "CET"), period_end = lubridate::ymd("2020-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -1469,7 +1168,7 @@ testthat::test_that( eic_out = "10YDE-VE-------2", period_start = lubridate::ymd("2020-01-01", tz = "CET"), period_end = lubridate::ymd("2020-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -1501,7 +1200,7 @@ testthat::test_that( eic_out = "10YDE-VE-------2", period_start = lubridate::ymd("2020-01-01", tz = "CET"), period_end = lubridate::ymd("2020-01-02", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -1533,7 +1232,7 @@ testthat::test_that( eic_out = "10YDE-VE-------2", period_start = lubridate::ymd("2020-01-01", tz = "CET"), period_end = lubridate::ymd("2020-01-01", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -1564,7 +1263,7 @@ testthat::test_that( eic = "10YFR-RTE------C", period_start = lubridate::ymd("2020-01-01", tz = "CET"), period_end = lubridate::ymd("2020-01-01", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -1596,7 +1295,7 @@ testthat::test_that( eic_out = "10YDE-VE-------2", period_start = lubridate::ymd("2020-01-01", tz = "CET"), period_end = lubridate::ymd("2020-01-01", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) @@ -1627,162 +1326,7 @@ testthat::test_that( eic = "10YFR-RTE------C", period_start = lubridate::ymd("2020-01-01", tz = "CET"), period_end = lubridate::ymd("2020-01-02", tz = "CET"), - security_token = "dummy_token" - ), - regexp = "HTTP 503" - ) - } -) - - -testthat::test_that( - desc = "net_transfer_capacities() validates inputs", - code = { - testthat::expect_error( - object = net_transfer_capacities( - eic_in = c("10YNL----------L", "10YBE----------2"), - eic_out = c("10YBE----------2", "10YNL----------L"), - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-05-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "Assertion on 'eic_in' failed: Must have length 1" - ) - testthat::expect_error( - object = net_transfer_capacities( - eic_in = "10YNL----------L", - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-05-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "Assertion on 'eic_out' failed: Must be of type 'string'" - ) - testthat::expect_error( - object = net_transfer_capacities( - eic_out = "10YBE----------2", - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-05-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "Assertion on 'eic_in' failed: Must be of type 'string'" - ) - testthat::expect_error( - object = net_transfer_capacities( - eic_in = "10YNL----------L", - eic_out = "10YBE----------2", - contract_type = "INVALID", - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-05-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ) - ) - testthat::expect_error( - object = net_transfer_capacities( - eic_in = "10YNL----------L", - eic_out = "10YBE----------2", - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-05-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "" - ), - regexp = "" - ) - testthat::expect_error( - object = net_transfer_capacities( - eic_in = "10YNL----------L", - eic_out = "10YBE----------2", - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2024-05-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "ABC" - ) - ) - testthat::expect_error( - object = net_transfer_capacities( - eic_in = "10YNL----------L", - eic_out = "10YBE----------2", - period_start = lubridate::ymd( - x = "2024-05-16", - tz = "CET" - ), - period_end = lubridate::ymd( - x = "2025-05-17", - tz = "CET" - ), - tidy_output = FALSE, - security_token = "dummy_token" - ), - regexp = "One year range limit should be applied" - ) - } -) - - -testthat::test_that( - desc = "net_transfer_capacities() covers happy path with mock", - code = { - httr2::local_mocked_responses( - mock = function(req) { - httr2::response( - status_code = 503L, - url = req$url, - headers = list("content-type" = "application/xml"), - body = charToRaw( - paste0( - '', - "Service Unavailable" - ) - ) - ) - } - ) - testthat::expect_error( - object = net_transfer_capacities( - eic_in = "10YNL----------L", - eic_out = "10YBE----------2", - period_start = lubridate::ymd(x = "2024-05-16", tz = "CET"), - period_end = lubridate::ymd(x = "2024-05-17", tz = "CET"), - security_token = "dummy_token" + security_token = .test_token ), regexp = "HTTP 503" ) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 5c664930..0f7ef246 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -1,167 +1,91 @@ -testthat::test_that( - desc = "extract_leaf_twig_branch() works 1", - code = { - sample_path_1 <- testthat::test_path("fixtures", "cd_catalog.xml") - content_1 <- list( - result = xml2::read_xml(x = sample_path_1), - error = NULL - ) - testthat::expect_s3_class( - object = xml2::xml_contents(x = content_1$result) |> - extract_leaf_twig_branch(), - class = "tbl" - ) +test_df_list <- testthat::test_path("fixtures", "test_df_list.rds") |> + readRDS() +entsoe_gen_min_raw <- testthat::test_path("fixtures", "entsoe_gen_min.xml") |> + readLines(encoding = "UTF-8") |> + paste(collapse = "\n") |> + charToRaw() +entsoe_gen_min_xml <- testthat::test_path("fixtures", "entsoe_gen_min.xml") |> + xml2::read_xml() +order_schema_xml <- testthat::test_path("fixtures", "order-schema.xml") |> + xml2::read_xml() +get_allocated_eic_min_raw <- testthat::test_path( + "fixtures", "get_allocated_eic_min.xml" +) |> + readLines(encoding = "UTF-8") |> + paste(collapse = "\n") |> + charToRaw() + + +testthat::test_that( + desc = "extract_leaf_twig_branch() works", + code = { + result <- xml2::xml_contents(entsoe_gen_min_xml) |> + extract_leaf_twig_branch() + testthat::expect_s3_class(object = result, class = "tbl") testthat::expect_equal( - object = xml2::xml_contents(x = content_1$result) |> - extract_leaf_twig_branch() |> - dim(), - expected = c(1, 6) - ) - } -) - - -testthat::test_that( - desc = "extract_leaf_twig_branch() works 2", - code = { - testthat::skip_if_not( - condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, - message = "No ENTSOE_PAT environment variable set" - ) - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) - url_sample_2 <- paste( - "documentType=A73", - "processType=A16", - "periodStart=202001302300", - "periodEnd=202001312300", - "in_Domain=10YDE-VE-------2", - sep = "&" - ) - url_sample_3 <- paste( - "documentType=A80", - "biddingZone_Domain=10YFR-RTE------C", - "periodStart=202407192200", - "periodEnd=202407232200", - sep = "&" - ) - url_sample_4 <- paste( - "documentType=A73", - "processType=A16", - "periodStart=202001302300", - "periodEnd=202001312300", - "in_Domain=10YDE-VE-------2", - sep = "&" - ) - content_2 <- api_req_safe( - query_string = url_sample_2, - security_token = Sys.getenv("ENTSOE_PAT") - ) - content_3 <- api_req_safe( - query_string = url_sample_3, - security_token = Sys.getenv("ENTSOE_PAT") - ) - content_4 <- api_req_safe( - query_string = url_sample_4, - security_token = Sys.getenv("ENTSOE_PAT") + object = dim(result), + expected = c(2L, 22L) ) testthat::expect_setequal( - object = xml2::xml_contents(x = content_2$result) |> - extract_leaf_twig_branch() |> - names() |> - sort(), + object = names(result), expected = c( - "createdDateTime", - "mRID", - "process.processType", + "createdDateTime", "mRID", "process.processType", "receiver_MarketParticipant.marketRole.type", - "receiver_MarketParticipant.mRID", - "revisionNumber", + "receiver_MarketParticipant.mRID", "revisionNumber", "sender_MarketParticipant.marketRole.type", - "sender_MarketParticipant.mRID", - "time_Period.timeInterval.end", - "time_Period.timeInterval.start", - "TimeSeries.businessType", - "TimeSeries.curveType", - "TimeSeries.inBiddingZone_Domain.mRID", - "TimeSeries.MktPSRType.PowerSystemResources.mRID", - "TimeSeries.MktPSRType.PowerSystemResources.name", - "TimeSeries.MktPSRType.psrType", - "TimeSeries.mRID", - "TimeSeries.objectAggregation", - "TimeSeries.Period.Point.position", - "TimeSeries.Period.Point.quantity", - "TimeSeries.Period.resolution", - "TimeSeries.Period.timeInterval.end", + "sender_MarketParticipant.mRID", "time_Period.timeInterval.end", + "time_Period.timeInterval.start", "TimeSeries.businessType", + "TimeSeries.curveType", "TimeSeries.inBiddingZone_Domain.mRID", + "TimeSeries.MktPSRType.psrType", "TimeSeries.mRID", + "TimeSeries.Period.Point.position", "TimeSeries.Period.Point.quantity", + "TimeSeries.Period.resolution", "TimeSeries.Period.timeInterval.end", "TimeSeries.Period.timeInterval.start", - "TimeSeries.quantity_Measure_Unit.name", - "TimeSeries.registeredResource.mRID", - "type" - ) - ) - testthat::expect_contains( - object = xml2::xml_contents(x = content_3$result[[1L]]) |> - extract_leaf_twig_branch() |> - names() |> - sort(), - expected = c( - "createdDateTime", - "mRID", - "process.processType", - "Reason.code", - "receiver_MarketParticipant.marketRole.type", - "receiver_MarketParticipant.mRID", - "revisionNumber", - "sender_MarketParticipant.marketRole.type", - "sender_MarketParticipant.mRID", - "TimeSeries.Available_Period.Point.position", - "TimeSeries.Available_Period.Point.quantity", - "TimeSeries.Available_Period.resolution", - "TimeSeries.Available_Period.timeInterval.end", - "TimeSeries.Available_Period.timeInterval.start", - "TimeSeries.biddingZone_Domain.mRID", - "TimeSeries.businessType", - "TimeSeries.curveType", - "TimeSeries.end_DateAndOrTime.date", - "TimeSeries.end_DateAndOrTime.time", - "TimeSeries.mRID", - "TimeSeries.production_RegisteredResource.location.name", - "TimeSeries.production_RegisteredResource.mRID", - "TimeSeries.production_RegisteredResource.name", - paste0( - "TimeSeries.production_RegisteredResource.", - "pSRType.powerSystemResources.mRID" - ), - paste0( - "TimeSeries.production_RegisteredResource.", - "pSRType.powerSystemResources.name" - ), - paste0( - "TimeSeries.production_RegisteredResource.", - "pSRType.powerSystemResources.nominalP" - ), - "TimeSeries.production_RegisteredResource.pSRType.psrType", - "TimeSeries.quantity_Measure_Unit.name", - "TimeSeries.start_DateAndOrTime.date", - "TimeSeries.start_DateAndOrTime.time", - "type", - "unavailability_Time_Period.timeInterval.end", - "unavailability_Time_Period.timeInterval.start" + "TimeSeries.quantity_Measure_Unit.name", "type" ) ) + } +) + + +testthat::test_that( + desc = "extract_leaf_twig_branch() cross-joins unequal-group XML", + code = { testthat::expect_equal( - object = xml2::xml_contents(x = content_4$result) |> + object = testthat::test_path("fixtures", "unequal_group.xml") |> + readLines(encoding = "UTF-8") |> + paste0(collapse = "") |> + xml2::read_xml() |> + xml2::xml_contents() |> extract_leaf_twig_branch() |> dim(), - expected = c(546, 26) + expected = c(6L, 2L) ) + } +) + + +testthat::test_that( + desc = paste( + "extract_leaf_twig_branch() returns empty tibble", + "when both leaf_rows and nested_all_rows are empty" + ), + code = { + result <- entsoeapi:::extract_leaf_twig_branch(nodesets = list()) + testthat::expect_s3_class(object = result, class = "tbl_df") + testthat::expect_equal(object = dim(result), expected = c(0L, 0L)) + } +) + + +testthat::test_that( + desc = "extract_leaf_twig_branch() not works for data.frame", + code = { testthat::expect_error( - object = extract_leaf_twig_branch(nodesets = test_df_6), - info = paste( + object = test_df_list[[6L]] |> + extract_leaf_twig_branch(), + regexp = paste( "no applicable method for 'nodeset_apply'", - "applied to an object of class 'c('double', 'numeric')'" + "applied to an object of class \\\"c\\('double', 'numeric'\\)\\\"" ) ) } @@ -169,28 +93,28 @@ testthat::test_that( testthat::test_that( - desc = "read_zipped_xml() works", + desc = "read_zipped_xml() works as expected", code = { gzipped_sample_fixture <- testthat::test_path("fixtures", "mtcars.gzip") zipped_sample_fixture <- testthat::test_path("fixtures", "mtcars.zip") zipped_xml_sample_fixture <- testthat::test_path( "fixtures", "cd_catalog_xml.zip" ) + testthat::expect_no_error( + object = read_zipped_xml(temp_file_path = zipped_xml_sample_fixture) + ) testthat::expect_warning( object = read_zipped_xml(temp_file_path = tempfile()), - info = "In .f(...) : error 1 in extracting from zip file" + regexp = "error 1 in extracting from zip file" ) testthat::expect_warning( object = read_zipped_xml(temp_file_path = gzipped_sample_fixture), - info = "In .f(...) : error 1 in extracting from zip file" + regexp = "error 1 in extracting from zip file" ) testthat::expect_error( object = read_zipped_xml(temp_file_path = zipped_sample_fixture), regexp = "Start tag expected, '<' not found \\[4\\]" ) - testthat::expect_no_error( - object = read_zipped_xml(temp_file_path = zipped_xml_sample_fixture) - ) } ) @@ -199,7 +123,7 @@ testthat::test_that( desc = "read_zipped_xml() aborts when unzip throws an error", code = { testthat::local_mocked_bindings( - unzip = function(...) stop("cannot open the connection"), + unzip = \(...) stop("cannot open the connection"), .package = "entsoeapi" ) testthat::expect_error( @@ -211,7 +135,7 @@ testthat::test_that( testthat::test_that( - desc = "calc_offset_urls() works", + desc = "calc_offset_urls() works as expected", code = { url_sample <- paste( "documentType=A65", @@ -224,13 +148,9 @@ testthat::test_that( reason_1 <- "allowed: 200; requested: 1111" reason_2 <- "allowed: -200; requested: -1111" reason_3 <- "foo; bar" - testthat::expect_equal( - object = calc_offset_urls( - reason = reason_1, - query_string = url_sample - ) |> - length(), - expected = 6L + testthat::expect_length( + object = calc_offset_urls(reason = reason_1, query_string = url_sample), + n = 6L ) testthat::expect_error( object = calc_offset_urls(reason = reason_2, query_string = url_sample), @@ -247,15 +167,8 @@ testthat::test_that( testthat::test_that( desc = "api_req() works", code = { - testthat::skip_if_not( - condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, - message = "No ENTSOE_PAT environment variable set" - ) - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) - url_sample_1 <- paste( + m$reset() + url_sample <- paste( "documentType=A73", "processType=A16", "periodStart=202001302300", @@ -263,64 +176,9 @@ testthat::test_that( "in_Domain=10YDE-VE-------2", sep = "&" ) - url_sample_2 <- paste( - "documentType=A80", - "biddingZone_Domain=10YFR-RTE------C", - "periodStart=202407222200", - "periodEnd=202407232200", - sep = "&" - ) - url_sample_3 <- paste( - "documentType=A65", - "processType=A16", - "outBiddingZone_Domain=10YCZ-CEPS-----N", - "periodStart=202501242300", - "periodEnd=202501312300", - sep = "&" - ) - url_sample_4 <- paste( - "documentType=A80", - "biddingZone_Domain=10YFR-RTE------C", - "periodStart=202407132200", - "periodEnd=202407232200", - sep = "&" - ) - url_sample_5 <- paste( - "documentType=A75", - "processType=A16", - "in_Domain=10YFR-RTE------C", - "periodStart=202202292300", - "periodEnd=202403312200", - sep = "&" - ) - testthat::expect_no_error( - object = api_req( - query_string = url_sample_4, - security_token = Sys.getenv("ENTSOE_PAT") - ) - ) - testthat::expect_error( - object = api_req( - query_string = url_sample_5, - security_token = Sys.getenv("ENTSOE_PAT") - ), - regexp = paste0( - "(is larger than maximum allowed period 'P1Y'|", - "Operation timed out)" - ) - ) - testthat::expect_error( - object = api_req( - query_string = paste0(.api_scheme, .api_domain, .api_name), - security_token = Sys.getenv("ENTSOE_PAT") - ), - regexp = "Unable to parse URI. Its format is not valid" - ) + # validation errors (offline) testthat::expect_error( - object = api_req( - query_string = NULL, - security_token = Sys.getenv("ENTSOE_PAT") - ), + object = api_req(query_string = NULL, security_token = .test_token), regexp = paste( "Assertion on 'query_string' failed:", "Must be of type 'string', not 'NULL'" @@ -334,55 +192,31 @@ testthat::test_that( ) ) testthat::expect_error( - object = api_req( - query_string = NA, - security_token = Sys.getenv("ENTSOE_PAT") - ), + object = api_req(query_string = NA, security_token = .test_token), regexp = "Assertion on 'query_string' failed: May not be NA." ) testthat::expect_error( - object = api_req( - query_string = paste0(.api_scheme, "google.com/"), - security_token = Sys.getenv("ENTSOE_PAT") - ), - regexp = "Unable to parse URI." - ) - testthat::expect_error( - object = api_req( - query_string = "", - security_token = Sys.getenv("ENTSOE_PAT") - ), - regexp = paste( - "The combination of \\[\\] is not valid, or the requested data is not", - "allowed to be fetched via this service" - ) - ) - testthat::expect_error( - object = api_req( - query_string = url_sample_1 - ), + object = api_req(query_string = url_sample), regexp = paste( "Assertion on 'security_token' failed:", "Must be of type 'string', not 'NULL'." ) ) + # mocked XML 200 response + httr2::local_mocked_responses( + mock = \(req) { + httr2::response( + status_code = 200L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = entsoe_gen_min_raw + ) + } + ) testthat::expect_s3_class( - object = api_req( - query_string = url_sample_1, - security_token = Sys.getenv("ENTSOE_PAT") - ), + object = api_req(query_string = url_sample, security_token = .test_token), class = "xml_document" ) - testthat::expect_true( - object = api_req( - query_string = url_sample_2, - security_token = Sys.getenv("ENTSOE_PAT") - ) |> - lapply(\(x) inherits(x = x, what = "xml_document")) |> - unlist() |> - all(), - info = "The url value should be printed in console!" - ) } ) @@ -390,91 +224,89 @@ testthat::test_that( testthat::test_that( desc = "api_req_safe() works", code = { - testthat::skip_if_not( - condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, - message = "No ENTSOE_PAT environment variable set" - ) - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) - url_sample_1 <- paste( - "documentType=A73", - "processType=A16", - "periodStart=202001302300", - "periodEnd=202001312300", - "in_Domain=10YDE-VE-------2", - sep = "&" + m$reset() + httr2::local_mocked_responses( + mock = \(req) { + httr2::response( + status_code = 200L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = entsoe_gen_min_raw + ) + } ) - url_sample_2 <- NULL testthat::expect_no_error( object = content_1 <- api_req_safe( - query_string = url_sample_1, - security_token = Sys.getenv("ENTSOE_PAT") + query_string = paste( + "documentType=A73", + "processType=A16", + "periodStart=202001302300", + "periodEnd=202001312300", + "in_Domain=10YDE-VE-------2", + sep = "&" + ), + security_token = .test_token ) ) - testthat::expect_true( - object = "xml_document" %in% class(content_1$result) - ) - testthat::expect_true( - object = is.null(content_1$error) - ) + testthat::expect_s3_class(object = content_1$result, class = "xml_document") + testthat::expect_null(object = content_1$error) testthat::expect_true( object = is.list(content_1) && length(content_1) == 2L && all(names(content_1) == c("result", "error")) ) + # error path: NULL query_string triggers + # assertion error captured by safely() testthat::expect_no_error( object = content_2 <- api_req_safe( - query_string = url_sample_2, - security_token = Sys.getenv("ENTSOE_PAT") + query_string = NULL, + security_token = .test_token ) ) - testthat::expect_true( - object = "error" %in% class(content_2$error) - ) - testthat::expect_true( - object = is.null(content_2$result) - ) + testthat::expect_s3_class(object = content_2$error, class = "error") + testthat::expect_null(object = content_2$result) } ) testthat::test_that( - desc = "url_posixct_format() works", + desc = "url_posixct_format() works as expected", code = { - sample_hour <- as.POSIXct("2026-03-25 12:00:00", tz = "CET") testthat::expect_null( object = url_posixct_format(x = NULL), info = "The result of this functions should be NULL!" ) testthat::expect_error( object = url_posixct_format(), - info = "The argument 'x' is missing!" + regexp = 'argument "x" is missing' ) testthat::expect_error( object = url_posixct_format(x = NA), - info = "The argument 'x' not in an acceptable timestamp format!" + regexp = "The argument is not in an acceptable timestamp format" ) testthat::expect_error( object = url_posixct_format(x = 101L:110L), - info = "The argument 'x' not in an acceptable timestamp format!" + regexp = "The argument is not in an acceptable timestamp format" ) testthat::expect_error( object = url_posixct_format(x = 101L), - info = "The argument 'x' not in an acceptable timestamp format!" + regexp = "The argument is not in an acceptable timestamp format" ) testthat::expect_error( object = url_posixct_format(x = 101.5), - info = "The argument 'x' not in an acceptable timestamp format!" + regexp = "The argument is not in an acceptable timestamp format" ) testthat::expect_error( object = url_posixct_format(x = "ABC"), - info = "The argument 'x' not in an acceptable timestamp format!" + regexp = paste( + "Only the class POSIXct or '%Y-%m-%d %H:%M:%S'", + "formatted text are supported by the converter" + ) ) - testthat::expect_true( - object = url_posixct_format(x = sample_hour) |> - stringr::str_like(pattern = "[0-9]{12}"), + testthat::expect_match( + object = as.POSIXct("2026-03-25 12:00:00", tz = "CET") |> + url_posixct_format(), + regexp = "[0-9]{12}", info = "The result of this functions should be 12 digit length string!" ) testthat::expect_message( @@ -488,146 +320,160 @@ testthat::test_that( testthat::test_that( desc = "get_eiccodes() works", code = { - testthat::skip_if_not( - condition = curl::nslookup(host = .pd_domain, error = FALSE) |> - is.null() |> - isFALSE(), - message = "The Entso-e download site cannot be reached" + result <- get_eiccodes( + pd_scheme = "", + pd_domain = "", + pd_csv_eic = "", + f = testthat::test_path("fixtures", "eiccodes.csv") ) testthat::expect_setequal( - object = get_eiccodes( - f = "Y_eicCodes.csv" - ) |> names(), + object = names(result), expected = c( - "eic_code", - "eic_display_name", - "eic_long_name", - "eic_parent", - "eic_responsible_party", - "eic_status", - "market_participant_postal_code", - "market_participant_iso_country_code", - "market_participant_vat_code", - "eic_type_function_list", - "type" + "eic_code", "eic_display_name", "eic_long_name", "eic_parent", + "eic_responsible_party", "eic_status", "market_participant_postal_code", + "market_participant_iso_country_code", "market_participant_vat_code", + "eic_type_function_list", "type" ) ) - testthat::expect_gt( - object = get_eiccodes(f = "Y_eicCodes.csv") |> nrow(), - expected = 300 - ) + testthat::expect_equal(object = dim(result), expected = c(2L, 11L)) + # error path: non-existent file returns NULL testthat::expect_null( - object = get_eiccodes(f = NULL), - info = "Cannot open the connection!" + object = get_eiccodes( + pd_scheme = "", + pd_domain = "", + pd_csv_eic = "", + f = "/nonexistent/path.csv" + ) + ) |> + testthat::expect_warning(regexp = "No such file or directory") + } +) + + +testthat::test_that( + desc = "get_eiccodes() suppresses incomplete final line warning", + code = { + # Write a valid CSV file that intentionally lacks a trailing newline so + # that readLines() would normally issue an "incomplete final line" warning. + # The withCallingHandlers() block in get_eiccodes() must muffle it. + csv_no_newline <- paste0( + '"EicCode";"EicDisplayName";"EicLongName";"EicParent";', + '"EicResponsibleParty";"EicStatus";"MarketParticipantPostalCode";', + '"MarketParticipantIsoCountryCode";"MarketParticipantVatCode";', + '"EicTypeFunctionList"\n', + '"10Y000-0000-0001";"AreaX";"Area X Long";"";', + '"";"";"";"";"";""' # <- no \n here, so last line is incomplete ) - testthat::expect_null( - object = get_eiccodes(f = "ABC"), - info = "Cannot open the connection!" + tmp <- tempfile(fileext = ".csv") + con <- file(tmp, open = "wb") + writeBin(charToRaw(csv_no_newline), con) + close(con) + on.exit(unlink(tmp), add = TRUE) + testthat::expect_no_warning( + object = get_eiccodes( + pd_scheme = "", + pd_domain = "", + pd_csv_eic = "", + f = tmp + ) ) - testthat::expect_no_error(object = get_eiccodes(f = "X_eicCodes.csv")) - testthat::expect_no_error(object = get_eiccodes(f = "Z_eicCodes.csv")) - testthat::expect_no_error(object = get_eiccodes(f = "T_eicCodes.csv")) - testthat::expect_no_error(object = get_eiccodes(f = "V_eicCodes.csv")) - testthat::expect_no_error(object = get_eiccodes(f = "W_eicCodes.csv")) - testthat::expect_no_error(object = get_eiccodes(f = "A_eicCodes.csv")) } ) testthat::test_that( - desc = "tidy_or_not() works", + desc = "tidy_or_not() works as expected", code = { - test_df_list <- readRDS( - file = testthat::test_path("fixtures", "test_df_list.rds") - ) - for (i in 1L:5L) { - assign(x = paste0("test_df_", i), value = test_df_list[[i]]) - } testthat::expect_equal( - object = tidy_or_not(tbl = test_df_1, tidy_output = TRUE) |> dim(), + object = tidy_or_not(tbl = test_df_list[[1L]], tidy_output = TRUE) |> + dim(), expected = c(1L, 4L) ) testthat::expect_equal( - object = tidy_or_not(tbl = test_df_1, tidy_output = FALSE) |> dim(), + object = tidy_or_not(tbl = test_df_list[[1L]], tidy_output = FALSE) |> + dim(), expected = c(1L, 4L) ) - testthat::expect_contains( - object = tidy_or_not(tbl = test_df_2, tidy_output = TRUE) |> + testthat::expect_setequal( + object = tidy_or_not(tbl = test_df_list[[2L]], tidy_output = TRUE) |> names(), expected = c( "ts_resolution", "ts_reason_code", "ts_time_interval_start", "ts_point_price", "ts_point_dt_start" ) ) - testthat::expect_contains( - object = tidy_or_not(tbl = test_df_2, tidy_output = FALSE) |> + testthat::expect_setequal( + object = tidy_or_not(tbl = test_df_list[[2L]], tidy_output = FALSE) |> names(), expected = c( "ts_resolution", "ts_reason_code", "ts_time_interval_start", "ts_point" ) ) - testthat::expect_no_error( - object = result_3_tidy <- tidy_or_not(tbl = test_df_3, tidy_output = TRUE) - ) - testthat::expect_contains( - object = names(result_3_tidy), - expected = c("bid_ts_point_price", "bid_ts_point_dt_start") - ) - testthat::expect_false(object = "ts_point_price" %in% names(result_3_tidy)) - testthat::expect_no_error( - object = result_4 <- tidy_or_not(tbl = test_df_4, tidy_output = FALSE) + testthat::expect_setequal( + object = tidy_or_not(tbl = test_df_list[[3L]], tidy_output = TRUE) |> + names(), + expected = c( + "bid_ts_mrid", "bid_ts_resolution", "bid_ts_time_interval_start", + "bid_ts_point_price", "bid_ts_point_dt_start" + ) ) - testthat::expect_contains( - object = names(result_4), + testthat::expect_setequal( + object = tidy_or_not(tbl = test_df_list[[4L]], tidy_output = FALSE) |> + names(), expected = c("bid_ts_resolution", "bid_ts_mrid") ) - testthat::expect_no_error( - object = result_5 <- tidy_or_not(tbl = test_df_5, tidy_output = TRUE) + testthat::expect_setequal( + object = tidy_or_not(tbl = test_df_list[[5L]], tidy_output = TRUE) |> + names(), + expected = c( + "ts_mrid", "ts_curve_type", "ts_resolution", "ts_time_interval_start", + "ts_time_interval_end", "ts_point_quantity", "ts_point_dt_start" + ) ) - testthat::expect_contains( - object = names(result_5), - expected = c("ts_point_dt_start", "ts_point_quantity") + testthat::expect_equal( + object = tidy_or_not(tbl = test_df_list[[5L]], tidy_output = TRUE) |> + dim(), + expected = c(6L, 7L) ) - testthat::expect_equal(object = nrow(result_5), expected = 6L) } ) testthat::test_that( - desc = "my_snakecase() works", + desc = "tidy_or_not() stops on unknown curve_type", code = { - test_df_6 <- readRDS( - file = testthat::test_path("fixtures", "test_df_list.rds") - ) |> - pluck(6) - test_df_7 <- readRDS( - file = testthat::test_path("fixtures", "test_df_list.rds") - ) |> - pluck(7) - testthat::expect_contains( - object = my_snakecase(tbl = test_df_6), + testthat::expect_error( + object = tidy_or_not(tbl = test_df_list[[13L]], tidy_output = TRUE), + regexp = "The curve type is not defined, but A99!" + ) + } +) + + +testthat::test_that( + desc = "my_snakecase() works as expected", + code = { + testthat::expect_setequal( + object = my_snakecase(tbl = test_df_list[[6L]]), expected = c( "sepal_length", "sepal_width", "petal_length", "petal_width", "species" ) ) - testthat::expect_contains( + testthat::expect_setequal( object = my_snakecase(tbl = transmission_pair_eic_dict), expected = c( - "out_area_code", "out_area_type_code", "out_area_name", - "out_map_code", "in_area_code", "in_area_type_code", - "in_area_name", "in_map_code" + "out_area_code", "out_area_type_code", "out_area_name", "out_map_code", + "in_area_code", "in_area_type_code", "in_area_name", "in_map_code" ) ) - testthat::expect_contains( - object = my_snakecase(tbl = test_df_7), + testthat::expect_setequal( + object = my_snakecase(tbl = test_df_list[[7L]]), expected = c( - "mrid", "ts_type", - "unavailability", "a_ts_production", - "b_ts_production", "c_ts_asset", "d_ts_asset", - "e_psr_type", "f_psr_type", "g_psr_type", - "receiver_market_participant_market_role" + "mrid", "ts_type", "unavailability", "a_ts_production", + "b_ts_production", "c_ts_asset", "d_ts_asset", "e_psr_type", + "f_psr_type", "g_psr_type", "receiver_market_participant_market_role" ) ) testthat::expect_error( @@ -642,38 +488,22 @@ testthat::test_that( testthat::test_that( - desc = "add_type_names() works", + desc = "add_type_names() works as expected", code = { - test_df_list <- readRDS( - file = testthat::test_path("fixtures", "test_df_list.rds") - ) - for (i in c(6L, 8L, 9L, 12L)) { - assign(x = paste0("test_df_", i), value = test_df_list[[i]]) - } testthat::expect_setequal( - object = add_type_names(tbl = test_df_8) |> + object = add_type_names(tbl = test_df_list[[8L]]) |> names(), expected = c( - "process_type", - "process_type_def", - "ts_auction_type", - "ts_auction_type_def", - "ts_business_type", - "ts_business_type_def", - "type", - "type_def", - "market_agreement_type", - "market_agreement_type_def", - "ts_asset_psr_type", - "ts_asset_psr_type_def", - "ts_production_psr_type", - "ts_production_psr_type_def", - "ts_mkt_psr_type", - "ts_mkt_psr_type_def" + "process_type", "process_type_def", "ts_auction_type", + "ts_auction_type_def", "ts_business_type", "ts_business_type_def", + "type", "type_def", "market_agreement_type", + "market_agreement_type_def", "ts_asset_psr_type", + "ts_asset_psr_type_def", "ts_production_psr_type", + "ts_production_psr_type_def", "ts_mkt_psr_type", "ts_mkt_psr_type_def" ) ) testthat::expect_no_warning( - object = add_type_names(tbl = test_df_6), + object = add_type_names(tbl = test_df_list[[6L]]), message = "No additional definitions added!" ) testthat::expect_no_warning( @@ -681,16 +511,16 @@ testthat::test_that( message = "No additional definitions added!" ) # ts_product branch - testthat::expect_contains( - object = add_type_names(tbl = test_df_12) |> names(), - expected = "ts_product_def" - ) - testthat::expect_no_error( - object = result_role_dir <- add_type_names(tbl = test_df_9) + testthat::expect_setequal( + object = add_type_names(tbl = test_df_list[[12L]]) |> names(), + expected = c("ts_product", "ts_product_def") ) - testthat::expect_contains( - object = names(result_role_dir), + testthat::expect_setequal( + object = add_type_names(tbl = test_df_list[[9L]]) |> + names(), expected = c( + "subject_market_participant_market_role_type", + "bid_ts_flow_direction", "subject_market_participant_market_role_type_def", "bid_ts_flow_direction_def" ) @@ -700,391 +530,297 @@ testthat::test_that( testthat::test_that( - desc = "add_eic_names() works", + desc = "add_eic_names() works as expected", code = { - testthat::skip_if_not( - condition = curl::nslookup(host = .pd_domain, error = FALSE) |> - is.null() |> - isFALSE(), - message = "The Entso-e download site cannot be reached" - ) - test_df_list <- readRDS( - file = testthat::test_path("fixtures", "test_df_list.rds") + m$reset() + testthat::local_mocked_bindings( + get_resource_object_eic = \(...) test_df_list[[16L]], + fetch_eic_csv = \(...) test_df_list[[17L]], + .package = "entsoeapi" ) - for (i in c(6L, 10L)) { - assign(x = paste0("test_df_", i), value = test_df_list[[i]]) - } - testthat::expect_contains( - object = add_eic_names(tbl = test_df_10) |> + testthat::expect_setequal( + object = add_eic_names(tbl = test_df_list[[10L]]) |> names(), expected = c( - "control_area_domain_mrid", - "ts_out_domain_mrid", - "ts_in_domain_mrid", - "ts_out_bidding_zone_domain_mrid", - "ts_in_bidding_zone_domain_mrid", - "ts_bidding_zone_domain_mrid", - "ts_registered_resource_mrid", - "ts_registered_resource_name", - "ts_bidding_zone_domain_name", - "ts_in_bidding_zone_domain_name", - "ts_out_bidding_zone_domain_name", - "ts_in_domain_name", - "ts_out_domain_name", - "control_area_domain_name" + "control_area_domain_mrid", "ts_out_domain_mrid", "ts_in_domain_mrid", + "ts_out_bidding_zone_domain_mrid", "ts_in_bidding_zone_domain_mrid", + "ts_bidding_zone_domain_mrid", "ts_registered_resource_mrid", + "ts_registered_resource_name", "ts_bidding_zone_domain_name", + "ts_in_bidding_zone_domain_name", "ts_out_bidding_zone_domain_name", + "ts_in_domain_name", "ts_out_domain_name", "control_area_domain_name" ) ) testthat::expect_s3_class( - object = add_eic_names(tbl = test_df_6), + object = add_eic_names(tbl = test_df_list[[6L]]), class = "data.frame" ) - testthat::expect_equal( + testthat::expect_s3_class( object = add_eic_names(tbl = NULL), - expected = data.frame() + class = "data.frame" ) } ) testthat::test_that( - desc = "add_definitions() works", + desc = "add_eic_names() adds names for additional domain mrid columns", code = { - test_df_list <- readRDS( - file = testthat::test_path("fixtures", "test_df_list.rds") + m$reset() + testthat::local_mocked_bindings( + fetch_eic_csv = \(...) test_df_list[[18L]], + .package = "entsoeapi" ) - for (i in c(6L, 11L)) { - assign(x = paste0("test_df_", i), value = test_df_list[[i]]) - } testthat::expect_setequal( - object = add_definitions(tbl = test_df_11) |> + object = add_eic_names(tbl = test_df_list[[14L]]) |> names(), expected = c( - "doc_status_value", - "ts_auction_category", - "ts_flow_direction", - "reason_code", - "ts_reason_code", - "ts_object_aggregation", - "doc_status", - "ts_auction_category_def", - "ts_flow_direction_def", - "reason_text", - "ts_reason_text", - "ts_object_aggregation_def" + "area_domain_mrid", "area_domain_name", "ts_acquiring_domain_mrid", + "ts_acquiring_domain_name", "ts_connecting_domain_mrid", + "ts_connecting_domain_name", "bid_ts_acquiring_domain_mrid", + "bid_ts_acquiring_domain_name", "bid_ts_connecting_domain_mrid", + "bid_ts_connecting_domain_name", "domain_mrid", "domain_name", + "constraint_ts_monitored_ptdf_domain_mrid", + "constraint_ts_monitored_ptdf_domain_name" ) ) - testthat::expect_s3_class( - object = add_definitions(tbl = test_df_6), - class = "data.frame" - ) - testthat::expect_equal( - object = add_definitions(tbl = NULL), - expected = data.frame() + } +) + + +testthat::test_that( + desc = "add_definitions() worksas expected", + code = { + testthat::expect_setequal( + object = add_definitions(tbl = test_df_list[[15L]]) |> + names(), + expected = c("ts_reason_code", "ts_reason_text") + ) + testthat::expect_true( + object = add_definitions(tbl = test_df_list[[15L]]) |> + pluck("ts_reason_text") |> + str_detect(pattern = " - ") |> + all() + ) + testthat::expect_setequal( + object = add_definitions(tbl = test_df_list[[11L]]) |> + names(), + expected = c( + "doc_status_value", "ts_auction_category", "ts_flow_direction", + "reason_code", "ts_reason_code", "ts_object_aggregation", + "doc_status", "ts_auction_category_def", "ts_flow_direction_def", + "reason_text", "ts_reason_text", "ts_object_aggregation_def" + ) + ) + testthat::expect_s3_class( + object = add_definitions(tbl = test_df_list[[6L]]), + class = "data.frame" + ) + testthat::expect_equal( + object = add_definitions(tbl = NULL), + expected = data.frame() ) } ) testthat::test_that( - desc = "xml_to_table() works 1", + desc = "xml_to_table() works as expected 1", code = { - test_df_6 <- readRDS( - file = testthat::test_path("fixtures", "test_df_list.rds") - ) |> - pluck(6) - xml_fixture <- testthat::test_path("fixtures", "order-schema.xml") |> - xml2::read_xml() testthat::expect_error( - object = xml_to_table(xml_content = xml_fixture, tidy_output = FALSE), - info = "There is no interesting columns in the result table!" + object = xml_to_table( + xml_content = order_schema_xml, + tidy_output = FALSE + ), + regexp = "There is no interesting column in the result table!" ) testthat::expect_error( - object = xml_to_table(xml_content = test_df_6), - info = "The 'xml_content' should be an xml document!" + object = xml_to_table(xml_content = test_df_list[[6L]]), + regexp = "The `xml_content` should be an xml document" ) testthat::expect_error( object = xml_to_table(xml_content = NULL), - info = "The 'xml_content' should be an xml document!" + regexp = "The `xml_content` should be an xml document" ) testthat::expect_error( object = xml_to_table(xml_content = NA), - info = "The 'xml_content' should be an xml document!" + regexp = "The `xml_content` should be an xml document" + ) + testthat::expect_error( + object = xml_to_table(xml_content = "not an xml"), + regexp = "The `xml_content` should be an xml document" ) } ) testthat::test_that( - desc = "xml_to_table() works 2", + desc = "xml_to_table() works as expected 2", code = { - testthat::skip_if_not( - condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, - message = "No ENTSOE_PAT environment variable set" - ) - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) - url_sample_1 <- paste( - "documentType=A73", - "processType=A16", - "periodStart=202001302300", - "periodEnd=202001312300", - "in_Domain=10YDE-VE-------2", - sep = "&" - ) - url_sample_2 <- paste( - "documentType=A44", - "in_Domain=10YDK-1--------W", - "out_Domain=10YDK-1--------W", - "periodStart=201910312300", - "periodEnd=201911302300", - sep = "&" - ) - url_sample_3 <- paste( - "documentType=A63", - "businessType=A85", - "in_Domain=10YNL----------L", - "out_Domain=10YNL----------L", - "periodStart=202402292300", - "periodEnd=202403312300", - sep = "&" - ) - url_sample_4 <- paste( - "documentType=A63", - "businessType=A85", - "in_Domain=10YNL----------L", - "out_Domain=10YNL----------L", - "periodStart=202310302300", - "periodEnd=202311302300", - sep = "&" - ) - url_sample_5 <- paste( - "documentType=A65", - "businessType=A85", - "in_Domain=10YNO-0--------C", - "out_Domain=10YNO-0--------C", - "periodStart=202402292300", - "periodEnd=202403102300", - sep = "&" - ) - content_1 <- api_req_safe( - query_string = url_sample_1, - security_token = Sys.getenv("ENTSOE_PAT") - ) - content_2 <- api_req_safe( - query_string = url_sample_2, - security_token = Sys.getenv("ENTSOE_PAT") - ) - content_3 <- api_req_safe( - query_string = url_sample_3, - security_token = Sys.getenv("ENTSOE_PAT") - ) - content_4 <- api_req_safe( - query_string = url_sample_4, - security_token = Sys.getenv("ENTSOE_PAT") - ) - content_5 <- api_req_safe( - query_string = url_sample_5, - security_token = Sys.getenv("ENTSOE_PAT") - ) - testthat::expect_no_error( - object = xml_to_table( - xml_content = content_1$result, - tidy_output = TRUE - ) + m$reset() + testthat::local_mocked_bindings( + fetch_eic_csv = \(...) test_df_list[[17L]], + .package = "entsoeapi" ) - testthat::expect_no_error( + testthat::expect_equal( object = xml_to_table( - xml_content = content_2$result, + xml_content = entsoe_gen_min_xml, tidy_output = TRUE - ) + ) |> + dim(), + expected = c(2L, 21L) ) - testthat::expect_no_error( + testthat::expect_equal( object = xml_to_table( - xml_content = content_3$result, - tidy_output = TRUE - ) + xml_content = entsoe_gen_min_xml, + tidy_output = FALSE + ) |> + dim(), + expected = c(1L, 20L) ) - testthat::expect_no_error( - object = xml_to_table( - xml_content = content_4$result, - tidy_output = TRUE - ) + } +) + + +testthat::test_that( + desc = "xml_to_table() aborts on unexpected XML tree structure", + code = { + m$reset() + # Mock extract_leaf_twig_branch to throw an error + testthat::local_mocked_bindings( + extract_leaf_twig_branch = \(...) stop("simulated extraction failure"), + .package = "entsoeapi" ) testthat::expect_error( - object = xml_to_table( - xml_content = content_5$result, - tidy_output = TRUE - ), - regexp = "The 'xml_content' should be an xml document" - ) - testthat::expect_s3_class( - object = xml_to_table(xml_content = content_1$result), - class = "data.frame" - ) - testthat::expect_gt( - object = xml_to_table(xml_content = content_1$result) |> - nrow(), - expected = 0L - ) - testthat::expect_gt( - object = xml_to_table(xml_content = content_1$result) |> - ncol(), - expected = 0L + object = testthat::test_path("fixtures", "unexpected_structure.xml") |> + xml2::read_xml() |> + entsoeapi:::xml_to_table(), + regexp = "unexpected tree structure.+simulated extraction failure" ) } ) testthat::test_that( - desc = "extract_response() works 1", + desc = "extract_response() works as expected 1", code = { - content_1 <- list( - result = testthat::test_path("fixtures", "cd_catalog.xml") |> - xml2::read_xml(), - error = NULL - ) - test_df_6 <- readRDS( - file = testthat::test_path("fixtures", "test_df_list.rds") - ) |> - pluck(6) testthat::expect_error( - object = extract_response(content = content_1), - info = "There is no interesting columns in the result table!" + object = extract_response( + content = list( + result = testthat::test_path("fixtures", "cd_catalog.xml") |> + xml2::read_xml(), + error = NULL + ) + ), + regexp = "There is no interesting column in the result table" ) testthat::expect_error( - object = extract_response(content = test_df_6), - info = "The content is not in the required list format!" + object = extract_response(content = list(result = "A", error = "B")), + regexp = "\\$ operator is invalid for atomic vectors" ) testthat::expect_error( - object = extract_response(content = NULL), - info = "The argument 'tbl' is missing!" + object = extract_response(content = test_df_list[[6L]]), + regexp = "The content is not in the required list format" ) testthat::expect_error( - object = extract_response(content = list(result = "A", error = "B")), - info = paste( - "Error in extract_response(content", - "= list(result = 'A', error = 'B'))" - ) + object = extract_response(content = NULL), + regexp = "The content is not in the required list format" ) } ) testthat::test_that( - desc = "extract_response() works 2", + desc = "extract_response() works as expected 2", code = { - testthat::skip_if_not( - condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, - message = "No ENTSOE_PAT environment variable set" - ) - testthat::skip_if_not( - condition = there_is_provider(), - message = "The Entso-e API cannot be reached" - ) - url_sample_2 <- paste( - "documentType=A73", - "processType=A16", - "periodStart=202001302300", - "periodEnd=202001312300", - "in_Domain=10YDE-VE-------2", - sep = "&" - ) - url_sample_3 <- paste( - "documentType=A80", - "biddingZone_Domain=10YFR-RTE------C", - "periodStart=202407192200", - "periodEnd=202407232200", - sep = "&" - ) - url_sample_4 <- paste( - "documentType=A73", - "processType=A16", - "periodStart=202001302300", - "periodEnd=202001312300", - "in_Domain=10YDE-VE-------2", - sep = "&" - ) - content_2 <- api_req_safe( - query_string = url_sample_2, - security_token = Sys.getenv("ENTSOE_PAT") - ) - content_3 <- api_req_safe( - query_string = url_sample_3, - security_token = Sys.getenv("ENTSOE_PAT") + m$reset() + testthat::local_mocked_bindings( + fetch_eic_csv = \(...) test_df_list[[17L]], + .package = "entsoeapi" ) - content_4 <- api_req_safe( - query_string = url_sample_4, - security_token = Sys.getenv("ENTSOE_PAT") + content_ok <- list( + result = entsoe_gen_min_xml, + error = NULL ) - testthat::expect_no_error( - object = extract_response( - content = content_2, - tidy_output = TRUE - ) + testthat::expect_equal( + object = extract_response(content = content_ok, tidy_output = TRUE) |> + dim(), + expected = c(2L, 21L) ) - testthat::expect_no_error( - object = extract_response( - content = content_3, - tidy_output = FALSE - ) + testthat::expect_equal( + object = extract_response(content = content_ok, tidy_output = FALSE) |> + dim(), + expected = c(1L, 20L) ) - testthat::expect_true( - object = extract_response( - content = content_4, - tidy_output = TRUE - ) |> - inherits(what = "data.frame") + } +) + + +testthat::test_that( + desc = "extract_response() returns empty tibble for NULL result element", + code = { + content_null <- list(result = list(NULL), error = NULL) + result <- extract_response(content = content_null) + testthat::expect_s3_class(object = result, class = "tbl_df") + testthat::expect_equal(object = dim(result), expected = c(0L, 0L)) + } +) + + +testthat::test_that( + desc = "extract_response() processes a list-of-xml_documents element", + code = { + content_alldoc <- list(result = list(list(order_schema_xml)), error = NULL) + # xml_to_table on order-schema.xml fails because it has no ENTSO-E columns; + # the important thing is the all_doc branch is entered + testthat::expect_error( + object = extract_response(content = content_alldoc), + regexp = "There is no interesting column in the result table" ) } ) +testthat::test_that( + desc = "extract_response() returns empty tibble for list of non-documents", + code = { + content_nondoc <- list(result = list(list(1L, 2L, 3L)), error = NULL) + result <- extract_response(content = content_nondoc) + testthat::expect_s3_class(object = result, class = "tbl_df") + testthat::expect_equal(object = dim(result), expected = c(0L, 0L)) + } +) + + testthat::test_that( desc = paste( "get_all_allocated_eic() returns a tibble", "with expected columns on valid XML" ), code = { - xml_fixture <- readLines( - con = testthat::test_path("fixtures", "get_allocated_eic_min.xml"), - encoding = "UTF-8" - ) |> - paste(collapse = "\n") |> - charToRaw() httr2::local_mocked_responses( - mock = function(req) { + mock = \(req) { httr2::response( status_code = 200L, headers = list("content-type" = "application/xml"), - body = xml_fixture + body = get_allocated_eic_min_raw ) } ) testthat::expect_s3_class( object = tbl <- get_all_allocated_eic(), - class = "tbl_df", - exact = FALSE + class = "tbl_df" ) - testthat::expect_gt( - object = nrow(tbl), - expected = 0L + testthat::expect_equal( + object = dim(tbl), + expected = c(2L, 12L) ) testthat::expect_setequal( object = names(tbl), expected = c( - "revision_number", - "created_date_time", - "eic_code", - "doc_status_value", - "doc_status", - "instance_component_attribute", - "long_name", - "display_name", - "last_request_date", - "responsible_market_participant_mrid", - "function_names", + "revision_number", "created_date_time", "eic_code", "doc_status_value", + "doc_status", "instance_component_attribute", "long_name", + "display_name", "last_request_date", + "responsible_market_participant_mrid", "function_names", "parent_market_document_mrid" ) ) @@ -1094,41 +830,13 @@ testthat::test_that( testthat::test_that( - desc = - "get_all_allocated_eic() joins doc_status from message_types correctly", - code = { - xml_fixture <- readLines( - con = testthat::test_path("fixtures", "get_allocated_eic_min.xml"), - encoding = "UTF-8" - ) |> - paste(collapse = "\n") |> - charToRaw() - httr2::local_mocked_responses( - mock = function(req) { - httr2::response( - status_code = 200L, - headers = list("content-type" = "application/xml"), - body = xml_fixture - ) - } - ) - tbl <- get_all_allocated_eic() - # A05 is in the fixture; its title in message_types - # is "Control block area schedule" - testthat::expect_equal( - object = tbl$doc_status[[1L]], - expected = "Control block area schedule" - ) - } -) - - -testthat::test_that( - desc = - "get_all_allocated_eic() stops with HTTP error message and request URL", + desc = paste( + "get_all_allocated_eic() stops with HTTP error", + "message and request URL" + ), code = { httr2::local_mocked_responses( - mock = function(req) { + mock = \(req) { httr2::response( status_code = 503L, headers = list("content-type" = "application/xml"), @@ -1157,7 +865,7 @@ testthat::test_that( desc = "get_all_allocated_eic() stops on empty response body", code = { httr2::local_mocked_responses( - mock = function(req) { + mock = \(req) { httr2::response( status_code = 200L, headers = list("content-type" = "application/xml"), @@ -1165,7 +873,10 @@ testthat::test_that( ) } ) - testthat::expect_error(object = get_all_allocated_eic()) + testthat::expect_error( + object = get_all_allocated_eic(), + regexp = "Can't retrieve empty body" + ) } ) @@ -1173,18 +884,15 @@ testthat::test_that( testthat::test_that( desc = "get_all_allocated_eic() stops on XML with unexpected tree structure", code = { - minimal_xml <- readLines( - con = testthat::test_path("fixtures", "minimal.xml"), - encoding = "UTF-8" - ) |> - paste(collapse = "\n") |> - charToRaw() httr2::local_mocked_responses( - mock = function(req) { + mock = \(req) { httr2::response( status_code = 200L, headers = list("content-type" = "application/xml"), - body = minimal_xml + body = testthat::test_path("fixtures", "minimal.xml") |> + readLines(encoding = "UTF-8") |> + paste(collapse = "\n") |> + charToRaw() ) } ) @@ -1196,113 +904,26 @@ testthat::test_that( ) -testthat::test_that( - desc = - "get_all_allocated_eic() returns one row per EICCode_MarketDocument node", - code = { - multi_eic_xml <- readLines( - con = testthat::test_path("fixtures", "get_allocated_eic_min.xml"), - encoding = "UTF-8" - ) |> - paste(collapse = "\n") |> - charToRaw() - httr2::local_mocked_responses( - mock = function(req) { - httr2::response( - status_code = 200L, - headers = list("content-type" = "application/xml"), - body = multi_eic_xml - ) - } - ) - tbl <- get_all_allocated_eic() - testthat::expect_equal(object = nrow(tbl), expected = 2L) - testthat::expect_setequal( - object = tbl$eic_code, - expected = c("10X-TEST--EIC--1", "10X-TEST--EIC--2") - ) - } -) - - testthat::test_that( desc = "get_all_allocated_eic() collapses duplicate Function_Names with ' - '", code = { - dupl_fn_xml <- readLines( - con = testthat::test_path("fixtures", "get_allocated_eic_min.xml"), - encoding = "UTF-8" - ) |> - paste(collapse = "\n") |> - charToRaw() httr2::local_mocked_responses( - mock = function(req) { + mock = \(req) { httr2::response( status_code = 200L, headers = list("content-type" = "application/xml"), - body = dupl_fn_xml + body = get_allocated_eic_min_raw ) } ) tbl <- get_all_allocated_eic() - testthat::expect_equal(object = nrow(tbl), expected = 2L) + testthat::expect_equal(object = dim(tbl), expected = c(2L, 12L)) testthat::expect_true( - object = grepl( - pattern = " - ", - x = tbl$function_names[[1L]], - fixed = TRUE - ) - ) - } -) - - -testthat::test_that( - desc = paste( - "get_all_allocated_eic() stops with error message", - "and URL on no internet connection" - ), - code = { - curl_err <- structure( - class = c("curl_error", "error", "condition"), - list(message = paste( - "Could not resolve host:", - "eepublicdownloads.blob.core.windows.net" - )) - ) - httr2_err <- structure( - class = c("httr2_failure", "httr2_error", "error", "condition"), - list( - message = "Failed to perform HTTP request.", - resp = NULL, - parent = curl_err - ) - ) - httr2::local_mocked_responses( - mock = function(req) stop(httr2_err) - ) - testthat::expect_error( - object = get_all_allocated_eic(), - regexp = "Failed to perform HTTP request\\." - ) - testthat::expect_error( - object = get_all_allocated_eic(), - regexp = "eepublicdownloads\\.blob\\.core\\.windows\\.net" - ) - } -) - - -testthat::test_that( - desc = "tidy_or_not() stops on unknown curve_type", - code = { - test_df_13 <- readRDS( - file = testthat::test_path("fixtures", "test_df_list.rds") - ) |> - pluck(13) - testthat::expect_error( - object = tidy_or_not(tbl = test_df_13, tidy_output = TRUE), - regexp = "The curve type is not defined, but A99!" + object = tbl |> + pluck("function_names") |> + str_detect(pattern = " - ") |> + all() ) } ) @@ -1321,7 +942,7 @@ testthat::test_that( paste(collapse = "\n") |> charToRaw() httr2::local_mocked_responses( - mock = function(req) { + mock = \(req) { httr2::response( status_code = 200L, url = req$url, @@ -1333,11 +954,8 @@ testthat::test_that( tbl <- get_all_allocated_eic() testthat::expect_equal(object = nrow(tbl), expected = 1L) testthat::expect_true( - object = grepl( - pattern = "GENERATION - LOAD", - x = tbl$function_names[[1L]], - fixed = TRUE - ) + object = tbl$function_names[[1L]] |> + str_detect(pattern = "GENERATION - LOAD") ) } ) @@ -1349,23 +967,17 @@ testthat::test_that( "when bind_cols raises an error" ), code = { - xml_fixture <- readLines( - con = testthat::test_path("fixtures", "get_allocated_eic_min.xml"), - encoding = "UTF-8" - ) |> - paste(collapse = "\n") |> - charToRaw() httr2::local_mocked_responses( - mock = function(req) { + mock = \(req) { httr2::response( status_code = 200L, headers = list("content-type" = "application/xml"), - body = xml_fixture + body = get_allocated_eic_min_raw ) } ) testthat::local_mocked_bindings( - bind_cols = function(...) stop("mocked bind_cols error"), + bind_cols = \(...) stop("mocked bind_cols error"), .package = "entsoeapi" ) testthat::expect_error( @@ -1376,125 +988,11 @@ testthat::test_that( ) -testthat::test_that( - desc = "add_eic_names() adds names for additional domain mrid columns", - code = { - testthat::skip_if_not( - condition = curl::nslookup(host = .pd_domain, error = FALSE) |> - is.null() |> - isFALSE(), - message = "The Entso-e download site cannot be reached" - ) - test_df_14 <- readRDS( - file = testthat::test_path("fixtures", "test_df_list.rds") - ) |> - pluck(14) - testthat::expect_no_error( - object = result <- add_eic_names(tbl = test_df_14) - ) - testthat::expect_setequal( - object = names(result), - expected = c( - "area_domain_mrid", - "area_domain_name", - "ts_acquiring_domain_mrid", - "ts_acquiring_domain_name", - "ts_connecting_domain_mrid", - "ts_connecting_domain_name", - "bid_ts_acquiring_domain_mrid", - "bid_ts_acquiring_domain_name", - "bid_ts_connecting_domain_mrid", - "bid_ts_connecting_domain_name", - "domain_mrid", - "domain_name", - "constraint_ts_monitored_ptdf_domain_mrid", - "constraint_ts_monitored_ptdf_domain_name" - ) - ) - } -) - - -testthat::test_that( - desc = "add_definitions() unites multiple ts_reason_code columns", - code = { - test_df_15 <- readRDS( - file = testthat::test_path("fixtures", "test_df_list.rds") - ) |> - pluck(15) - testthat::expect_no_error( - object = result <- add_definitions(tbl = test_df_15) - ) - testthat::expect_contains( - object = names(result), - expected = c("ts_reason_code", "ts_reason_text") - ) - testthat::expect_true( - object = all(grepl(" - ", result$ts_reason_text, fixed = TRUE)) - ) - } -) - - -testthat::test_that( - desc = "extract_leaf_twig_branch() cross-joins unequal-group XML", - code = { - result <- readLines( - con = testthat::test_path("fixtures", "unequal_group.xml"), - encoding = "UTF-8" - ) |> - paste0(collapse = "") |> - xml2::read_xml() |> - xml2::xml_contents() |> - extract_leaf_twig_branch() - testthat::expect_equal(object = nrow(result), expected = 6L) - testthat::expect_equal(object = ncol(result), expected = 2L) - } -) - - -testthat::test_that( - desc = "extract_response() returns empty tibble for NULL result element", - code = { - content_null <- list(result = list(NULL), error = NULL) - result <- extract_response(content = content_null) - testthat::expect_s3_class(object = result, class = "tbl_df", exact = FALSE) - testthat::expect_equal(object = nrow(result), expected = 0L) - } -) - - -testthat::test_that( - desc = "extract_response() processes a list-of-xml_documents element", - code = { - xml_doc <- xml2::xml2_example(path = "order-schema.xml") |> - xml2::read_xml() - content_alldoc <- list(result = list(list(xml_doc)), error = NULL) - # xml_to_table on order-schema.xml fails because it has no ENTSO-E columns; - # the important thing is the all_doc branch is entered (lines 2037-2041) - testthat::expect_error( - object = extract_response(content = content_alldoc) - ) - } -) - - -testthat::test_that( - desc = "extract_response() returns empty tibble for list of non-documents", - code = { - content_nondoc <- list(result = list(list(1L, 2L, 3L)), error = NULL) - result <- extract_response(content = content_nondoc) - testthat::expect_s3_class(object = result, class = "tbl_df", exact = FALSE) - testthat::expect_equal(object = nrow(result), expected = 0L) - } -) - - testthat::test_that( desc = "api_req() stops on unknown 200 response content-type", code = { httr2::local_mocked_responses( - mock = function(req) { + mock = \(req) { httr2::response( status_code = 200L, url = req$url, @@ -1506,7 +1004,7 @@ testthat::test_that( testthat::expect_error( object = api_req( query_string = "documentType=A73", - security_token = "dummy_token" + security_token = .test_token ), regexp = "Not known response content-type: text/plain" ) @@ -1518,7 +1016,7 @@ testthat::test_that( desc = "api_req() stops on HTML error response", code = { httr2::local_mocked_responses( - mock = function(req) { + mock = \(req) { httr2::response( status_code = 403L, url = req$url, @@ -1529,14 +1027,15 @@ testthat::test_that( ) } ) - # The stop() message may be empty when xmlconvert::xml_to_list()|>pluck() + # The stop() message may be empty when xmlconvert::xml_to_list() |> pluck() # returns NULL for the HTML body; what matters is that the HTML error branch - # (lines 721-730) is reached and an error is thrown. + # is reached and an error is thrown. testthat::expect_error( object = api_req( query_string = "documentType=A73", - security_token = "dummy_token" - ) + security_token = .test_token + ), + regexp = "subscript out of bounds" ) } ) @@ -1545,26 +1044,25 @@ testthat::test_that( testthat::test_that( desc = "api_req() stops on XML error with unexpected Reason structure", code = { - xml_fixture <- readLines( - con = testthat::test_path("fixtures", "something_went_wrong.xml"), - encoding = "UTF-8" - ) |> - paste(collapse = "\n") |> - charToRaw() httr2::local_mocked_responses( - mock = function(req) { + mock = \(req) { httr2::response( status_code = 500L, url = req$url, headers = list("content-type" = "application/xml"), - body = xml_fixture + body = readLines( + con = testthat::test_path("fixtures", "something_went_wrong.xml"), + encoding = "UTF-8" + ) |> + paste(collapse = "\n") |> + charToRaw() ) } ) testthat::expect_error( object = api_req( query_string = "documentType=A73", - security_token = "dummy_token" + security_token = .test_token ), regexp = "^500" ) @@ -1575,26 +1073,25 @@ testthat::test_that( testthat::test_that( desc = "api_req() stops with code:text message on non-999 XML error code", code = { - xml_fixture <- readLines( - con = testthat::test_path("fixtures", "not_available.xml"), - encoding = "UTF-8" - ) |> - paste(collapse = "\n") |> - charToRaw() httr2::local_mocked_responses( - mock = function(req) { + mock = \(req) { httr2::response( status_code = 400L, url = req$url, headers = list("content-type" = "application/xml"), - body = xml_fixture + body = readLines( + con = testthat::test_path("fixtures", "not_available.xml"), + encoding = "UTF-8" + ) |> + paste(collapse = "\n") |> + charToRaw() ) } ) testthat::expect_error( object = api_req( query_string = "documentType=A73", - security_token = "dummy_token" + security_token = .test_token ), regexp = "B11" ) @@ -1605,58 +1102,135 @@ testthat::test_that( testthat::test_that( desc = "api_req() stops with curl error message on no internet connection", code = { - curl_err <- structure( - class = c("curl_error", "error", "condition"), - list(message = "Could not resolve host: web-api.tp.entsoe.eu") - ) httr2_err <- structure( class = c("httr2_failure", "httr2_error", "error", "condition"), list( message = "Failed to perform HTTP request.", resp = NULL, - parent = curl_err + parent = structure( + class = c("curl_error", "error", "condition"), + list(message = "Could not resolve host: web-api.tp.entsoe.eu") + ) ) ) httr2::local_mocked_responses( - mock = function(req) stop(httr2_err) + mock = \(req) stop(httr2_err) ) testthat::expect_error( object = api_req( - query_string = paste( + query_string = paste0( "documentType=A73", - "processType=A16", - "periodStart=202001302300", - "periodEnd=202001312300", - "in_Domain=10YDE-VE-------2", - sep = "&" + "&processType=A16", + "&periodStart=202001302300", + "&periodEnd=202001312300", + "&in_Domain=10YDE-VE-------2" ), - security_token = "dummy_token" + security_token = .test_token + ), + regexp = "Could not resolve host: web-api\\.tp\\.entsoe\\.eu" + ) + } +) + + +testthat::test_that( + desc = "api_req() stops with HTTP 503 message on service unavailable", + code = { + httr2::local_mocked_responses( + mock = \(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "text/html"), + body = charToRaw("Service Unavailable") + ) + } + ) + testthat::expect_error( + object = api_req( + query_string = "documentType=A73", + security_token = .test_token + ), + regexp = "HTTP 503" + ) + } +) + + +testthat::test_that( + desc = "api_req() extracts body text from HTML error response", + code = { + httr2::local_mocked_responses( + mock = \(req) { + httr2::response( + status_code = 400L, + url = req$url, + headers = list("content-type" = "text/html"), + body = readLines( + con = testthat::test_path("fixtures", "bad_request.xml"), + encoding = "UTF-8" + ) |> + paste(collapse = "\n") |> + charToRaw() + ) + } + ) + testthat::expect_error( + object = entsoeapi:::api_req( + query_string = "documentType=A73", + security_token = .test_token + ), + regexp = "400.*Bad Request" + ) + } +) + + +testthat::test_that( + desc = "api_req() aborts on unexpected non-200 HTTP success status", + code = { + httr2::local_mocked_responses( + mock = \(req) { + httr2::response( + status_code = 201L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw("") + ) + } + ) + testthat::expect_error( + object = entsoeapi:::api_req( + query_string = "documentType=A73", + security_token = .test_token ), - regexp = "Could not resolve host: web-api\\.tp\\.entsoe\\.eu" + regexp = "Unexpected HTTP 201" ) } ) testthat::test_that( - desc = "api_req() stops with HTTP 503 message on service unavailable", + desc = "api_req() aborts and extracts error from JSON response", code = { httr2::local_mocked_responses( - mock = function(req) { + mock = \(req) { httr2::response( - status_code = 503L, + status_code = 400L, url = req$url, - headers = list("content-type" = "text/html"), - body = charToRaw("Service Unavailable") + headers = list("content-type" = "application/json"), + body = charToRaw( + '{"uuAppErrorMap": {"URI_FORMAT_ERROR": {"message": "foo"}}}' + ) ) } ) testthat::expect_error( - object = api_req( + object = entsoeapi:::api_req( query_string = "documentType=A73", - security_token = "dummy_token" + security_token = .test_token ), - regexp = "HTTP 503" + regexp = "foo" ) } ) @@ -1666,7 +1240,7 @@ testthat::test_that( desc = "there_is_provider() returns TRUE on 401 Unauthorized", code = { httr2::local_mocked_responses( - mock = function(req) { + mock = \(req) { httr2::response( status_code = 401L, headers = list("content-type" = "text/html"), @@ -1685,7 +1259,7 @@ testthat::test_that( desc = "there_is_provider() returns FALSE on 503 Service Unavailable", code = { httr2::local_mocked_responses( - mock = function(req) { + mock = \(req) { httr2::response( status_code = 503L, headers = list("content-type" = "text/html"), @@ -1715,12 +1289,8 @@ testthat::test_that( parent = curl_err ) ) - httr2::local_mocked_responses( - mock = function(req) stop(httr2_err) - ) - testthat::expect_false( - object = there_is_provider() - ) + httr2::local_mocked_responses(mock = \(req) stop(httr2_err)) + testthat::expect_false(object = there_is_provider()) } ) @@ -1730,7 +1300,7 @@ testthat::test_that( code = { captured_url <- NULL httr2::local_mocked_responses( - mock = function(req) { + mock = \(req) { captured_url <<- req$url httr2::response( status_code = 401L, @@ -1760,21 +1330,18 @@ testthat::test_that( "there is no internet connection" ), code = { - httr2::local_mocked_responses( - mock = function(req) { - stop(structure( - class = c("httr2_failure", "httr2_error", "error", "condition"), - list( - message = "Failed to perform HTTP request.", - resp = NULL, - parent = structure( - class = c("curl_error", "error", "condition"), - list(message = "Could not connect to web-api.tp.entsoe.eu") - ) - ) - )) - } + connection_error <- structure( + class = c("httr2_failure", "httr2_error", "error", "condition"), + list( + message = "Failed to perform HTTP request.", + resp = NULL, + parent = structure( + class = c("curl_error", "error", "condition"), + list(message = "Could not connect to web-api.tp.entsoe.eu") + ) + ) ) + httr2::local_mocked_responses(mock = \(req) stop(connection_error)) testthat::expect_false(object = there_is_provider()) } ) @@ -1830,58 +1397,83 @@ testthat::test_that( testthat::test_that( - desc = "assert_eic() throws for strings with wrong length", - code = { - testthat::expect_error(object = assert_eic(eic = "")) - testthat::expect_error(object = assert_eic(eic = "10YCZ-CEPS----N")) - testthat::expect_error(object = assert_eic(eic = "10YCZ-CEPS------N")) - } -) - - -testthat::test_that( - desc = "assert_eic() throws for strings with disallowed characters", + desc = "assert_eic() respects null_ok argument", code = { - testthat::expect_error(object = assert_eic(eic = "10YCZ-CEPS----!N")) - testthat::expect_error(object = assert_eic(eic = "10ycz-ceps-----n")) + testthat::expect_invisible( + call = result <- assert_eic(eic = NULL, null_ok = TRUE) + ) + testthat::expect_null(object = result) + testthat::expect_error( + object = assert_eic(eic = NULL, null_ok = FALSE), + regexp = "Must be of type 'string', not 'NULL'" + ) } ) testthat::test_that( - desc = "assert_eic() respects null_ok argument", + desc = "check_sec_token() returns invisibly for a valid token", code = { testthat::expect_invisible( - call = result <- assert_eic(eic = NULL, null_ok = TRUE) + call = result <- entsoeapi:::check_sec_token( + security_token = .test_token + ) ) - testthat::expect_null(object = result) - testthat::expect_error(object = assert_eic(eic = NULL, null_ok = FALSE)) + testthat::expect_equal(object = result, expected = .test_token) } ) testthat::test_that( - desc = "assert_eic() uses var_name in error messages", + desc = "check_sec_token() rejects tokens containing not hexadecimals", code = { testthat::expect_error( - assert_eic(eic = "BAD-EIC-CODE----", var_name = "my_eic"), - regexp = "Invalid EIC checksum character" + object = entsoeapi:::check_sec_token( + security_token = "token?value12345678901234567890qwert" + ), + regexp = "should comply with the UUID v4 format" + ) + testthat::expect_error( + object = entsoeapi:::check_sec_token( + security_token = "" + ), + regexp = "should comply with the UUID v4 format" + ) + testthat::expect_error( + object = entsoeapi:::check_sec_token( + security_token = NA_character_ + ), + regexp = "should comply with the UUID v4 format" + ) + testthat::expect_error( + object = entsoeapi:::check_sec_token( + security_token = 12345 + ), + regexp = "should comply with the UUID v4 format" + ) + testthat::expect_error( + object = entsoeapi:::check_sec_token( + security_token = NULL + ), + regexp = "should comply with the UUID v4 format" ) testthat::expect_error( - object = assert_eic(eic = "SHORT", var_name = "my_eic"), - regexp = "All elements must have exactly 16 characters" + object = entsoeapi:::check_sec_token( + security_token = FALSE + ), + regexp = "should comply with the UUID v4 format" ) } ) -# ── pluck() ─────────────────────────────────────────────────────────────────── - testthat::test_that( desc = "pluck() extracts a nested element by name", code = { - x <- list(a = list(b = list(c = 42L))) - testthat::expect_equal(object = pluck(x, "a", "b", "c"), expected = 42L) + testthat::expect_equal( + object = list(a = list(b = list(c = 42L))) |> pluck("a", "b", "c"), + expected = 42L + ) } ) @@ -1889,8 +1481,10 @@ testthat::test_that( testthat::test_that( desc = "pluck() extracts by integer index", code = { - x <- list(list(10L, 20L), list(30L, 40L)) - testthat::expect_equal(object = pluck(x, 2L, 1L), expected = 30L) + x <- testthat::expect_equal( + object = list(list(10L, 20L), list(30L, 40L)) |> pluck(2L, 1L), + expected = 30L + ) } ) @@ -1898,76 +1492,40 @@ testthat::test_that( testthat::test_that( desc = "pluck() returns NULL when path traversal hits NULL", code = { - x <- list(a = NULL) - testthat::expect_null(object = pluck(x, "a", "b")) - } -) - - -testthat::test_that( - desc = "pluck() with no keys returns the input unchanged", - code = { - x <- list(a = 1L) - testthat::expect_equal(object = pluck(x), expected = x) - } -) - - -# ── safely() ────────────────────────────────────────────────────────────────── - -testthat::test_that( - desc = "safely() returns result and NULL error on success", - code = { - safe_sqrt <- safely(sqrt) - out <- safe_sqrt(4) - testthat::expect_equal(object = out$result, expected = 2) - testthat::expect_null(object = out$error) - } -) - - -testthat::test_that( - desc = "safely() returns NULL result and error object on failure", - code = { - safe_log <- safely(log) - out <- safe_log("not a number") - testthat::expect_null(object = out$result) - testthat::expect_s3_class(object = out$error, class = "error") + testthat::expect_null(object = list(a = NULL) |> pluck("a", "b")) } ) -# ── extract_nodesets: NULL named_vect (L289) ───────────────────────────────── - testthat::test_that( desc = "extract_nodesets() converts nodeset with no text content to NA", code = { - doc <- xml2::read_xml(x = "") - nodesets <- list(xml2::xml_find_first(x = doc, xpath = "//empty")) + nodesets <- xml2::read_xml(x = "") |> + xml2::xml_find_first(xpath = "//empty") |> + list() result <- entsoeapi:::extract_nodesets(nodesets = nodesets) testthat::expect_length(object = result, n = 1L) tbl <- result[[1L]] - testthat::expect_true(object = tibble::is_tibble(x = tbl)) - testthat::expect_true(object = all(is.na(tbl[[1L]]))) + testthat::expect_s3_class(object = tbl, class = "tbl_df") + testthat::expect_true(object = is.na(tbl[[1L]]) |> all()) } ) -# ── extract_nodesets: non-conformable column lengths ────────────── - testthat::test_that( desc = "extract_nodesets() warns on non-conformable column lengths", code = { # Build XML where unlist() produces columns of length 3 and length 2, # which are non-conformable (3 %% 2 != 0). - xml_fixture <- readLines( + nodesets <- readLines( con = testthat::test_path("fixtures", "semi_structured.xml"), encoding = "UTF-8" ) |> paste(collapse = "\n") |> charToRaw() |> - xml2::read_xml() - nodesets <- list(xml2::xml_find_first(x = xml_fixture, xpath = "//wrapper")) + xml2::read_xml() |> + xml2::xml_find_first(xpath = "//wrapper") |> + list() testthat::expect_warning( object = entsoeapi:::extract_nodesets(nodesets = nodesets), regexp = "recycling with truncation" @@ -1976,14 +1534,12 @@ testthat::test_that( ) -# ── node_to_rows: terminal node with prefix = NULL ──────────────── - testthat::test_that( desc = "node_to_rows() handles terminal node with prefix = NULL", code = { - doc <- xml2::read_xml(x = "hello") - leaf_node <- xml2::xml_find_first(x = doc, xpath = "//leaf") - result <- entsoeapi:::node_to_rows(node = leaf_node, prefix = NULL) + result <- xml2::read_xml(x = "hello") |> + xml2::xml_find_first(xpath = "//leaf") |> + entsoeapi:::node_to_rows(prefix = NULL) testthat::expect_length(object = result, n = 1L) testthat::expect_equal(object = result[[1L]], expected = c(leaf = "hello")) } @@ -1993,9 +1549,9 @@ testthat::test_that( testthat::test_that( desc = "node_to_rows() returns empty string for empty terminal node", code = { - doc <- xml2::read_xml(x = "") - leaf_node <- xml2::xml_find_first(x = doc, xpath = "//leaf") - result <- entsoeapi:::node_to_rows(node = leaf_node, prefix = NULL) + result <- xml2::read_xml(x = "") |> + xml2::xml_find_first(xpath = "//leaf") |> + entsoeapi:::node_to_rows(prefix = NULL) testthat::expect_length(object = result, n = 1L) testthat::expect_equal(object = result[[1L]], expected = c(leaf = "")) testthat::expect_equal(object = names(result[[1L]]), expected = "leaf") @@ -2009,12 +1565,12 @@ testthat::test_that( # Mock xml_text in the entsoeapi namespace to return NA, # triggering the L354 defensive branch. testthat::local_mocked_bindings( - xml_text = function(x, ...) NA, + xml_text = \(x, ...) NA, .package = "entsoeapi" ) - doc <- xml2::read_xml(x = "value") - leaf_node <- xml2::xml_find_first(x = doc, xpath = "//leaf") - result <- entsoeapi:::node_to_rows(node = leaf_node, prefix = NULL) + result <- xml2::read_xml(x = "value") |> + xml2::xml_find_first(xpath = "//leaf") |> + entsoeapi:::node_to_rows(prefix = NULL) testthat::expect_length(object = result, n = 1L) testthat::expect_true(object = is.na(result[[1L]])) testthat::expect_equal(object = names(result[[1L]]), expected = "leaf") @@ -2022,8 +1578,6 @@ testthat::test_that( ) -# ── node_to_rows: leaf with internal structure ────────── - testthat::test_that( desc = "node_to_rows() handles leaf with sub-children text nodes", code = { @@ -2035,10 +1589,9 @@ testthat::test_that( # Use a single sub-child to stay within vapply's FUN.VALUE=character(1L). compound_doc <- xml2::read_xml(x = "X") compound_children <- xml2::xml_children(x = compound_doc) - real_xml_children <- xml2::xml_children testthat::local_mocked_bindings( - xml_children = function(x, ...) { + xml_children = \(x, ...) { ch <- real_xml_children(x, ...) # When the real result is empty (leaf node named "compound"), # inject a fake sub-child to exercise the branch. @@ -2049,14 +1602,11 @@ testthat::test_that( }, .package = "entsoeapi" ) - - doc <- xml2::read_xml(x = paste0( - "", - "text", - "" - )) - parent_node <- xml2::xml_find_first(x = doc, xpath = "//parent") - result <- entsoeapi:::node_to_rows(node = parent_node, prefix = NULL) + result <- xml2::read_xml( + x = "text" + ) |> + xml2::xml_find_first(xpath = "//parent") |> + entsoeapi:::node_to_rows(prefix = NULL) testthat::expect_length(object = result, n = 1L) row <- result[[1L]] # The name should be "compound.a" and the value "X". @@ -2066,8 +1616,6 @@ testthat::test_that( ) -# ── node_to_rows: stacked_rows with nested children ────────────────── - testthat::test_that( desc = paste( "node_to_rows() uses stacked_rows[[1L]] as leaf_row", @@ -2075,16 +1623,14 @@ testthat::test_that( ), code = { # Duplicate leaf names + nested children - xml_fixture <- readLines( - con = testthat::test_path("fixtures", "duplicate_leaf_names.xml"), - encoding = "UTF-8" - ) |> + result <- testthat::test_path("fixtures", "duplicate_leaf_names.xml") |> + readLines(encoding = "UTF-8") |> paste(collapse = "\n") |> charToRaw() |> - xml2::read_xml() - parent_node <- xml2::xml_find_first(x = xml_fixture, xpath = "//parent") - result <- entsoeapi:::node_to_rows(node = parent_node, prefix = "p") - testthat::expect_true(object = length(result) >= 1L) + xml2::read_xml() |> + xml2::xml_find_first(xpath = "//parent") |> + entsoeapi:::node_to_rows(prefix = "p") + testthat::expect_true(object = length(result) == 1L) # Each row should have both val and nested.inner columns row <- result[[1L]] testthat::expect_true(object = "p.val" %in% names(row)) @@ -2093,8 +1639,6 @@ testthat::test_that( ) -# ── node_to_rows: both leaf_row and nested_rows empty ──────────────── - testthat::test_that( desc = paste( "node_to_rows() returns list() when", @@ -2108,7 +1652,7 @@ testthat::test_that( real_node_to_rows <- entsoeapi:::node_to_rows first_call <- TRUE testthat::local_mocked_bindings( - node_to_rows = function(node, prefix = NULL) { + node_to_rows = \(node, prefix = NULL) { if (first_call) { first_call <<- FALSE real_node_to_rows(node = node, prefix = prefix) @@ -2119,28 +1663,24 @@ testthat::test_that( }, .package = "entsoeapi" ) - xml_fixture <- xml2::read_xml( - x = testthat::test_path("fixtures", "empty_leaf_and_nested.xml") - ) - parent_node <- xml2::xml_find_first(x = xml_fixture, xpath = "//parent") - result <- entsoeapi:::node_to_rows(node = parent_node, prefix = "p") + result <- testthat::test_path("fixtures", "empty_leaf_and_nested.xml") |> + xml2::read_xml() |> + xml2::xml_find_first(xpath = "//parent") |> + entsoeapi:::node_to_rows(prefix = "p") testthat::expect_equal(object = result, expected = list()) } ) - -# ── node_to_rows: stacked_rows exists but nested_rows empty ────── - testthat::test_that( desc = paste( "node_to_rows() returns stacked_rows when duplicate leaf names exist", "but no nested children are present" ), code = { - xml_fixture <- testthat::test_path("fixtures", "dupl_leaf_names.xml") |> - xml2::read_xml() - parent_node <- xml2::xml_find_first(x = xml_fixture, xpath = "//parent") - result <- entsoeapi:::node_to_rows(node = parent_node, prefix = "p") + result <- testthat::test_path("fixtures", "dupl_leaf_names.xml") |> + xml2::read_xml() |> + xml2::xml_find_first(xpath = "//parent") |> + entsoeapi:::node_to_rows(prefix = "p") testthat::expect_length(object = result, n = 3L) testthat::expect_equal(object = result[[1L]], expected = c(p.val = "1")) testthat::expect_equal(object = result[[2L]], expected = c(p.val = "2")) @@ -2149,85 +1689,311 @@ testthat::test_that( ) -# ── rows_to_tbl: empty input ───────────────────────────────────────── - testthat::test_that( desc = "rows_to_tbl() returns empty tibble on empty input", code = { result <- entsoeapi:::rows_to_tbl(list()) - testthat::expect_true(object = tibble::is_tibble(result)) - testthat::expect_equal(object = nrow(result), expected = 0L) - testthat::expect_equal(object = ncol(result), expected = 0L) + testthat::expect_s3_class(object = result, class = "tbl_df") + testthat::expect_equal(object = dim(result), expected = c(0L, 0L)) } ) -# ── extract_leaf_twig_branch: both leaf and nested empty ────────────── +testthat::test_that( + desc = "check_period() returns formatted start/end for a valid period", + code = { + result <- entsoeapi:::check_period( + period_start = lubridate::ymd("2023-01-01", tz = "CET"), + period_end = lubridate::ymd("2023-12-31", tz = "CET"), + period_length = "1 year" + ) + testthat::expect_type(object = result, type = "list") + testthat::expect_named(object = result, expected = c("start", "end")) + testthat::expect_type(object = result$start, type = "character") + testthat::expect_type(object = result$end, type = "character") + } +) + testthat::test_that( - desc = paste( - "extract_leaf_twig_branch() returns empty tibble", - "when both leaf_rows and nested_all_rows are empty" - ), + desc = "check_period() aborts when period exceeds one year", code = { - result <- entsoeapi:::extract_leaf_twig_branch(nodesets = list()) - testthat::expect_true(object = tibble::is_tibble(result)) - testthat::expect_equal(object = nrow(result), expected = 0L) - testthat::expect_equal(object = ncol(result), expected = 0L) + testthat::expect_error( + object = entsoeapi:::check_period( + period_start = lubridate::ymd("2023-01-01", tz = "CET"), + period_end = lubridate::ymd("2024-01-02", tz = "CET"), + period_length = "1 year" + ), + regexp = "1 year range limit should be applied" + ) + } +) + + +testthat::test_that( + desc = "check_period() skips validation when period_length is NULL", + code = { + result <- entsoeapi:::check_period( + period_start = lubridate::ymd("2020-01-01", tz = "CET"), + period_end = lubridate::ymd("2025-01-01", tz = "CET"), + period_length = NULL + ) + testthat::expect_type(object = result, type = "list") + testthat::expect_named(object = result, expected = c("start", "end")) } ) -# ── api_req: HTML error response path ────────────────────────── +testthat::test_that( + desc = "check_period() passes when period is within day limit", + code = { + result <- entsoeapi:::check_period( + period_start = lubridate::ymd("2023-06-01", tz = "CET"), + period_end = lubridate::ymd("2023-06-02", tz = "CET"), + period_length = "1 day" + ) + testthat::expect_type(object = result, type = "list") + testthat::expect_named(object = result, expected = c("start", "end")) + } +) + testthat::test_that( - desc = "api_req() extracts body text from HTML error response", + desc = "check_period() aborts when period exceeds day limit", + code = { + testthat::expect_error( + object = entsoeapi:::check_period( + period_start = lubridate::ymd("2023-06-01", tz = "CET"), + period_end = lubridate::ymd("2023-06-03", tz = "CET"), + period_length = "1 day" + ), + regexp = "1 day range limit should be applied" + ) + } +) + + +testthat::test_that( + desc = "check_period() aborts on invalid period_length pattern", + code = { + testthat::expect_error( + object = entsoeapi:::check_period( + period_start = lubridate::ymd("2023-01-01", tz = "CET"), + period_end = lubridate::ymd("2023-06-01", tz = "CET"), + period_length = "foo" + ), + regexp = "Assertion on 'period_length' failed: Must comply to pattern" + ) + } +) + + +testthat::test_that( + desc = "check_period() aborts on missing period borders", + code = { + testthat::expect_error( + object = entsoeapi:::check_period( + period_start = NULL, + period_end = lubridate::ymd("2023-06-01", tz = "CET") + ), + regexp = "the period should have both start and end" + ) + testthat::expect_error( + object = entsoeapi:::check_period( + period_start = lubridate::ymd("2023-01-01", tz = "CET"), + period_end = NULL + ), + regexp = "the period should have both start and end" + ) + testthat::expect_error( + object = entsoeapi:::check_period( + period_start = NULL, + period_end = NULL + ), + regexp = "the period should have both start and end" + ) + } +) + + +testthat::test_that( + desc = "run_api_query() returns a tibble from a mocked XML response", + code = { + httr2::local_mocked_responses( + mock = \(req) { + httr2::response( + status_code = 200L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = testthat::test_path("fixtures", "allocated_eic_min.xml") |> + readLines(encoding = "UTF-8") |> + paste(collapse = "\n") |> + charToRaw() + ) + } + ) + testthat::expect_s3_class( + object = result <- entsoeapi:::run_api_query( + query_string = "documentType=A73", + security_token = .test_token, + tidy_output = FALSE + ), + class = "tbl_df" + ) + testthat::expect_equal(object = dim(result), expected = c(1L, 4L)) + } +) + + +testthat::test_that( + desc = "api_req() handles zip response content-type", + code = { + file_size <- testthat::test_path("fixtures", "cd_catalog_xml.zip") |> + file.size() + httr2::local_mocked_responses( + mock = \(req) { + httr2::response( + status_code = 200L, + url = req$url, + headers = list("content-type" = "application/zip"), + body = testthat::test_path("fixtures", "cd_catalog_xml.zip") |> + readBin(what = "raw", n = file_size) + ) + } + ) + result <- entsoeapi:::api_req( + query_string = "documentType=A73", + security_token = .test_token + ) + testthat::expect_type(object = result, type = "list") + } +) + + +testthat::test_that( + desc = "api_req() aborts on code-999 XML error when offset is not needed", code = { - xml_fixture <- readLines( - con = testthat::test_path("fixtures", "bad_request.xml"), - encoding = "UTF-8" - ) |> - paste(collapse = "\n") |> - charToRaw() httr2::local_mocked_responses( - mock = function(req) { + mock = \(req) { httr2::response( status_code = 400L, url = req$url, - headers = list("content-type" = "text/html"), - body = xml_fixture + headers = list("content-type" = "application/xml"), + body = testthat::test_path("fixtures", "no_data.xml") |> + readLines(encoding = "UTF-8") |> + paste(collapse = "\n") |> + charToRaw() ) } ) testthat::expect_error( object = entsoeapi:::api_req( - query_string = "documentType=A73", - security_token = "dummy_token" + query_string = "documentType=A73&processType=A16", + security_token = .test_token ), - regexp = "400.*Bad Request" + regexp = "Internal error" + ) + } +) + + +testthat::test_that( + desc = "api_req() handles code-999 offset pagination", + code = { + call_count <- 0L + httr2::local_mocked_responses( + mock = \(req) { + call_count <<- call_count + 1L + if (call_count == 1L) { + httr2::response( + status_code = 200L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = testthat::test_path("fixtures", "offset_response.xml") |> + readLines(encoding = "UTF-8") |> + paste(collapse = "\n") |> + charToRaw() + ) + } else { + httr2::response( + status_code = 200L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = entsoe_gen_min_raw + ) + } + } + ) + result <- entsoeapi:::api_req( + query_string = paste0( + "documentType=A73&processType=A16", + "&periodStart=202001302300&periodEnd=202001312300" + ), + security_token = .test_token ) + testthat::expect_type(object = result, type = "list") + testthat::expect_length(object = result, n = 2L) } ) -# ── xml_to_table: unexpected XML tree structure ───────────────── +testthat::test_that( + desc = "xml_to_table() merges start_DateAndOrTime date and time columns", + code = { + result <- testthat::test_path("fixtures", "merge_date_and_time.xml") |> + xml2::read_xml() |> + entsoeapi:::xml_to_table() + testthat::expect_s3_class(object = result, class = "tbl_df") + # date and time sub-columns should have been merged and removed + testthat::expect_false( + object = str_detect( + string = names(result), + pattern = "date_and_or_time_date|date_and_or_time_time" + ) |> + any() + ) + } +) + testthat::test_that( - desc = "xml_to_table() aborts on unexpected XML tree structure", + desc = "get_resource_object_eic() executes compute_fn on cold cache", code = { - # Mock extract_leaf_twig_branch to throw an error + m$reset() + mock_resource_tbl <- tibble::tibble( + eic_code = c("10YDE-VE-------2"), + eic_long_name = c("DE TSO") + ) testthat::local_mocked_bindings( - extract_leaf_twig_branch = function(...) { - stop("simulated extraction failure") - }, + resource_object_eic = \(...) mock_resource_tbl, .package = "entsoeapi" ) - xml_fixture <- xml2::read_xml( - x = testthat::test_path("fixtures", "unexpected_structure.xml") + result <- entsoeapi:::get_resource_object_eic() + testthat::expect_setequal( + object = names(result), + expected = c("ts_registered_resource_mrid", "ts_registered_resource_name") ) - testthat::expect_error( - object = entsoeapi:::xml_to_table(xml_content = xml_fixture), - regexp = "unexpected tree structure" + testthat::expect_s3_class(object = result, class = "tbl_df") + } +) + + +testthat::test_that( + desc = paste( + "extract_response() triggers progress bar and", + "processes xml_document list elements" + ), + code = { + m$reset() + testthat::local_mocked_bindings( + fetch_eic_csv = \(...) test_df_list[[17L]], + .package = "entsoeapi" + ) + content <- list(result = list(entsoe_gen_min_xml), error = NULL) + result <- entsoeapi:::extract_response( + content = content, + progress_bar_limit = 0L ) + testthat::expect_s3_class(object = result, class = "tbl_df") } ) diff --git a/vignettes/architecture.Rmd b/vignettes/architecture.Rmd index 8ee0fb81..8081b6d9 100644 --- a/vignettes/architecture.Rmd +++ b/vignettes/architecture.Rmd @@ -11,13 +11,25 @@ editor_options: --- ```{r setup, include = FALSE} -knitr::opts_chunk$set(echo = FALSE) +run_chunks <- identical(Sys.getenv("NOT_CRAN"), "true") && + nchar(Sys.getenv("ENTSOE_PAT")) > 0L && + entsoeapi::there_is_provider() + +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + eval = run_chunks, + fig.width = 10, + fig.height = 6, + out.width = "98%", + out.height = "98%" +) ``` ```{r load-packages} library(entsoeapi) library(cli) -library(lubridate) +suppressPackageStartupMessages(library(lubridate)) ``` ## Overview @@ -402,7 +414,7 @@ The package maintains two independent in-memory caches, both with a 1-hour maximum age: | Object | Initialised in | Caches | -|---------------------------|---------------------------|---------------------------| +|----------------|----------------------|------------------------------------------| | `m` | `R/utils.R` (top of file) | EIC name lookup tables used during XML enrichment | | `mh` | `R/en_helpers.R` (top of file) | Full EIC code tibbles downloaded by `*_eic()` functions | @@ -428,7 +440,7 @@ not user-configurable. **Via `m`** (used inside the XML-to-table engine): | Cache key | Content | -|----------------------------------------|----------------------------------------| +|---------------------------|-----------------------------------------------------| | `area_eic_name_key` | Subset of `area_eic()`: EicCode + EicLongName columns | | `resource_object_eic_name_key` | Subset of `resource_object_eic()`: EicCode + EicLongName columns | @@ -522,7 +534,7 @@ load_actual_total(eic, period_start, period_end, tidy_output = TRUE) ## 5. Configuration Reference | Setting | Value | Location | -|---------------------------|---------------------------|---------------------------| +|-------------------|-----------------------------|---------------------------------| | API base URL | `https://web-api.tp.entsoe.eu/api?` | `.api_scheme`, `.api_domain`, `.api_name` in `R/constants.R` | | HTTP method | GET | `api_req()` in `R/utils.R` | | HTTP timeout | 60 seconds (`.req_timeout`) | `R/constants.R`, applied in `api_req()` | @@ -540,7 +552,7 @@ load_actual_total(eic, period_start, period_end, tidy_output = TRUE) ## 6. Code References | Component | File | Key Symbols | -|---------------------------|---------------------------|---------------------------| +|----------------|----------------|------------------------------------------------| | Package constants | `R/constants.R` | `.api_scheme`, `.api_domain`, `.api_name`, `.req_timeout`, `.max_age` | | EIC checksum validation | `R/utils.R` | `assert_eic()`, `possible_eic_chars` | | Provider check | `R/utils.R` | `there_is_provider()` | @@ -566,7 +578,7 @@ load_actual_total(eic, period_start, period_end, tidy_output = TRUE) ## 7. Glossary | Term | Definition | -|----------------------------------------|----------------------------------------| +|------------------------|-------------------------------------------------------| | EIC | Energy Identification Code — a 16-character alphanumeric code (digits, uppercase letters, `-`) identifying market participants, bidding zones, transmission lines, etc. on the ENTSO-E platform; the 16th character is a weighted-modulo-37 checksum of the first 15 | | Document type | A 3-character ENTSO-E code (e.g., A65) identifying the category of data being requested | | Process type | A 3-character ENTSO-E code (e.g., A16) qualifying the sub-type of a document type | diff --git a/vignettes/da-price-spread-vignette.Rmd b/vignettes/da-price-spread-vignette.Rmd index e1f09142..e7ae404e 100644 --- a/vignettes/da-price-spread-vignette.Rmd +++ b/vignettes/da-price-spread-vignette.Rmd @@ -30,7 +30,7 @@ knitr::opts_chunk$set( library(entsoeapi) suppressPackageStartupMessages(library(dplyr)) suppressPackageStartupMessages(library(lubridate)) -library(kableExtra) +suppressPackageStartupMessages(library(kableExtra)) library(cli) library(ggplot2) ``` diff --git a/vignettes/getting-started.Rmd b/vignettes/getting-started.Rmd index e2e3267e..184424a2 100644 --- a/vignettes/getting-started.Rmd +++ b/vignettes/getting-started.Rmd @@ -80,8 +80,8 @@ Load the packages: library(entsoeapi) suppressPackageStartupMessages(library(dplyr)) library(cli) -library(lubridate) -library(kableExtra) +suppressPackageStartupMessages(library(lubridate)) +suppressPackageStartupMessages(library(kableExtra)) ``` ### Testing Connectivity diff --git a/vignettes/time-series-restructuring.Rmd b/vignettes/time-series-restructuring.Rmd index 09a9c6d9..ee23487c 100644 --- a/vignettes/time-series-restructuring.Rmd +++ b/vignettes/time-series-restructuring.Rmd @@ -30,8 +30,8 @@ knitr::opts_chunk$set( library(entsoeapi) suppressPackageStartupMessages(library(dplyr)) library(cli) -library(lubridate) -library(kableExtra) +suppressPackageStartupMessages(library(lubridate)) +suppressPackageStartupMessages(library(kableExtra)) library(tidyr) ``` diff --git a/vignettes/working-with-eic-codes.Rmd b/vignettes/working-with-eic-codes.Rmd index 9f5e524d..0d7025d1 100644 --- a/vignettes/working-with-eic-codes.Rmd +++ b/vignettes/working-with-eic-codes.Rmd @@ -30,8 +30,8 @@ knitr::opts_chunk$set( library(entsoeapi) suppressPackageStartupMessages(library(dplyr)) library(cli) -library(lubridate) -library(kableExtra) +suppressPackageStartupMessages(library(lubridate)) +suppressPackageStartupMessages(library(kableExtra)) ``` ## Introduction