-
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.
test repeating instruments w/ sparse records
ref #143
- Loading branch information
Showing
6 changed files
with
186 additions
and
0 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
14 changes: 14 additions & 0 deletions
14
inst/test-data/specific-redcapr/read-batch-repeating-sparse/batch-size-1.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,14 @@ | ||
structure(list(record_id = c(1, 1, 1, 1, 2, 2, 3, 4, 5), redcap_repeat_instrument = c(NA, | ||
"bp", "bp", "bp", NA, "bp", NA, NA, NA), redcap_repeat_instance = c(NA, | ||
1, 2, 3, NA, 1, NA, NA, NA), date_enrolled = structure(c(18183, | ||
NA, NA, NA, 17929, NA, 18935, 18935, NA), class = "Date"), first_name = c("aaa", | ||
NA, NA, NA, "bbb", NA, "empty 3", "empty 4", "empty 5"), dob = structure(c(14896, | ||
NA, NA, NA, 14642, NA, NA, NA, NA), class = "Date"), age = c(8.9, | ||
NA, NA, NA, 9.6, NA, NA, NA, NA), ethnicity = c(1, NA, NA, NA, | ||
0, NA, NA, NA, NA), race = c(4, NA, NA, NA, 6, NA, NA, NA, NA | ||
), sex = c(0, NA, NA, NA, 1, NA, NA, NA, NA), demographics_complete = c(2, | ||
NA, NA, NA, 2, NA, 0, 0, 0), date_bp = structure(c(NA, 18183, | ||
18183, 18183, NA, 12512, NA, NA, NA), class = "Date"), bp_systolic = c(NA, | ||
110, 111, 112, NA, 114, NA, NA, NA), bp_diastolic = c(NA, 100, | ||
101, 102, NA, 104, NA, NA, NA), bp_complete = c(NA, 2, 2, 2, | ||
NA, 2, NA, NA, NA)), row.names = c(NA, -9L), class = "data.frame") |
14 changes: 14 additions & 0 deletions
14
inst/test-data/specific-redcapr/read-batch-repeating-sparse/batch-size-3.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,14 @@ | ||
structure(list(record_id = c(1, 1, 1, 1, 2, 2, 3, 4, 5), redcap_repeat_instrument = c(NA, | ||
"bp", "bp", "bp", NA, "bp", NA, NA, NA), redcap_repeat_instance = c(NA, | ||
1, 2, 3, NA, 1, NA, NA, NA), date_enrolled = structure(c(18183, | ||
NA, NA, NA, 17929, NA, 18935, 18935, NA), class = "Date"), first_name = c("aaa", | ||
NA, NA, NA, "bbb", NA, "empty 3", "empty 4", "empty 5"), dob = structure(c(14896, | ||
NA, NA, NA, 14642, NA, NA, NA, NA), class = "Date"), age = c(8.9, | ||
NA, NA, NA, 9.6, NA, NA, NA, NA), ethnicity = c(1, NA, NA, NA, | ||
0, NA, NA, NA, NA), race = c(4, NA, NA, NA, 6, NA, NA, NA, NA | ||
), sex = c(0, NA, NA, NA, 1, NA, NA, NA, NA), demographics_complete = c(2, | ||
NA, NA, NA, 2, NA, 0, 0, 0), date_bp = structure(c(NA, 18183, | ||
18183, 18183, NA, 12512, NA, NA, NA), class = "Date"), bp_systolic = c(NA, | ||
110, 111, 112, NA, 114, NA, NA, NA), bp_diastolic = c(NA, 100, | ||
101, 102, NA, 104, NA, NA, NA), bp_complete = c(NA, 2, 2, 2, | ||
NA, 2, NA, NA, NA)), row.names = c(NA, -9L), class = "data.frame") |
14 changes: 14 additions & 0 deletions
14
inst/test-data/specific-redcapr/read-batch-repeating-sparse/batch-szie-2.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,14 @@ | ||
structure(list(record_id = c(1, 1, 1, 1, 2, 2, 3, 4, 5), redcap_repeat_instrument = c(NA, | ||
"bp", "bp", "bp", NA, "bp", NA, NA, NA), redcap_repeat_instance = c(NA, | ||
1, 2, 3, NA, 1, NA, NA, NA), date_enrolled = structure(c(18183, | ||
NA, NA, NA, 17929, NA, 18935, 18935, NA), class = "Date"), first_name = c("aaa", | ||
NA, NA, NA, "bbb", NA, "empty 3", "empty 4", "empty 5"), dob = structure(c(14896, | ||
NA, NA, NA, 14642, NA, NA, NA, NA), class = "Date"), age = c(8.9, | ||
NA, NA, NA, 9.6, NA, NA, NA, NA), ethnicity = c(1, NA, NA, NA, | ||
0, NA, NA, NA, NA), race = c(4, NA, NA, NA, 6, NA, NA, NA, NA | ||
), sex = c(0, NA, NA, NA, 1, NA, NA, NA, NA), demographics_complete = c(2, | ||
NA, NA, NA, 2, NA, 0, 0, 0), date_bp = structure(c(NA, 18183, | ||
18183, 18183, NA, 12512, NA, NA, NA), class = "Date"), bp_systolic = c(NA, | ||
110, 111, 112, NA, 114, NA, NA, NA), bp_diastolic = c(NA, 100, | ||
101, 102, NA, 104, NA, NA, NA), bp_complete = c(NA, 2, 2, 2, | ||
NA, 2, NA, NA, NA)), row.names = c(NA, -9L), class = "data.frame") |
14 changes: 14 additions & 0 deletions
14
inst/test-data/specific-redcapr/read-batch-repeating-sparse/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,14 @@ | ||
structure(list(record_id = c(1, 1, 1, 1, 2, 2, 3, 4, 5), redcap_repeat_instrument = c(NA, | ||
"bp", "bp", "bp", NA, "bp", NA, NA, NA), redcap_repeat_instance = c(NA, | ||
1, 2, 3, NA, 1, NA, NA, NA), date_enrolled = structure(c(18183, | ||
NA, NA, NA, 17929, NA, 18935, 18935, NA), class = "Date"), first_name = c("aaa", | ||
NA, NA, NA, "bbb", NA, "empty 3", "empty 4", "empty 5"), dob = structure(c(14896, | ||
NA, NA, NA, 14642, NA, NA, NA, NA), class = "Date"), age = c(8.9, | ||
NA, NA, NA, 9.6, NA, NA, NA, NA), ethnicity = c(1, NA, NA, NA, | ||
0, NA, NA, NA, NA), race = c(4, NA, NA, NA, 6, NA, NA, NA, NA | ||
), sex = c(0, NA, NA, NA, 1, NA, NA, NA, NA), demographics_complete = c(2, | ||
NA, NA, NA, 2, NA, 0, 0, 0), date_bp = structure(c(NA, 18183, | ||
18183, 18183, NA, 12512, NA, NA, NA), class = "Date"), bp_systolic = c(NA, | ||
110, 111, 112, NA, 114, NA, NA, NA), bp_diastolic = c(NA, 100, | ||
101, 102, NA, 104, NA, NA, NA), bp_complete = c(NA, 2, 2, 2, | ||
NA, 2, NA, NA, NA)), row.names = c(NA, -9L), class = "data.frame") |
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,129 @@ | ||
library(testthat) | ||
|
||
credential <- retrieve_credential_testing(project_id = 2603L) | ||
update_expectation <- FALSE | ||
|
||
test_that("smoke test", { | ||
testthat::skip_on_cran() | ||
expect_message( | ||
returned_object <- | ||
redcap_read( | ||
redcap_uri = credential$redcap_uri, | ||
token = credential$token | ||
) | ||
) | ||
}) | ||
|
||
test_that("default", { | ||
testthat::skip_on_cran() | ||
path_expected <- "test-data/specific-redcapr/read-batch-repeating-sparse/default.R" | ||
expected_outcome_message <- "\\d+ records and \\d+ columns were read from REDCap in \\d+(\\.\\d+\\W|\\W)seconds\\." | ||
|
||
expect_message( | ||
regexp = expected_outcome_message, | ||
returned_object <- | ||
redcap_read( | ||
redcap_uri = credential$redcap_uri, | ||
token = credential$token#, | ||
# batch_size = 1 | ||
) | ||
) | ||
|
||
if (update_expectation) save_expected(returned_object$data, path_expected) | ||
expected_data_frame <- retrieve_expected(path_expected) | ||
|
||
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(returned_object$status_code, expected="200") | ||
expect_true(returned_object$records_collapsed=="", "A subset of records was not requested.") | ||
expect_true(returned_object$fields_collapsed=="", "A subset of fields was not requested.") | ||
expect_true(returned_object$filter_logic=="", "A filter was not specified.") | ||
expect_match(returned_object$outcome_message, regexp=expected_outcome_message, perl=TRUE) | ||
expect_true(returned_object$success) | ||
}) | ||
|
||
|
||
test_that("batch size 3", { | ||
testthat::skip_on_cran() | ||
path_expected <- "test-data/specific-redcapr/read-batch-repeating-sparse/batch-size-3.R" | ||
expected_outcome_message <- "\\d+ records and \\d+ columns were read from REDCap in \\d+(\\.\\d+\\W|\\W)seconds\\." | ||
|
||
expect_message( | ||
regexp = expected_outcome_message, | ||
returned_object <- | ||
redcap_read( | ||
redcap_uri = credential$redcap_uri, | ||
token = credential$token, | ||
batch_size = 3 | ||
) | ||
) | ||
|
||
if (update_expectation) save_expected(returned_object$data, path_expected) | ||
expected_data_frame <- retrieve_expected(path_expected) | ||
|
||
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(returned_object$status_code, expected="200; 200") | ||
expect_true(returned_object$records_collapsed=="", "A subset of records was not requested.") | ||
expect_true(returned_object$fields_collapsed=="", "A subset of fields was not requested.") | ||
expect_true(returned_object$filter_logic=="", "A filter was not specified.") | ||
expect_match(returned_object$outcome_message, regexp=expected_outcome_message, perl=TRUE) | ||
expect_true(returned_object$success) | ||
}) | ||
|
||
|
||
test_that("batch size 2", { | ||
testthat::skip_on_cran() | ||
path_expected <- "test-data/specific-redcapr/read-batch-repeating-sparse/batch-szie-2.R" | ||
expected_outcome_message <- "\\d+ records and \\d+ columns were read from REDCap in \\d+(\\.\\d+\\W|\\W)seconds\\." | ||
|
||
expect_message( | ||
regexp = expected_outcome_message, | ||
returned_object <- | ||
redcap_read( | ||
redcap_uri = credential$redcap_uri, | ||
token = credential$token, | ||
batch_size = 2 | ||
) | ||
) | ||
|
||
if (update_expectation) save_expected(returned_object$data, path_expected) | ||
expected_data_frame <- retrieve_expected(path_expected) | ||
|
||
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(returned_object$status_code, expected="200; 200; 200") | ||
expect_true(returned_object$records_collapsed=="", "A subset of records was not requested.") | ||
expect_true(returned_object$fields_collapsed=="", "A subset of fields was not requested.") | ||
expect_true(returned_object$filter_logic=="", "A filter was not specified.") | ||
expect_match(returned_object$outcome_message, regexp=expected_outcome_message, perl=TRUE) | ||
expect_true(returned_object$success) | ||
}) | ||
|
||
|
||
test_that("batch size 1", { | ||
testthat::skip_on_cran() | ||
path_expected <- "test-data/specific-redcapr/read-batch-repeating-sparse/batch-size-1.R" | ||
expected_outcome_message <- "\\d+ records and \\d+ columns were read from REDCap in \\d+(\\.\\d+\\W|\\W)seconds\\." | ||
|
||
expect_message( | ||
regexp = expected_outcome_message, | ||
returned_object <- | ||
redcap_read( | ||
redcap_uri = credential$redcap_uri, | ||
token = credential$token, | ||
batch_size = 1 | ||
) | ||
) | ||
|
||
if (update_expectation) save_expected(returned_object$data, path_expected) | ||
expected_data_frame <- retrieve_expected(path_expected) | ||
|
||
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(returned_object$status_code, expected="200; 200; 200; 200; 200") | ||
expect_true(returned_object$records_collapsed=="", "A subset of records was not requested.") | ||
expect_true(returned_object$fields_collapsed=="", "A subset of fields was not requested.") | ||
expect_true(returned_object$filter_logic=="", "A filter was not specified.") | ||
expect_match(returned_object$outcome_message, regexp=expected_outcome_message, perl=TRUE) | ||
expect_true(returned_object$success) | ||
}) | ||
|
||
rm(credential) | ||
|