Skip to content

Commit

Permalink
test that forms work for read & read_oneshot
Browse files Browse the repository at this point in the history
ref #431
  • Loading branch information
wibeasley committed Oct 8, 2022
1 parent 4eba8cb commit a17fc63
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
structure(list(record_id = c(1, 2, 3, 4, 5), name_first = c("Nutmeg",
"Tumtum", "Marcus", "Trudy", "John Lee"), name_last = c("Nutmouse",
"Nutmouse", "Wood", "DAG", "Walker"), address = c("14 Rose Cottage St.\nKenning UK, 323232",
"14 Rose Cottage Blvd.\nKenning UK 34243", "243 Hill St.\nGuthrie OK 73402",
"342 Elm\nDuncanville TX, 75116", "Hotel Suite\nNew Orleans LA, 70115"
), telephone = c("(405) 321-1111", "(405) 321-2222", "(405) 321-3333",
"(405) 321-4444", "(405) 321-5555"), email = c("[email protected]",
"[email protected]", "[email protected]", "[email protected]", "[email protected]"
), dob = structure(c(12294, 12121, -13051, -6269, -5375), class = "Date"),
age = c(11, 11, 80, 61, 59), sex = c(0, 1, 1, 0, 1), demographics_complete = c(2,
2, 2, 2, 2)), row.names = c(NA, -5L), class = c("spec_tbl_df",
"tbl_df", "tbl", "data.frame"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
structure(list(record_id = c(1, 2, 3, 4, 5), name_first = c("Nutmeg",
"Tumtum", "Marcus", "Trudy", "John Lee"), name_last = c("Nutmouse",
"Nutmouse", "Wood", "DAG", "Walker"), address = c("14 Rose Cottage St.\nKenning UK, 323232",
"14 Rose Cottage Blvd.\nKenning UK 34243", "243 Hill St.\nGuthrie OK 73402",
"342 Elm\nDuncanville TX, 75116", "Hotel Suite\nNew Orleans LA, 70115"
), telephone = c("(405) 321-1111", "(405) 321-2222", "(405) 321-3333",
"(405) 321-4444", "(405) 321-5555"), email = c("[email protected]",
"[email protected]", "[email protected]", "[email protected]", "[email protected]"
), dob = structure(c(12294, 12121, -13051, -6269, -5375), class = "Date"),
age = c(11, 11, 80, 61, 59), sex = c(0, 1, 1, 0, 1), demographics_complete = c(2,
2, 2, 2, 2)), row.names = c(NA, -5L), spec = structure(list(
cols = list(record_id = structure(list(), class = c("collector_double",
"collector")), name_first = structure(list(), class = c("collector_character",
"collector")), name_last = structure(list(), class = c("collector_character",
"collector")), address = structure(list(), class = c("collector_character",
"collector")), telephone = structure(list(), class = c("collector_character",
"collector")), email = structure(list(), class = c("collector_character",
"collector")), dob = structure(list(format = ""), class = c("collector_date",
"collector")), age = structure(list(), class = c("collector_double",
"collector")), sex = structure(list(), class = c("collector_double",
"collector")), demographics_complete = structure(list(), class = c("collector_double",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), delim = ","), class = "col_spec"), class = c("spec_tbl_df",
"tbl_df", "tbl", "data.frame"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
structure(list(race___1 = c(0, 0, 0, 0, 1), race___2 = c(0, 0,
0, 1, 0), race___3 = c(0, 1, 0, 0, 0), race___4 = c(0, 0, 1,
0, 0), race___5 = c(1, 1, 1, 1, 0), race___6 = c(0, 0, 0, 0,
1), ethnicity = c(1, 1, 0, 1, 2), interpreter_needed = c(0, 0,
1, NA, 0), race_and_ethnicity_complete = c(2, 0, 2, 2, 2)), row.names = c(NA,
-5L), spec = structure(list(cols = list(race___1 = structure(list(), class = c("collector_double",
"collector")), race___2 = structure(list(), class = c("collector_double",
"collector")), race___3 = structure(list(), class = c("collector_double",
"collector")), race___4 = structure(list(), class = c("collector_double",
"collector")), race___5 = structure(list(), class = c("collector_double",
"collector")), race___6 = structure(list(), class = c("collector_double",
"collector")), ethnicity = structure(list(), class = c("collector_double",
"collector")), interpreter_needed = structure(list(), class = c("collector_double",
"collector")), race_and_ethnicity_complete = structure(list(), class = c("collector_double",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), delim = ","), class = "col_spec"), class = c("spec_tbl_df",
"tbl_df", "tbl", "data.frame"))
82 changes: 82 additions & 0 deletions tests/testthat/test-read-batch-simple.R
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,88 @@ test_that("specify-forms", {
expect_match(returned_object2$outcome_messages, regexp=expected_outcome_message, perl=TRUE)
expect_s3_class(returned_object2$data, "tbl")
})
test_that("specify-forms-only-1st", {
testthat::skip_on_cran()
path_expected <- "test-data/specific-redcapr/read-batch-simple/specify-forms-only-1st.R"
desired_forms <- c("demographics")
expected_outcome_message <- "\\d+ records and 10 columns were read from REDCap in \\d+(\\.\\d+\\W|\\W)seconds\\."

###########################
## Default Batch size
expect_message(
regexp = expected_outcome_message,
returned_object1 <- redcap_read(redcap_uri=credential$redcap_uri, token=credential$token, forms=desired_forms)
)

if (update_expectation) save_expected(returned_object1$data, path_expected)
expected_data_frame <- retrieve_expected(path_expected)

expect_equal(returned_object1$data, expected=expected_data_frame, label="The returned data.frame should be correct", ignore_attr = TRUE) # dput(returned_object1$data)
expect_true(returned_object1$success)
expect_match(returned_object1$status_codes, regexp="200", perl=TRUE)
expect_true(returned_object1$records_collapsed=="", "A subset of records was not requested.")
expect_true(returned_object1$fields_collapsed=="", "A subset of fields was not requested.")
expect_true(returned_object1$filter_logic=="", "A filter was not specified.")
expect_match(returned_object1$outcome_messages, regexp=expected_outcome_message, perl=TRUE)
expect_s3_class(returned_object1$data, "tbl")

###########################
## Tiny Batch size
expect_message(
returned_object2 <- redcap_read(redcap_uri=credential$redcap_uri, token=credential$token, forms=desired_forms, batch_size=2),
regexp = expected_outcome_message
)

expect_equal(returned_object2$data, expected=expected_data_frame, label="The returned data.frame should be correct", ignore_attr = TRUE) # dput(returned_object2$data)
expect_true(returned_object2$success)
expect_match(returned_object2$status_codes, regexp="200", perl=TRUE)
expect_true(returned_object2$records_collapsed=="", "A subset of records was not requested.")
expect_true(returned_object2$fields_collapsed=="", "A subset of fields was not requested.")
expect_true(returned_object2$filter_logic=="", "A filter was not specified.")
expect_match(returned_object2$outcome_messages, regexp=expected_outcome_message, perl=TRUE)
expect_s3_class(returned_object2$data, "tbl")
})
# test_that("specify-forms-only-2nd", {
# testthat::skip_on_cran()
# path_expected <- "test-data/specific-redcapr/read-batch-simple/specify-forms-only-2nd.R"
# desired_forms <- c("race_and_ethnicity")
# expected_outcome_message <- "\\d+ records and 19 columns were read from REDCap in \\d+(\\.\\d+\\W|\\W)seconds\\."
#
# ###########################
# ## Default Batch size
# expect_message(
# regexp = expected_outcome_message,
# returned_object1 <- redcap_read(redcap_uri=credential$redcap_uri, token=credential$token, forms=desired_forms)
# )
#
# if (update_expectation) save_expected(returned_object1$data, path_expected)
# expected_data_frame <- retrieve_expected(path_expected)
#
# expect_equal(returned_object1$data, expected=expected_data_frame, label="The returned data.frame should be correct", ignore_attr = TRUE) # dput(returned_object1$data)
# expect_true(returned_object1$success)
# expect_match(returned_object1$status_codes, regexp="200", perl=TRUE)
# expect_true(returned_object1$records_collapsed=="", "A subset of records was not requested.")
# expect_true(returned_object1$fields_collapsed=="", "A subset of fields was not requested.")
# expect_true(returned_object1$filter_logic=="", "A filter was not specified.")
# expect_match(returned_object1$outcome_messages, regexp=expected_outcome_message, perl=TRUE)
# expect_s3_class(returned_object1$data, "tbl")
#
# ###########################
# ## Tiny Batch size
# expect_message(
# returned_object2 <- redcap_read(redcap_uri=credential$redcap_uri, token=credential$token, forms=desired_forms, batch_size=2),
# regexp = expected_outcome_message
# )
#
# expect_equal(returned_object2$data, expected=expected_data_frame, label="The returned data.frame should be correct", ignore_attr = TRUE) # dput(returned_object2$data)
# expect_true(returned_object2$success)
# expect_match(returned_object2$status_codes, regexp="200", perl=TRUE)
# expect_true(returned_object2$records_collapsed=="", "A subset of records was not requested.")
# expect_true(returned_object2$fields_collapsed=="", "A subset of fields was not requested.")
# expect_true(returned_object2$filter_logic=="", "A filter was not specified.")
# expect_match(returned_object2$outcome_messages, regexp=expected_outcome_message, perl=TRUE)
# expect_s3_class(returned_object2$data, "tbl")
# })
test_that("raw", {
testthat::skip_on_cran()
path_expected <- "test-data/specific-redcapr/read-batch-simple/raw.R"
Expand Down
50 changes: 50 additions & 0 deletions tests/testthat/test-read-oneshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,56 @@ test_that("specify-forms", {

expect_s3_class(returned_object$data, "tbl")
})
test_that("specify-forms-only-1st", {
testthat::skip_on_cran()
path_expected <- "test-data/specific-redcapr/read-oneshot/specify-forms-only-1st.R"
desired_forms <- c("demographics")
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_oneshot(redcap_uri=credential$redcap_uri, token=credential$token, forms=desired_forms)
)

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=200L)
expect_equal(returned_object$raw_text, expected="", ignore_attr = TRUE) # dput(returned_object$raw_text)
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)

expect_s3_class(returned_object$data, "tbl")
})
test_that("specify-forms-only-2nd", {
testthat::skip_on_cran()
path_expected <- "test-data/specific-redcapr/read-oneshot/specify-forms-only-2nd.R"
desired_forms <- c("race_and_ethnicity")
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_oneshot(redcap_uri=credential$redcap_uri, token=credential$token, forms=desired_forms)
)

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=200L)
expect_equal(returned_object$raw_text, expected="", ignore_attr = TRUE) # dput(returned_object$raw_text)
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)

expect_s3_class(returned_object$data, "tbl")
})
test_that("force-character-type", {
testthat::skip_on_cran()
path_expected <- "test-data/specific-redcapr/read-oneshot/force-character-type.R"
Expand Down

0 comments on commit a17fc63

Please sign in to comment.