Skip to content

Commit

Permalink
createClusterST() updated with temporary solution for api part causin…
Browse files Browse the repository at this point in the history
…g error if cluster already exist + tests
  • Loading branch information
berthetclement committed Jul 5, 2024
1 parent c428296 commit 1953166
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
11 changes: 11 additions & 0 deletions R/createClusterST.R
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,17 @@ createClusterST <- function(area,
if (is_api_study(opts)) {
# format name for API
cluster_name <- transform_name_to_id(cluster_name)

# /!\ temporary solution /!\
# as the endpoint does not return an error if the cluster already exist
if(!is_api_mocked(opts)){
cluster_exists <- check_cluster_name(area, cluster_name, add_prefix, opts)
assertthat::assert_that(cluster_exists,
msg = paste0("Cluster '",
cluster_name,
"' already exist. It can not be created."))
}

params_cluster$name <- cluster_name

cmd <- api_command_generate(
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-createClusterST.R
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ test_that("Create short-term storage cluster (new feature v8.8.0)",{
# "enabled" must be present with TRUE values default
testthat::expect_true("enabled"%in%names(read_prop))
testthat::expect_true(read_prop$enabled[1]%in%TRUE)

deleteStudy()
})


Expand Down
38 changes: 38 additions & 0 deletions tests/testthat/test-editClusterST.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

# v860 ----
test_that("edit st-storage clusters (only for study >= v8.6.0" , {
# global params for structure v8.6 ----
opts_test <-createStudy(path = tempdir(),
Expand Down Expand Up @@ -236,3 +237,40 @@ test_that("API Command test for editClusterST", {
names_file_list))
})

# v880 ----
test_that("Edit short-term storage cluster (new feature v8.8.0)",{
## basics errors cases ----
suppressWarnings(
createStudy(path = tempdir(),
study_name = "st-storage880",
antares_version = "8.8.0"))

# default area with st cluster
area_test_clust = "al"
createArea(name = area_test_clust)

# default
createClusterST(area = area_test_clust,
cluster_name = "default")

# edit
list_params <- storage_values_default()
list_params$efficiency <- 0.5
list_params$reservoircapacity <- 50
list_params$enabled <- FALSE

editClusterST(area = area_test_clust,
cluster_name = "default",
storage_parameters = list_params)

# read properties
st_params <- readClusterSTDesc()

# "enabled" must be present
testthat::expect_true("enabled"%in%names(st_params))
testthat::expect_true(st_params$enabled[1]%in%FALSE)

deleteStudy()
})


0 comments on commit 1953166

Please sign in to comment.