Skip to content

Commit

Permalink
adding tests for blank_for_gray
Browse files Browse the repository at this point in the history
ref #389
  • Loading branch information
wibeasley committed Aug 14, 2022
1 parent 2c4ff75 commit 76b1784
Show file tree
Hide file tree
Showing 10 changed files with 317 additions and 0 deletions.
1 change: 1 addition & 0 deletions inst/misc/example.credentials
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ redcap_uri,username,project_id,token,comment
"https://bbmc.ouhsc.edu/redcap/api/","myusername","2631","D2A6FF48D266C0CFAAED8842CDCC7CED","decimal comma"
"https://bbmc.ouhsc.edu/redcap/api/","myusername","2632","D7DDE242E717619E17F7DF0D3CE582B1","decimal dot"
"https://bbmc.ouhsc.edu/redcap/api/","myusername","2634","8F5313CAA266789F560D79EFCEE2E2F1","Validation Types"
"https://bbmc.ouhsc.edu/redcap/api/","myusername","3003","1F2EC7059AC339DFDCD5800225DC7A95","Blank for Gray Status"
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
structure(list(record_id = c(1, 2, 3, 4, 5, 6), name_first = c("Nutmeg",
"Tumtum", "Marcus", "Trudy", "John Lee", "blank-for-gray"), name_last = c("Nutmouse",
"Nutmouse", "Wood", "DAG", "Walker", "blank-for-gray"), 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",
NA), telephone = c("(405) 321-1111", "(405) 321-2222", "(405) 321-3333",
"(405) 321-4444", "(405) 321-5555", NA), email = c("[email protected]",
"[email protected]", "[email protected]", "[email protected]", "[email protected]",
NA), dob = structure(c(12294, 12121, -13051, -6269, -5375, NA
), class = "Date"), age = c(11, 11, 80, 61, 59, NA), sex = c(0,
1, 1, 0, 1, NA), demographics_complete = c(2, 2, 2, 2, 2, 0),
height = c(7, 6, 180, 165, 193.04, NA), weight = c(1, 1,
80, 54, 104, NA), bmi = c(204.1, 277.8, 24.7, 19.8, 27.9,
NA), comments = c("Character in a book, with some guessing",
"A mouse character from a good book", "completely made up",
"This record doesn't have a DAG assigned\n\nSo call up Trudy on the telephone\nSend her a letter in the mail",
"Had a hand for trouble and a eye for cash\n\nHe had a gold watch chain and a black mustache",
NA), mugshot = c("mugshot-1.jpg", "mugshot-2.jpg", "mugshot-3.jpg",
"mugshot-4.jpg", "mugshot-5.jpg", NA), health_complete = c(1,
0, 2, 2, 0, 0), race___1 = c(0, 0, 0, 0, 1, 0), race___2 = c(0,
0, 0, 1, 0, 0), race___3 = c(0, 1, 0, 0, 0, 0), race___4 = c(0,
0, 1, 0, 0, 0), race___5 = c(1, 1, 1, 1, 0, 0), race___6 = c(0,
0, 0, 0, 1, 0), ethnicity = c(1, 1, 0, 1, 2, NA), interpreter_needed = c(0,
0, 1, NA, 0, NA), race_and_ethnicity_complete = c(2, 0, 2,
2, 2, 0)), row.names = c(NA, -6L), class = "data.frame")
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
structure(list(record_id = c(1, 2, 3, 4, 5, 6), name_first = c("Nutmeg",
"Tumtum", "Marcus", "Trudy", "John Lee", "blank-for-gray"), name_last = c("Nutmouse",
"Nutmouse", "Wood", "DAG", "Walker", "blank-for-gray"), 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",
NA), telephone = c("(405) 321-1111", "(405) 321-2222", "(405) 321-3333",
"(405) 321-4444", "(405) 321-5555", NA), email = c("[email protected]",
"[email protected]", "[email protected]", "[email protected]", "[email protected]",
NA), dob = structure(c(12294, 12121, -13051, -6269, -5375, NA
), class = "Date"), age = c(11, 11, 80, 61, 59, NA), sex = c(0,
1, 1, 0, 1, NA), demographics_complete = c(2, 2, 2, 2, 2, 0),
height = c(7, 6, 180, 165, 193.04, NA), weight = c(1, 1,
80, 54, 104, NA), bmi = c(204.1, 277.8, 24.7, 19.8, 27.9,
NA), comments = c("Character in a book, with some guessing",
"A mouse character from a good book", "completely made up",
"This record doesn't have a DAG assigned\n\nSo call up Trudy on the telephone\nSend her a letter in the mail",
"Had a hand for trouble and a eye for cash\n\nHe had a gold watch chain and a black mustache",
NA), mugshot = c("mugshot-1.jpg", "mugshot-2.jpg", "mugshot-3.jpg",
"mugshot-4.jpg", "mugshot-5.jpg", NA), health_complete = c(1,
0, 2, 2, 0, NA), race___1 = c(0, 0, 0, 0, 1, 0), race___2 = c(0,
0, 0, 1, 0, 0), race___3 = c(0, 1, 0, 0, 0, 0), race___4 = c(0,
0, 1, 0, 0, 0), race___5 = c(1, 1, 1, 1, 0, 0), race___6 = c(0,
0, 0, 0, 1, 0), ethnicity = c(1, 1, 0, 1, 2, NA), interpreter_needed = c(0,
0, 1, NA, 0, NA), race_and_ethnicity_complete = c(2, 0, 2,
2, 2, NA)), row.names = c(NA, -6L), class = "data.frame")
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
structure(list(record_id = 1:6, name_first = c("Nutmeg", "Tumtum",
"Marcus", "Trudy", "John Lee", "blank-for-gray"), name_last = c("Nutmouse",
"Nutmouse", "Wood", "DAG", "Walker", "blank-for-gray"), 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",
NA), telephone = c("(405) 321-1111", "(405) 321-2222", "(405) 321-3333",
"(405) 321-4444", "(405) 321-5555", NA), email = c("[email protected]",
"[email protected]", "[email protected]", "[email protected]", "[email protected]",
NA), dob = c("2003-08-30", "2003-03-10", "1934-04-09", "1952-11-02",
"1955-04-15", NA), age = c(11L, 11L, 80L, 61L, 59L, NA), sex = c(0L,
1L, 1L, 0L, 1L, NA), height = c(7, 6, 180, 165, 193.04, NA),
weight = c(1L, 1L, 80L, 54L, 104L, NA), bmi = c(204.1, 277.8,
24.7, 19.8, 27.9, NA), comments = c("Character in a book, with some guessing",
"A mouse character from a good book", "completely made up",
"This record doesn't have a DAG assigned\n\nSo call up Trudy on the telephone\nSend her a letter in the mail",
"Had a hand for trouble and a eye for cash\n\nHe had a gold watch chain and a black mustache",
NA), mugshot = c(324901L, 324902L, 324903L, 324904L, 324905L,
NA), race___1 = c(FALSE, FALSE, FALSE, FALSE, TRUE, FALSE
), race___2 = c(FALSE, FALSE, FALSE, TRUE, FALSE, FALSE),
race___3 = c(FALSE, TRUE, FALSE, FALSE, FALSE, FALSE), race___4 = c(FALSE,
FALSE, TRUE, FALSE, FALSE, FALSE), race___5 = c(TRUE, TRUE,
TRUE, TRUE, FALSE, FALSE), race___6 = c(FALSE, FALSE, FALSE,
FALSE, TRUE, FALSE), ethnicity = c(1L, 1L, 0L, 1L, 2L, NA
), interpreter_needed = c(0L, 0L, 1L, NA, 0L, NA), demographics_complete = c(2L,
2L, 2L, 2L, 2L, 0L), health_complete = c(1L, 0L, 2L, 2L,
0L, NA), race_and_ethnicity_complete = c(2L, 0L, 2L, 2L,
2L, NA)), row.names = c(NA, -6L), class = c("tbl_df", "tbl",
"data.frame"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
structure(list(record_id = 1:6, name_first = c("Nutmeg", "Tumtum",
"Marcus", "Trudy", "John Lee", "blank-for-gray"), name_last = c("Nutmouse",
"Nutmouse", "Wood", "DAG", "Walker", "blank-for-gray"), 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",
NA), telephone = c("(405) 321-1111", "(405) 321-2222", "(405) 321-3333",
"(405) 321-4444", "(405) 321-5555", NA), email = c("[email protected]",
"[email protected]", "[email protected]", "[email protected]", "[email protected]",
NA), dob = c("2003-08-30", "2003-03-10", "1934-04-09", "1952-11-02",
"1955-04-15", NA), age = c(11L, 11L, 80L, 61L, 59L, NA), sex = c(0L,
1L, 1L, 0L, 1L, NA), height = c(7, 6, 180, 165, 193.04, NA),
weight = c(1L, 1L, 80L, 54L, 104L, NA), bmi = c(204.1, 277.8,
24.7, 19.8, 27.9, NA), comments = c("Character in a book, with some guessing",
"A mouse character from a good book", "completely made up",
"This record doesn't have a DAG assigned\n\nSo call up Trudy on the telephone\nSend her a letter in the mail",
"Had a hand for trouble and a eye for cash\n\nHe had a gold watch chain and a black mustache",
NA), mugshot = c(324901L, 324902L, 324903L, 324904L, 324905L,
NA), race___1 = c(FALSE, FALSE, FALSE, FALSE, TRUE, FALSE
), race___2 = c(FALSE, FALSE, FALSE, TRUE, FALSE, FALSE),
race___3 = c(FALSE, TRUE, FALSE, FALSE, FALSE, FALSE), race___4 = c(FALSE,
FALSE, TRUE, FALSE, FALSE, FALSE), race___5 = c(TRUE, TRUE,
TRUE, TRUE, FALSE, FALSE), race___6 = c(FALSE, FALSE, FALSE,
FALSE, TRUE, FALSE), ethnicity = c(1L, 1L, 0L, 1L, 2L, NA
), interpreter_needed = c(0L, 0L, 1L, NA, 0L, NA), demographics_complete = c(2L,
2L, 2L, 2L, 2L, 0L), health_complete = c(1L, 0L, 2L, 2L,
0L, NA), race_and_ethnicity_complete = c(2L, 0L, 2L, 2L,
2L, NA)), row.names = c(NA, -6L), class = c("tbl_df", "tbl",
"data.frame"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
structure(list(record_id = c(1, 2, 3, 4, 5, 6), name_first = c("Nutmeg",
"Tumtum", "Marcus", "Trudy", "John Lee", "blank-for-gray"), name_last = c("Nutmouse",
"Nutmouse", "Wood", "DAG", "Walker", "blank-for-gray"), 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",
NA), telephone = c("(405) 321-1111", "(405) 321-2222", "(405) 321-3333",
"(405) 321-4444", "(405) 321-5555", NA), email = c("[email protected]",
"[email protected]", "[email protected]", "[email protected]", "[email protected]",
NA), dob = structure(c(12294, 12121, -13051, -6269, -5375, NA
), class = "Date"), age = c(11, 11, 80, 61, 59, NA), sex = c(0,
1, 1, 0, 1, NA), demographics_complete = c(2, 2, 2, 2, 2, 0),
height = c(7, 6, 180, 165, 193.04, NA), weight = c(1, 1,
80, 54, 104, NA), bmi = c(204.1, 277.8, 24.7, 19.8, 27.9,
NA), comments = c("Character in a book, with some guessing",
"A mouse character from a good book", "completely made up",
"This record doesn't have a DAG assigned\n\nSo call up Trudy on the telephone\nSend her a letter in the mail",
"Had a hand for trouble and a eye for cash\n\nHe had a gold watch chain and a black mustache",
NA), mugshot = c("mugshot-1.jpg", "mugshot-2.jpg", "mugshot-3.jpg",
"mugshot-4.jpg", "mugshot-5.jpg", NA), health_complete = c(1,
0, 2, 2, 0, 0), race___1 = c(0, 0, 0, 0, 1, 0), race___2 = c(0,
0, 0, 1, 0, 0), race___3 = c(0, 1, 0, 0, 0, 0), race___4 = c(0,
0, 1, 0, 0, 0), race___5 = c(1, 1, 1, 1, 0, 0), race___6 = c(0,
0, 0, 0, 1, 0), ethnicity = c(1, 1, 0, 1, 2, NA), interpreter_needed = c(0,
0, 1, NA, 0, NA), race_and_ethnicity_complete = c(2, 0, 2,
2, 2, 0)), row.names = c(NA, -6L), class = "data.frame")
25 changes: 25 additions & 0 deletions inst/test-data/specific-redcapr/read-oneshot/blank-for-gray-true.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
structure(list(record_id = c(1, 2, 3, 4, 5, 6), name_first = c("Nutmeg",
"Tumtum", "Marcus", "Trudy", "John Lee", "blank-for-gray"), name_last = c("Nutmouse",
"Nutmouse", "Wood", "DAG", "Walker", "blank-for-gray"), 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",
NA), telephone = c("(405) 321-1111", "(405) 321-2222", "(405) 321-3333",
"(405) 321-4444", "(405) 321-5555", NA), email = c("[email protected]",
"[email protected]", "[email protected]", "[email protected]", "[email protected]",
NA), dob = structure(c(12294, 12121, -13051, -6269, -5375, NA
), class = "Date"), age = c(11, 11, 80, 61, 59, NA), sex = c(0,
1, 1, 0, 1, NA), demographics_complete = c(2, 2, 2, 2, 2, 0),
height = c(7, 6, 180, 165, 193.04, NA), weight = c(1, 1,
80, 54, 104, NA), bmi = c(204.1, 277.8, 24.7, 19.8, 27.9,
NA), comments = c("Character in a book, with some guessing",
"A mouse character from a good book", "completely made up",
"This record doesn't have a DAG assigned\n\nSo call up Trudy on the telephone\nSend her a letter in the mail",
"Had a hand for trouble and a eye for cash\n\nHe had a gold watch chain and a black mustache",
NA), mugshot = c("mugshot-1.jpg", "mugshot-2.jpg", "mugshot-3.jpg",
"mugshot-4.jpg", "mugshot-5.jpg", NA), health_complete = c(1,
0, 2, 2, 0, NA), race___1 = c(0, 0, 0, 0, 1, 0), race___2 = c(0,
0, 0, 1, 0, 0), race___3 = c(0, 1, 0, 0, 0, 0), race___4 = c(0,
0, 1, 0, 0, 0), race___5 = c(1, 1, 1, 1, 0, 0), race___6 = c(0,
0, 0, 0, 1, 0), ethnicity = c(1, 1, 0, 1, 2, NA), interpreter_needed = c(0,
0, 1, NA, 0, NA), race_and_ethnicity_complete = c(2, 0, 2,
2, 2, NA)), row.names = c(NA, -6L), class = "data.frame")
52 changes: 52 additions & 0 deletions tests/testthat/test-read-batch-simple.R
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,58 @@ test_that("filter-character", {
expect_match(returned_object$outcome_message, regexp=expected_outcome_message, perl=TRUE)
expect_true(returned_object$success)
})
test_that("blank-for-gray-status-true", {
testthat::skip_on_cran()
credential_blank_for_gray <- retrieve_credential_testing(3003L)
path_expected <- "test-data/specific-redcapr/read-batch-simple/blank-for-gray-true.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_blank_for_gray$redcap_uri,
token = credential_blank_for_gray$token,
export_blankforgray_form_status = TRUE
)
)

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("blank-for-gray-status-false", {
testthat::skip_on_cran()
credential_blank_for_gray <- retrieve_credential_testing(3003L)
path_expected <- "test-data/specific-redcapr/read-batch-simple/blank-for-gray-false.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_blank_for_gray$redcap_uri,
token = credential_blank_for_gray$token,
export_blankforgray_form_status = FALSE
)
)

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("date-range", {
testthat::skip_on_cran()
Expand Down
54 changes: 54 additions & 0 deletions tests/testthat/test-read-oneshot-eav.R
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,60 @@ test_that("filter-character", {
expect_match(returned_object$outcome_message, regexp=expected_outcome_message, perl=TRUE)
expect_true(returned_object$success)
})
test_that("blank-for-gray-status-true", {
testthat::skip_on_cran()
credential_blank_for_gray <- retrieve_credential_testing(3003L)
path_expected <- "test-data/specific-redcapr/read-oneshot-eav/blank-for-gray-true.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 <- REDCapR:::redcap_read_oneshot_eav(
redcap_uri = credential_blank_for_gray$redcap_uri,
token = credential_blank_for_gray$token,
export_blankforgray_form_status = TRUE
)
)

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)
})
test_that("blank-for-gray-status-false", {
testthat::skip_on_cran()
credential_blank_for_gray <- retrieve_credential_testing(3003L)
path_expected <- "test-data/specific-redcapr/read-oneshot-eav/blank-for-gray-false.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 <- REDCapR:::redcap_read_oneshot_eav(
redcap_uri = credential_blank_for_gray$redcap_uri,
token = credential_blank_for_gray$token,
export_blankforgray_form_status = FALSE
)
)

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)
})

test_that("date-range", {
testthat::skip_on_cran()
Expand Down
Loading

0 comments on commit 76b1784

Please sign in to comment.