-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #551 from OuhscBbmc/dev
add tests for `redcap_file_repo_list()`
- Loading branch information
Showing
13 changed files
with
383 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
file-repo Test Project | ||
========= | ||
|
||
Steps to Recreate: | ||
|
||
1. Create new project, based on project.xml | ||
1. Reconstruct the file repository, manually | ||
1. Create top-level directory called "the-state" | ||
1. Drop [levon-and-barry.jpg](../../levon-and-barry.jpg) into this directory | ||
1. Navigate back to the root directory. | ||
1. Drop the following file files into the root directory: | ||
1. [mugshot-1.jpg](../../mugshot-1.jpg) | ||
1. [mugshot-2.jpg](../../mugshot-2.jpg) | ||
1. [mugshot-3.jpg](../../mugshot-3.jpg) | ||
1. [mugshot-4.jpg](../../mugshot-4.jpg) | ||
1. [mugshot-5.jpg](../../mugshot-5.jpg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
record_id,redcap_survey_identifier,form_1_timestamp,name,date,signature,form_1_complete | ||
1,,"2024-10-25 10:16:01",Scissors,2024-10-25,signature_2024-10-25_1015.png,2 | ||
2,,"2024-10-25 10:17:24",Paper,2024-10-25,signature_2024-10-25_1017.png,2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"Variable / Field Name","Form Name","Section Header","Field Type","Field Label","Choices, Calculations, OR Slider Labels","Field Note","Text Validation Type OR Show Slider Number","Text Validation Min","Text Validation Max",Identifier?,"Branching Logic (Show field only if...)","Required Field?","Custom Alignment","Question Number (surveys only)","Matrix Group Name","Matrix Ranking?","Field Annotation" | ||
record_id,form_1,,text,"Record ID",,,,,,,,,,,,, | ||
consent_01,form_1,,descriptive,,,,,,,,,,,,,, | ||
name,form_1,,text,Name,,,,,,,,,,,,, | ||
date,form_1,,text,Date,,,date_ymd,,,,,,,,,," @TODAY" | ||
signature,form_1,,file,Signature,,,signature,,,,,,,,,, |
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
inst/test-data/specific-redcapr/file-repo-list-oneshot/bad-folder-id.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
structure(list(), class = c("tbl_df", "tbl", "data.frame"), row.names = integer(0), names = character(0)) |
10 changes: 10 additions & 0 deletions
10
inst/test-data/specific-redcapr/file-repo-list-oneshot/default.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
structure(list(folder_id = c(1L, NA, NA, NA, NA, NA), doc_id = c(NA, | ||
6652L, 6653L, 6654L, 6655L, 6656L), name = c("the-state", "mugshot-1.jpg", | ||
"mugshot-2.jpg", "mugshot-3.jpg", "mugshot-4.jpg", "mugshot-5.jpg" | ||
)), row.names = c(NA, -6L), spec = structure(list(cols = list( | ||
folder_id = structure(list(), class = c("collector_integer", | ||
"collector")), doc_id = structure(list(), class = c("collector_integer", | ||
"collector")), name = structure(list(), class = c("collector_character", | ||
"collector"))), default = structure(list(), class = c("collector_guess", | ||
"collector")), delim = ","), class = "col_spec"), class = c("spec_tbl_df", | ||
"tbl_df", "tbl", "data.frame")) |
7 changes: 7 additions & 0 deletions
7
inst/test-data/specific-redcapr/file-repo-list-oneshot/first-subdirectory.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
structure(list(folder_id = NA_integer_, doc_id = 6651L, name = "levon-and-barry.jpg"), row.names = c(NA, | ||
-1L), spec = structure(list(cols = list(folder_id = structure(list(), class = c("collector_integer", | ||
"collector")), doc_id = structure(list(), class = c("collector_integer", | ||
"collector")), name = structure(list(), class = c("collector_character", | ||
"collector"))), default = structure(list(), class = c("collector_guess", | ||
"collector")), delim = ","), class = "col_spec"), class = c("spec_tbl_df", | ||
"tbl_df", "tbl", "data.frame")) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
library(testthat) | ||
|
||
credential <- retrieve_credential_testing("file-repo") | ||
update_expectation <- FALSE | ||
|
||
test_that("smoke test", { | ||
testthat::skip_on_cran() | ||
expected_message <- "The file repository structure describing 6 elements was read from REDCap in [0-9.]+ seconds\\. The http status code was 200\\." | ||
|
||
suppressMessages({ | ||
expect_message( | ||
redcap_file_repo_list_oneshot( | ||
redcap_uri = credential$redcap_uri, | ||
token = credential$token | ||
), | ||
expected_message | ||
) | ||
}) | ||
}) | ||
test_that("default", { | ||
testthat::skip_on_cran() | ||
expected_message <- "The file repository structure describing 6 elements was read from REDCap in [0-9.]+ seconds\\. The http status code was 200\\." | ||
|
||
path_expected <- "test-data/specific-redcapr/file-repo-list-oneshot/default.R" | ||
|
||
suppressMessages({ | ||
expect_message( | ||
returned_object <- | ||
redcap_file_repo_list_oneshot( | ||
redcap_uri = credential$redcap_uri, | ||
token = credential$token | ||
), | ||
expected_message | ||
) | ||
}) | ||
|
||
if (update_expectation) save_expected(returned_object$data, path_expected) | ||
expected_data_frame <- retrieve_expected(path_expected) | ||
|
||
#Test the values of the returned object. | ||
if (credential$redcap_uri == "https://redcap-dev-2.ouhsc.edu/redcap/api/") { | ||
expect_equal(returned_object$data, expected=expected_data_frame, label="The returned data.frame should be correct", ignore_attr = TRUE) # dput(returned_object$data) | ||
} | ||
|
||
expect_equal(nrow(returned_object$data), expected=6L) | ||
expect_equal(returned_object$data$name, expected_data_frame$name) | ||
expect_equal(class(returned_object$data$folder_id), "integer") | ||
expect_equal(class(returned_object$data$doc_id ), "integer") | ||
expect_equal( | ||
!is.na(returned_object$data$folder_id), | ||
c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) | ||
) | ||
expect_equal( | ||
!is.na(returned_object$data$doc_id), | ||
c(FALSE, TRUE, TRUE, TRUE, TRUE, TRUE) | ||
) | ||
|
||
expect_true(returned_object$success) | ||
expect_equal(returned_object$status_code, expected=200L) | ||
expect_match(returned_object$outcome_message, regexp=expected_message, perl=TRUE) | ||
expect_true(returned_object$elapsed_seconds>0, "The `elapsed_seconds` should be a positive number.") | ||
expect_equal(returned_object$raw_text, expected="", ignore_attr = TRUE) # dput(returned_object$raw_text) | ||
}) | ||
test_that("first-subdirectory", { | ||
testthat::skip_on_cran() | ||
|
||
if (credential$redcap_uri != "https://redcap-dev-2.ouhsc.edu/redcap/api/") { | ||
testthat::skip("The `folder_id` will be different on different servers.") | ||
} | ||
|
||
expected_message <- "The file repository structure describing 1 elements was read from REDCap in [0-9.]+ seconds\\. The http status code was 200\\." | ||
|
||
path_expected <- "test-data/specific-redcapr/file-repo-list-oneshot/first-subdirectory.R" | ||
|
||
suppressMessages({ | ||
expect_message( | ||
returned_object <- | ||
redcap_file_repo_list_oneshot( | ||
redcap_uri = credential$redcap_uri, | ||
token = credential$token, | ||
folder_id = 1 | ||
), | ||
expected_message | ||
) | ||
}) | ||
|
||
if (update_expectation) save_expected(returned_object$data, path_expected) | ||
expected_data_frame <- retrieve_expected(path_expected) | ||
|
||
#Test the values of the returned object. | ||
expect_equal(returned_object$data, expected=expected_data_frame, label="The returned data.frame should be correct", ignore_attr = TRUE) # dput(returned_object$data) | ||
|
||
expect_equal(nrow(returned_object$data), expected=1L) | ||
expect_equal(returned_object$data$name, expected_data_frame$name) | ||
expect_equal(class(returned_object$data$folder_id), "integer") | ||
expect_equal(class(returned_object$data$doc_id ), "integer") | ||
expect_equal( | ||
!is.na(returned_object$data$folder_id), | ||
c(FALSE) | ||
) | ||
expect_equal( | ||
!is.na(returned_object$data$doc_id), | ||
c(TRUE) | ||
) | ||
|
||
expect_true(returned_object$success) | ||
expect_equal(returned_object$status_code, expected=200L) | ||
expect_match(returned_object$outcome_message, regexp=expected_message, perl=TRUE) | ||
expect_true(returned_object$elapsed_seconds>0, "The `elapsed_seconds` should be a positive number.") | ||
expect_equal(returned_object$raw_text, expected="", ignore_attr = TRUE) # dput(returned_object$raw_text) | ||
}) | ||
test_that("bad-folder-id", { | ||
testthat::skip_on_cran() | ||
expected_message <- "ERROR: The File Repository folder folder_id=99 does not exist or else you do not have permission to that folder because it is DAG-restricted or Role-restricted." | ||
|
||
path_expected <- "test-data/specific-redcapr/file-repo-list-oneshot/bad-folder-id.R" | ||
|
||
suppressMessages({ | ||
expect_message( | ||
returned_object <- | ||
redcap_file_repo_list_oneshot( | ||
redcap_uri = credential$redcap_uri, | ||
token = credential$token, | ||
folder_id = 99 | ||
), | ||
expected_message | ||
) | ||
}) | ||
|
||
if (update_expectation) save_expected(returned_object$data, path_expected) | ||
expected_data_frame <- retrieve_expected(path_expected) | ||
|
||
#Test the values of the returned object. | ||
if (credential$redcap_uri == "https://redcap-dev-2.ouhsc.edu/redcap/api/") { | ||
expect_equal(returned_object$data, expected=expected_data_frame, label="The returned data.frame should be correct", ignore_attr = TRUE) # dput(returned_object$data) | ||
} | ||
|
||
expect_equal(nrow(returned_object$data), expected=0L) | ||
|
||
expect_false(returned_object$success) | ||
expect_equal(returned_object$status_code, expected=400L) | ||
expect_match(returned_object$outcome_message, regexp=expected_message, perl=TRUE) | ||
expect_true(returned_object$elapsed_seconds>0, "The `elapsed_seconds` should be a positive number.") | ||
expect_equal(returned_object$raw_text, expected=expected_message, ignore_attr = TRUE) # dput(returned_object$raw_text) | ||
}) | ||
test_that("download w/ bad token -Error", { | ||
testthat::skip_on_cran() | ||
|
||
returned_object <- | ||
redcap_file_repo_list_oneshot( | ||
redcap_uri = credential$redcap_uri, | ||
token = "BAD00000000000000000000000000000", | ||
verbose = FALSE | ||
) | ||
|
||
expected_data <- structure(list(), class = c("tbl_df", "tbl", "data.frame"), row.names = integer(0), names = character(0)) | ||
testthat::expect_equal(returned_object$data, expected_data) | ||
|
||
testthat::expect_false(returned_object$success) | ||
testthat::expect_equal(returned_object$status_code, 403L) | ||
testthat::expect_equal(returned_object$raw_text, "ERROR: You do not have permissions to use the API") | ||
}) | ||
|
||
rm(credential) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters