Skip to content

Commit

Permalink
Merge pull request #545 from OuhscBbmc/dev
Browse files Browse the repository at this point in the history
tests on multiple servers
  • Loading branch information
wibeasley authored Oct 17, 2024
2 parents a7a9175 + dcdcd24 commit d6df830
Show file tree
Hide file tree
Showing 35 changed files with 338 additions and 217 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ These features are not yet on CRAN. Install with `remotes::install_github("Ouhs

### Minor Enhancements

* Redirection layer for test suite allows you to plug in your own server (#539)
* Redirection layer for test suite allows you to plug in your own server (#539, #542, #544)

Version 1.2.0 (released 2024-09-08)
==========================================================
Expand Down
57 changes: 54 additions & 3 deletions R/helpers-testing.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
retrieve_credential_testing <- function(project_tag = "simple", server_instance = "dev-2", username = NA_character_) {
retrieve_credential_testing <- function(
project_tag = "simple",
username = NA_character_
) {
checkmate::assert_character(project_tag , any.missing = FALSE, min.chars = 2, max.chars = 50)
checkmate::assert_character(server_instance , any.missing = FALSE, min.chars = 2, max.chars = 50)
checkmate::assert_character(username , any.missing = TRUE , min.chars = 2, max.chars = 50)

server_instance <-
# if(Sys.getenv("redcapr_test_server") != "") {
Sys.getenv("redcapr_test_server")
# } else {
# "dev-2"
# }
checkmate::assert_character(server_instance , any.missing = FALSE, min.chars = 2, max.chars = 50)

# This line avoids a warning from the package check.
projects <- project_id <- instance <- tag <- NULL

Expand Down Expand Up @@ -49,7 +59,49 @@ retrieve_credential_testing <- function(project_tag = "simple", server_instance
username = username
)
}
retrieve_plugins <- function(plugin_name) {
checkmate::assert_character(plugin_name , any.missing = FALSE, min.chars = 2, max.chars = 50)

server_instance <-
# if(Sys.getenv("redcapr_test_server") != "") {
Sys.getenv("redcapr_test_server")
# } else {
# "dev-2"
# }
checkmate::assert_character(server_instance , any.missing = FALSE, min.chars = 2, max.chars = 50)

# This line avoids a warning from the package check.
plugins <- instance <- tag <- project_tag <- NULL

if (!requireNamespace("yaml", quietly = TRUE)) {
stop(
"Package `yaml` must be installed to use this function.",
call. = FALSE
)
}
d_map <-
system.file("misc/plugin-redirection.yml", package = "REDCapR") |>
yaml::yaml.load_file(
handlers = list(map = \(x) tibble::as_tibble(x))
) |>
dplyr::bind_rows() |>
tidyr::unnest(plugins) |>
tidyr::pivot_longer(
cols = -c("instance"),
names_to = "tag",
values_to = "url"
) |>
tidyr::drop_na(url) |>
dplyr::filter(instance == server_instance) |>
dplyr::filter(tag == plugin_name)

if (nrow(d_map) == 0L) {
stop("A plugin mapping entry does not exist for the desired arguments.")
}

d_map |>
dplyr::pull(url)
}
# This function isn't used during testing itself. Just to create the expected file.
save_expected <- function(o, path) {
# nocov start
Expand All @@ -60,7 +112,6 @@ save_expected <- function(o, path) {
dput(o, path)
# nocov end
}

retrieve_expected <- function(path) {
full_path <- system.file(path, package = "REDCapR")
if (!file.exists(full_path))
Expand Down
5 changes: 3 additions & 2 deletions R/project-dag-write.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ clear_project_dag_write <- function(verbose = FALSE) {
)
# nocov end
}
path_delete_test_record <-
"https://redcap-dev-2.ouhsc.edu/redcap/plugins/redcapr/delete_redcapr_dag_write.php"

path_delete_test_record <- retrieve_plugins("delete_dag")
# "https://redcap-dev-2.ouhsc.edu/redcap/plugins/redcapr/delete_redcapr_dag_write.php"

# Returns a boolean value if successful
was_successful <- !httr::http_error(path_delete_test_record)
Expand Down
7 changes: 4 additions & 3 deletions R/project-delete-multiple-arm.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ populate_project_delete_multiple_arm <- function(verbose = FALSE) {
token = credential$token
)
path_in <- system.file(
"test-data/delete-multiple-arm/data.csv",
"test-data/projects/arm-multiple-delete/data.csv",
# "test-data/delete-multiple-arm/data.csv",
package = "REDCapR"
)

Expand Down Expand Up @@ -63,8 +64,8 @@ clear_project_delete_multiple_arm <- function(verbose = TRUE) {
)
# nocov end
}
path_delete_test_record <-
"https://redcap-dev-2.ouhsc.edu/redcap/plugins/redcapr/delete_redcapr_delete_multiple_arm.php"
path_delete_test_record <- retrieve_plugins("delete_arm_multiple")
# "https://redcap-dev-2.ouhsc.edu/redcap/plugins/redcapr/delete_redcapr_delete_multiple_arm.php"

# Returns a boolean value if successful
was_successful <- !httr::http_error(path_delete_test_record)
Expand Down
7 changes: 4 additions & 3 deletions R/project-delete-single-arm.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ populate_project_delete_single_arm <- function(verbose = FALSE) {
token = credential$token
)
path_in <- system.file(
"test-data/delete-single-arm/data.csv",
"test-data/projects/arm-single-delete/data.csv",
# "test-data/delete-single-arm/data.csv",
package = "REDCapR"
)

Expand Down Expand Up @@ -63,8 +64,8 @@ clear_project_delete_single_arm <- function(verbose = FALSE) {
)
# nocov end
}
path_delete_test_record <-
"https://redcap-dev-2.ouhsc.edu/redcap/plugins/redcapr/delete_redcapr_delete_single_arm.php"
path_delete_test_record <- retrieve_plugins("delete_arm_single")
# "https://redcap-dev-2.ouhsc.edu/redcap/plugins/redcapr/delete_redcapr_delete_single_arm.php"

# Returns a boolean value if successful
was_successful <- !httr::http_error(path_delete_test_record)
Expand Down
4 changes: 2 additions & 2 deletions R/project-simple.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ clear_project_simple <- function(verbose = TRUE) {
)
# nocov end
}
path_delete_test_record <-
"https://redcap-dev-2.ouhsc.edu/redcap/plugins/redcapr/delete_redcapr_simple.php"
path_delete_test_record <- retrieve_plugins("delete_simple")
# "https://redcap-dev-2.ouhsc.edu/redcap/plugins/redcapr/delete_redcapr_simple.php"

# Returns a boolean value if successful
was_successful <- !httr::http_error(path_delete_test_record)
Expand Down
3 changes: 0 additions & 3 deletions R/retrieve-credential.R
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,6 @@ credential_local_validation <- function(
}
}

# system.file("misc/vignette.css", package="REDCapR")
# system.file("misc/dev-2.credentials", package="REDCapR")

#' @export
create_credential_local <- function(path_credential) {
path_source <- system.file(
Expand Down
15 changes: 15 additions & 0 deletions inst/misc/plugin-redirection.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-
instance: bbmc
plugins:
- delete_simple : "https://bbmc.ouhsc.edu/redcap/plugins/redcapr/delete_redcapr_simple.php"
- delete_arm_single : "https://bbmc.ouhsc.edu/redcap/plugins/redcapr/delete_redcapr_delete_single_arm.php"
- delete_arm_multiple : "https://bbmc.ouhsc.edu/redcap/plugins/redcapr/delete_redcapr_delete_multiple_arm.php"
- delete_dag : "https://bbmc.ouhsc.edu/redcap/plugins/redcapr/delete_redcapr_dag_write.php"

-
instance: dev-2
plugins:
- delete_simple : "https://redcap-dev-2.ouhsc.edu/redcap/plugins/redcapr/delete_redcapr_simple.php"
- delete_arm_single : "https://redcap-dev-2.ouhsc.edu/redcap/plugins/redcapr/delete_redcapr_delete_single_arm.php"
- delete_arm_multiple : "https://redcap-dev-2.ouhsc.edu/redcap/plugins/redcapr/delete_redcapr_delete_multiple_arm.php"
- delete_dag : "https://redcap-dev-2.ouhsc.edu/redcap/plugins/redcapr/delete_redcapr_dag_write.php"
9 changes: 6 additions & 3 deletions inst/test-data/projects/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Test Projects

Steps to recreate on a fresh server

1. Create two accounts for testing.
The names shouldn't matter, but we named them 'unittestphifree' and 'unittestphifree-dag1'.
Table-based accounts are probably easiest.
1. Create two accounts for testing:
Table-based accounts are probably easiest.
Tests are case-sensitive.
1. 'unittestphifree': First name = "Unit Test"; Last name "Phi Free".
1. 'unittestphifree-dag1': First name = "Unit Test"; Last name "PHI Free DAG1"
1. Install plugins
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,61 +1,57 @@
record_id,redcap_event_name,birth_date,position,demographics_complete
101,event_1_arm_1,2020-05-01,pg,2
102,event_1_arm_1,2020-06-01,sg,2
103,event_1_arm_1,2020-07-01,sf,2
104,event_1_arm_1,2020-08-01,pf,2
105,event_1_arm_1,2020-09-01,c,2
106,event_1_arm_1,2020-10-01,pg,2
107,event_1_arm_1,2020-11-01,sg,2
108,event_1_arm_1,2020-12-01,sf,2
109,event_1_arm_1,2021-01-01,pf,2
110,event_1_arm_1,2021-02-01,c,2
111,event_1_arm_1,2021-03-01,pg,2
112,event_1_arm_1,2021-04-01,sg,2
113,event_1_arm_1,2021-05-01,sf,2
114,event_1_arm_1,2021-06-01,pf,2
115,event_1_arm_1,2021-07-01,c,2
116,event_1_arm_1,2021-08-01,pg,2
117,event_1_arm_1,2021-09-01,sg,2
118,event_1_arm_1,2021-10-01,sf,2
119,event_1_arm_1,2021-11-01,pf,2
120,event_1_arm_1,2021-12-01,c,2
101,event_1_arm_2,2020-05-01,pg,2
102,event_1_arm_2,2020-06-01,sg,2
103,event_1_arm_2,2020-07-01,sf,2
104,event_1_arm_2,2020-08-01,pf,2
105,event_1_arm_2,2020-09-01,c,2
106,event_1_arm_2,2020-10-01,pg,2
107,event_1_arm_2,2020-11-01,sg,2
108,event_1_arm_2,2020-12-01,sf,2
109,event_1_arm_2,2021-01-01,pf,2
110,event_1_arm_2,2021-02-01,c,2
111,event_1_arm_2,2021-03-01,pg,2
112,event_1_arm_2,2021-04-01,sg,2
113,event_1_arm_2,2021-05-01,sf,2
114,event_1_arm_2,2021-06-01,pf,2
115,event_1_arm_2,2021-07-01,c,2
116,event_1_arm_2,2021-08-01,pg,2
117,event_1_arm_2,2021-09-01,sg,2
118,event_1_arm_2,2021-10-01,sf,2
119,event_1_arm_2,2021-11-01,pf,2
120,event_1_arm_2,2021-12-01,c,2
101,event_1_arm_3,2020-05-01,pg,2
102,event_1_arm_1,2020-06-01,sg,2
102,event_1_arm_3,2020-06-01,sg,2
103,event_1_arm_1,2020-07-01,sf,2
103,event_1_arm_3,2020-07-01,sf,2
104,event_1_arm_1,2020-08-01,pf,2
104,event_1_arm_2,2020-08-01,pf,2
104,event_1_arm_3,2020-08-01,pf,2
105,event_1_arm_1,2020-09-01,c,2
105,event_1_arm_3,2020-09-01,c,2
106,event_1_arm_1,2020-10-01,pg,2
106,event_1_arm_2,2020-10-01,pg,2
106,event_1_arm_3,2020-10-01,pg,2
107,event_1_arm_1,2020-11-01,sg,2
107,event_1_arm_2,2020-11-01,sg,2
107,event_1_arm_3,2020-11-01,sg,2
108,event_1_arm_1,2020-12-01,sf,2
108,event_1_arm_2,2020-12-01,sf,2
108,event_1_arm_3,2020-12-01,sf,2
109,event_1_arm_1,2021-01-01,pf,2
109,event_1_arm_2,2021-01-01,pf,2
109,event_1_arm_3,2021-01-01,pf,2
110,event_1_arm_1,2021-02-01,c,2
110,event_1_arm_2,2021-02-01,c,2
110,event_1_arm_3,2021-02-01,c,2
111,event_1_arm_1,2021-03-01,pg,2
111,event_1_arm_2,2021-03-01,pg,2
111,event_1_arm_3,2021-03-01,pg,2
112,event_1_arm_1,2021-04-01,sg,2
112,event_1_arm_2,2021-04-01,sg,2
112,event_1_arm_3,2021-04-01,sg,2
113,event_1_arm_1,2021-05-01,sf,2
113,event_1_arm_2,2021-05-01,sf,2
113,event_1_arm_3,2021-05-01,sf,2
114,event_1_arm_1,2021-06-01,pf,2
114,event_1_arm_2,2021-06-01,pf,2
114,event_1_arm_3,2021-06-01,pf,2
115,event_1_arm_1,2021-07-01,c,2
115,event_1_arm_2,2021-07-01,c,2
115,event_1_arm_3,2021-07-01,c,2
116,event_1_arm_1,2021-08-01,pg,2
116,event_1_arm_2,2021-08-01,pg,2
116,event_1_arm_3,2021-08-01,pg,2
117,event_1_arm_1,2021-09-01,sg,2
117,event_1_arm_2,2021-09-01,sg,2
117,event_1_arm_3,2021-09-01,sg,2
118,event_1_arm_1,2021-10-01,sf,2
118,event_1_arm_2,2021-10-01,sf,2
118,event_1_arm_3,2021-10-01,sf,2
119,event_1_arm_1,2021-11-01,pf,2
119,event_1_arm_2,2021-11-01,pf,2
119,event_1_arm_3,2021-11-01,pf,2
120,event_1_arm_1,2021-12-01,c,2
120,event_1_arm_3,2021-12-01,c,2
72 changes: 38 additions & 34 deletions inst/test-data/projects/arm-multiple-delete/data.csv
Original file line number Diff line number Diff line change
@@ -1,57 +1,61 @@
record_id,redcap_event_name,birth_date,position,demographics_complete
101,event_1_arm_1,2020-05-01,pg,2
101,event_1_arm_2,2020-05-01,pg,2
101,event_1_arm_3,2020-05-01,pg,2
102,event_1_arm_1,2020-06-01,sg,2
102,event_1_arm_3,2020-06-01,sg,2
103,event_1_arm_1,2020-07-01,sf,2
103,event_1_arm_3,2020-07-01,sf,2
104,event_1_arm_1,2020-08-01,pf,2
104,event_1_arm_2,2020-08-01,pf,2
104,event_1_arm_3,2020-08-01,pf,2
105,event_1_arm_1,2020-09-01,c,2
105,event_1_arm_3,2020-09-01,c,2
106,event_1_arm_1,2020-10-01,pg,2
106,event_1_arm_2,2020-10-01,pg,2
106,event_1_arm_3,2020-10-01,pg,2
107,event_1_arm_1,2020-11-01,sg,2
107,event_1_arm_2,2020-11-01,sg,2
107,event_1_arm_3,2020-11-01,sg,2
108,event_1_arm_1,2020-12-01,sf,2
108,event_1_arm_2,2020-12-01,sf,2
108,event_1_arm_3,2020-12-01,sf,2
109,event_1_arm_1,2021-01-01,pf,2
109,event_1_arm_2,2021-01-01,pf,2
109,event_1_arm_3,2021-01-01,pf,2
110,event_1_arm_1,2021-02-01,c,2
110,event_1_arm_2,2021-02-01,c,2
110,event_1_arm_3,2021-02-01,c,2
111,event_1_arm_1,2021-03-01,pg,2
111,event_1_arm_2,2021-03-01,pg,2
111,event_1_arm_3,2021-03-01,pg,2
112,event_1_arm_1,2021-04-01,sg,2
112,event_1_arm_2,2021-04-01,sg,2
112,event_1_arm_3,2021-04-01,sg,2
113,event_1_arm_1,2021-05-01,sf,2
113,event_1_arm_2,2021-05-01,sf,2
113,event_1_arm_3,2021-05-01,sf,2
114,event_1_arm_1,2021-06-01,pf,2
114,event_1_arm_2,2021-06-01,pf,2
114,event_1_arm_3,2021-06-01,pf,2
115,event_1_arm_1,2021-07-01,c,2
115,event_1_arm_2,2021-07-01,c,2
115,event_1_arm_3,2021-07-01,c,2
116,event_1_arm_1,2021-08-01,pg,2
116,event_1_arm_2,2021-08-01,pg,2
116,event_1_arm_3,2021-08-01,pg,2
117,event_1_arm_1,2021-09-01,sg,2
117,event_1_arm_2,2021-09-01,sg,2
117,event_1_arm_3,2021-09-01,sg,2
118,event_1_arm_1,2021-10-01,sf,2
118,event_1_arm_2,2021-10-01,sf,2
118,event_1_arm_3,2021-10-01,sf,2
119,event_1_arm_1,2021-11-01,pf,2
120,event_1_arm_1,2021-12-01,c,2
101,event_1_arm_2,2020-05-01,pg,2
102,event_1_arm_2,2020-06-01,sg,2
103,event_1_arm_2,2020-07-01,sf,2
104,event_1_arm_2,2020-08-01,pf,2
105,event_1_arm_2,2020-09-01,c,2
106,event_1_arm_2,2020-10-01,pg,2
107,event_1_arm_2,2020-11-01,sg,2
108,event_1_arm_2,2020-12-01,sf,2
109,event_1_arm_2,2021-01-01,pf,2
110,event_1_arm_2,2021-02-01,c,2
111,event_1_arm_2,2021-03-01,pg,2
112,event_1_arm_2,2021-04-01,sg,2
113,event_1_arm_2,2021-05-01,sf,2
114,event_1_arm_2,2021-06-01,pf,2
115,event_1_arm_2,2021-07-01,c,2
116,event_1_arm_2,2021-08-01,pg,2
117,event_1_arm_2,2021-09-01,sg,2
118,event_1_arm_2,2021-10-01,sf,2
119,event_1_arm_2,2021-11-01,pf,2
120,event_1_arm_2,2021-12-01,c,2
101,event_1_arm_3,2020-05-01,pg,2
102,event_1_arm_3,2020-06-01,sg,2
103,event_1_arm_3,2020-07-01,sf,2
104,event_1_arm_3,2020-08-01,pf,2
105,event_1_arm_3,2020-09-01,c,2
106,event_1_arm_3,2020-10-01,pg,2
107,event_1_arm_3,2020-11-01,sg,2
108,event_1_arm_3,2020-12-01,sf,2
109,event_1_arm_3,2021-01-01,pf,2
110,event_1_arm_3,2021-02-01,c,2
111,event_1_arm_3,2021-03-01,pg,2
112,event_1_arm_3,2021-04-01,sg,2
113,event_1_arm_3,2021-05-01,sf,2
114,event_1_arm_3,2021-06-01,pf,2
115,event_1_arm_3,2021-07-01,c,2
116,event_1_arm_3,2021-08-01,pg,2
117,event_1_arm_3,2021-09-01,sg,2
118,event_1_arm_3,2021-10-01,sf,2
119,event_1_arm_3,2021-11-01,pf,2
120,event_1_arm_1,2021-12-01,c,2
120,event_1_arm_3,2021-12-01,c,2
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
record_id,birth_date,position,demographics_complete
101,2020-05-01,pg,2
102,2020-06-01,sg,2
103,2020-07-01,sf,2
104,2020-08-01,pf,2
105,2020-09-01,c,2
106,2020-10-01,pg,2
107,2020-11-01,sg,2
108,2020-12-01,sf,2
Expand All @@ -18,4 +15,3 @@ record_id,birth_date,position,demographics_complete
117,2021-09-01,sg,2
118,2021-10-01,sf,2
119,2021-11-01,pf,2
120,2021-12-01,c,2
Loading

0 comments on commit d6df830

Please sign in to comment.