Skip to content

Commit

Permalink
make user test more portable
Browse files Browse the repository at this point in the history
ref #539
  • Loading branch information
wibeasley committed Oct 11, 2024
1 parent 2062f98 commit f021279
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 58 deletions.
32 changes: 13 additions & 19 deletions inst/test-data/specific-redcapr/users-export/with-dags--user.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
structure(list(username = c("unittestphifree", "wbeasleya"),
email = c("[email protected]", "[email protected]"
), firstname = c("Unit Test", "Will"), lastname = c("PHI Free",
"Beasley_A"), expiration = structure(c(NA_real_, NA_real_
), class = "Date"), data_access_group = c("daga", NA), data_access_group_id = c("331",
NA), design = c(FALSE, TRUE), alerts = c(0, 1), user_rights = 2:1,
data_access_groups = c(FALSE, TRUE), reports = c(FALSE, TRUE
), stats_and_charts = c(FALSE, TRUE), manage_survey_participants = c(TRUE,
TRUE), calendar = c(FALSE, TRUE), data_import_tool = c(FALSE,
TRUE), data_comparison_tool = c(FALSE, TRUE), logging = c(FALSE,
TRUE), email_logging = c(FALSE, TRUE), file_repository = c(FALSE,
TRUE), data_quality_create = c(FALSE, TRUE), data_quality_execute = c(FALSE,
TRUE), api_export = c(TRUE, TRUE), api_import = c(FALSE,
TRUE), api_modules = c(FALSE, FALSE), mobile_app = c(FALSE,
TRUE), mobile_app_download_data = c(FALSE, TRUE), record_create = c(FALSE,
TRUE), record_rename = c(FALSE, FALSE), record_delete = c(FALSE,
FALSE), lock_records_all_forms = c(FALSE, FALSE), lock_records = c(FALSE,
FALSE), lock_records_customization = c(FALSE, FALSE), forms_export = c("demographics:1",
"demographics:1")), row.names = c(NA, -2L), class = c("tbl_df",
structure(list(username = "unittestphifree", firstname = "Unit Test",
lastname = "PHI Free", expiration = structure(NA_real_, class = "Date"),
data_access_group = "daga", data_access_group_id = "331",
design = FALSE, alerts = 0, user_rights = 2L, data_access_groups = FALSE,
reports = FALSE, stats_and_charts = FALSE, manage_survey_participants = TRUE,
calendar = FALSE, data_import_tool = FALSE, data_comparison_tool = FALSE,
logging = FALSE, email_logging = FALSE, file_repository = FALSE,
data_quality_create = FALSE, data_quality_execute = FALSE,
api_export = TRUE, api_import = FALSE, api_modules = FALSE,
mobile_app = FALSE, mobile_app_download_data = FALSE, record_create = FALSE,
record_rename = FALSE, record_delete = FALSE, lock_records_all_forms = FALSE,
lock_records = FALSE, lock_records_customization = FALSE,
forms_export = "demographics:1"), row.names = c(NA, -1L), class = c("tbl_df",
"tbl", "data.frame"))
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
structure(list(username = c("unittestphifree", "wbeasleya"),
form_name = c("demographics", NA), permission_id = c(1L,
NA), permission = structure(c(3L, 5L), levels = c("no_access",
structure(list(username = "unittestphifree", form_name = "demographics",
permission_id = 1L, permission = structure(3L, levels = c("no_access",
"readonly", "edit_form", "edit_survey", "unknown"), class = "factor")), row.names = c(NA,
-2L), class = c("tbl_df", "tbl", "data.frame"))
-1L), class = c("tbl_df", "tbl", "data.frame"))
35 changes: 14 additions & 21 deletions inst/test-data/specific-redcapr/users-export/without-dags--user.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
structure(list(username = c("unittestphifree", "wbeasleya"),
email = c("[email protected]", "[email protected]"
), firstname = c("Unit Test", "Will"), lastname = c("PHI Free",
"Beasley_A"), expiration = structure(c(NA_real_, NA_real_
), class = "Date"), data_access_group = c(NA_character_,
NA_character_), data_access_group_id = c(NA_character_, NA_character_
), design = c(FALSE, TRUE), alerts = c(0, 1), user_rights = 2:1,
data_access_groups = c(TRUE, TRUE), reports = c(TRUE, TRUE
), stats_and_charts = c(TRUE, TRUE), manage_survey_participants = c(TRUE,
TRUE), calendar = c(TRUE, TRUE), data_import_tool = c(FALSE,
TRUE), data_comparison_tool = c(FALSE, TRUE), logging = c(TRUE,
TRUE), email_logging = c(FALSE, TRUE), file_repository = c(TRUE,
TRUE), data_quality_create = c(FALSE, TRUE), data_quality_execute = c(FALSE,
TRUE), api_export = c(TRUE, FALSE), api_import = c(FALSE,
FALSE), api_modules = c(FALSE, FALSE), mobile_app = c(FALSE,
FALSE), mobile_app_download_data = c(FALSE, FALSE), record_create = c(TRUE,
TRUE), record_rename = c(FALSE, FALSE), record_delete = c(FALSE,
FALSE), lock_records_all_forms = c(FALSE, FALSE), lock_records = c(FALSE,
FALSE), lock_records_customization = c(FALSE, FALSE), forms_export = c("demographics:1,health:1,race_and_ethnicity:1",
"demographics:1,health:1,race_and_ethnicity:1")), row.names = c(NA,
-2L), class = c("tbl_df", "tbl", "data.frame"))
structure(list(username = "unittestphifree", firstname = "Unit Test",
lastname = "PHI Free", expiration = structure(NA_real_, class = "Date"),
data_access_group = NA_character_, data_access_group_id = NA_character_,
design = FALSE, alerts = 0, user_rights = 1L, data_access_groups = TRUE,
reports = FALSE, stats_and_charts = FALSE, manage_survey_participants = TRUE,
calendar = FALSE, data_import_tool = FALSE, data_comparison_tool = FALSE,
logging = TRUE, email_logging = FALSE, file_repository = FALSE,
data_quality_create = FALSE, data_quality_execute = FALSE,
api_export = TRUE, api_import = FALSE, api_modules = FALSE,
mobile_app = FALSE, mobile_app_download_data = FALSE, record_create = FALSE,
record_rename = FALSE, record_delete = FALSE, lock_records_all_forms = FALSE,
lock_records = FALSE, lock_records_customization = FALSE,
forms_export = "demographics:1,health:1,race_and_ethnicity:1"), row.names = c(NA,
-1L), class = c("tbl_df", "tbl", "data.frame"))
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
structure(list(username = c("unittestphifree", "unittestphifree",
"unittestphifree", "wbeasleya", "wbeasleya", "wbeasleya"), form_name = c("demographics",
"health", "race_and_ethnicity", "demographics", "health", "race_and_ethnicity"
), permission_id = c(1L, 1L, 1L, 1L, 1L, 1L), permission = structure(c(3L,
3L, 3L, 3L, 3L, 3L), levels = c("no_access", "readonly", "edit_form",
"edit_survey", "unknown"), class = "factor")), row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"))
"unittestphifree"), form_name = c("demographics", "health", "race_and_ethnicity"
), permission_id = c(1L, 1L, 1L), permission = structure(c(3L,
3L, 3L), levels = c("no_access", "readonly", "edit_form", "edit_survey",
"unknown"), class = "factor")), row.names = c(NA, -3L), class = c("tbl_df",
"tbl", "data.frame"))
38 changes: 30 additions & 8 deletions tests/testthat/test-users-export.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,26 @@ test_that("with-dags", {
verbose = FALSE
)

d_user <-
returned_object$data_user |>
dplyr::filter(username == "unittestphifree") |>
dplyr::select(
-email
)

d_user_form <-
returned_object$data_user_form |>
dplyr::filter(username == "unittestphifree")

if (update_expectation) {
save_expected(returned_object$data_user , path_expected_user )
save_expected(returned_object$data_user_form, path_expected_user_form)
save_expected(d_user , path_expected_user )
save_expected(d_user_form, path_expected_user_form)
}
expected_data_user <- retrieve_expected(path_expected_user )
expected_data_user_form <- retrieve_expected(path_expected_user_form)

expect_equal(returned_object$data_user , expected=expected_data_user , label="The returned data.frame should be correct", ignore_attr = TRUE) # dput(returned_object$data_user);
expect_equal(returned_object$data_user_form, expected=expected_data_user_form, label="The returned data.frame should be correct", ignore_attr = TRUE) # dput(returned_object$data_user_form)
expect_equal(d_user , expected=expected_data_user , label="The returned data.frame should be correct", ignore_attr = TRUE) # dput(returned_object$data_user);
expect_equal(d_user_form, expected=expected_data_user_form, label="The returned data.frame should be correct", ignore_attr = TRUE) # dput(returned_object$data_user_form)
expect_equal(returned_object$status_code, expected=200L)
expect_equal(returned_object$raw_text, expected="", ignore_attr = TRUE) # dput(returned_object$raw_text)
expect_match(returned_object$outcome_message, regexp=expected_outcome_message, perl=TRUE)
Expand All @@ -67,15 +78,26 @@ test_that("without DAGs", {
verbose = FALSE
)

d_user <-
returned_object$data_user |>
dplyr::filter(username == "unittestphifree") |>
dplyr::select(
-email
)

d_user_form <-
returned_object$data_user_form |>
dplyr::filter(username == "unittestphifree")

if (update_expectation) {
save_expected(returned_object$data_user , path_expected_user )
save_expected(returned_object$data_user_form, path_expected_user_form)
save_expected(d_user , path_expected_user )
save_expected(d_user_form, path_expected_user_form)
}
expected_data_user <- retrieve_expected(path_expected_user )
expected_data_user_form <- retrieve_expected(path_expected_user_form)

expect_equal(returned_object$data_user , expected=expected_data_user , label="The returned data.frame should be correct", ignore_attr = TRUE) # dput(returned_object$data_user);
expect_equal(returned_object$data_user_form, expected=expected_data_user_form, label="The returned data.frame should be correct", ignore_attr = TRUE) # dput(returned_object$data_user_form)
expect_equal(d_user , expected=expected_data_user , label="The returned data.frame should be correct", ignore_attr = TRUE) # dput(returned_object$data_user);
expect_equal(d_user_form, expected=expected_data_user_form, label="The returned data.frame should be correct", ignore_attr = TRUE) # dput(returned_object$data_user_form)
expect_equal(returned_object$status_code, expected=200L)
expect_equal(returned_object$raw_text, expected="", ignore_attr = TRUE) # dput(returned_object$raw_text)
expect_match(returned_object$outcome_message, regexp=expected_outcome_message, perl=TRUE)
Expand Down

0 comments on commit f021279

Please sign in to comment.