diff --git a/R/skippers.R b/R/skippers.R new file mode 100644 index 00000000..7d0e31d2 --- /dev/null +++ b/R/skippers.R @@ -0,0 +1,7 @@ +skip_if_onlyread <- function() { + if (identical(Sys.getenv("ONLY_READ_TESTS"), "")) { + return(invisible(TRUE)) + } + + testthat::skip("Skipping test if only server reads/exports are used. (And server writes/imports are skipped.)" ) +} diff --git a/tests/testthat/test-skippers.R b/tests/testthat/test-skippers.R new file mode 100644 index 00000000..46d7b91d --- /dev/null +++ b/tests/testthat/test-skippers.R @@ -0,0 +1,12 @@ + +test_that("skip_if_onlyread set", { + # Test that a skip happens + withr::local_envvar(ONLY_READ_TESTS = "yes") + expect_condition(skip_if_onlyread(), class = "skip") +}) + +test_that("skip_if_onlyread not set", { + # Test that a skip doesn't happen + withr::local_envvar(ONLY_READ_TESTS = "") + expect_condition(skip_if_onlyread(), NA, class = "skip") +}) diff --git a/tests/testthat/test-write-batch.R b/tests/testthat/test-write-batch.R index 0076fa39..c55b1a4f 100644 --- a/tests/testthat/test-write-batch.R +++ b/tests/testthat/test-write-batch.R @@ -4,12 +4,16 @@ update_expectation <- FALSE test_that("Smoke Test", { testthat::skip_on_cran() + skip_if_onlyread() + start_clean_result <- REDCapR:::clean_start_simple(batch=TRUE) project <- start_clean_result$redcap_project }) test_that("default", { testthat::skip_on_cran() + skip_if_onlyread() + path_expected <- "test-data/specific-redcapr/write-batch/default.R" start_clean_result <- REDCapR:::clean_start_simple(batch=TRUE) project <- start_clean_result$redcap_project @@ -37,7 +41,9 @@ test_that("default", { }) test_that("update-one-field", { - testthat::skip_on_cran() + testthat::skip_on_cran + skip_if_onlyread() + path_expected <- "test-data/specific-redcapr/write-batch/update-one-field.R" start_clean_result <- REDCapR:::clean_start_simple(batch=TRUE) project <- start_clean_result$redcap_project @@ -77,6 +83,8 @@ test_that("update-one-field", { test_that("update-two-fields", { testthat::skip_on_cran() + skip_if_onlyread() + path_expected <- "test-data/specific-redcapr/write-batch/update-two-fields.R" start_clean_result <- REDCapR:::clean_start_simple(batch=TRUE) project <- start_clean_result$redcap_project @@ -116,6 +124,8 @@ test_that("update-two-fields", { }) test_that("Write Batch -Bad URI", { testthat::skip_on_cran() + skip_if_onlyread() + bad_uri <- "google.com" start_clean_result <- REDCapR:::clean_start_simple(batch=TRUE) project <- start_clean_result$redcap_project diff --git a/tests/testthat/test-write-dag.R b/tests/testthat/test-write-dag.R index 761cab5f..835afb7f 100644 --- a/tests/testthat/test-write-dag.R +++ b/tests/testthat/test-write-dag.R @@ -3,12 +3,16 @@ update_expectation <- FALSE test_that("Smoke Test", { testthat::skip_on_cran() + skip_if_onlyread() + start_clean_result <- REDCapR:::clean_start_dag_write(batch=FALSE) project <- start_clean_result$redcap_project }) test_that("default", { testthat::skip_on_cran() + skip_if_onlyread() + path_expected_before <- "test-data/specific-redcapr/write-dag/before.R" path_expected_after <- "test-data/specific-redcapr/write-dag/after.R" start_clean_result <- REDCapR:::clean_start_dag_write(batch=FALSE) @@ -55,6 +59,7 @@ test_that("default", { test_that("reassign subject to a different dag", { testthat::skip_on_cran() + skip_if_onlyread() # Step 1: Initialize the project start_clean_result <- REDCapR:::clean_start_dag_write(batch=FALSE) diff --git a/tests/testthat/test-write-error.R b/tests/testthat/test-write-error.R index 79d42593..71b76aff 100644 --- a/tests/testthat/test-write-error.R +++ b/tests/testthat/test-write-error.R @@ -4,6 +4,8 @@ update_expectation <- FALSE test_that("One Shot: writing with read-only privileges", { testthat::skip_on_cran() + skip_if_onlyread() + credential <- retrieve_credential_testing(project_id = 153L) # read-only # expect_message( # returned_object1 <- redcap_read_oneshot(redcap_uri=credential$redcap_uri, token=credential$token, raw_or_label="raw") @@ -35,6 +37,8 @@ test_that("One Shot: writing with read-only privileges", { test_that("Single Batch: writing with read-only privileges", { testthat::skip_on_cran() + skip_if_onlyread() + credential <- retrieve_credential_testing(project_id = 153L) # read-only expected_message <- "The REDCapR write/import operation was not successful. The error message was:\nERROR: You do not have API Import/Update privileges" @@ -54,6 +58,8 @@ test_that("Single Batch: writing with read-only privileges", { test_that("Many Batches: writing with read-only privileges", { testthat::skip_on_cran() + skip_if_onlyread() + credential <- retrieve_credential_testing(project_id = 153L) # read-only expected_message <- "The REDCapR write/import operation was not successful. The error message was:\nERROR: You do not have API Import/Update privileges" @@ -72,6 +78,8 @@ test_that("Many Batches: writing with read-only privileges", { test_that("Single Batch: writing with read-only privileges --contiue on error", { testthat::skip_on_cran() + skip_if_onlyread() + credential <- retrieve_credential_testing(project_id = 153L) # read-only expected_message <- "The REDCapR write/import operation was not successful. The error message was:\nERROR: You do not have API Import/Update privileges" @@ -94,6 +102,8 @@ test_that("Single Batch: writing with read-only privileges --contiue on error", test_that("Many Batches: writing with read-only privileges --contiue on error", { testthat::skip_on_cran() + skip_if_onlyread() + credential <- retrieve_credential_testing(project_id = 153L) # read-only expected_message <- "The REDCapR write/import operation was not successful. The error message was:\nERROR: You do not have API Import/Update privileges" diff --git a/tests/testthat/test-write-oneshot.R b/tests/testthat/test-write-oneshot.R index 62031fc8..3e14dfbe 100644 --- a/tests/testthat/test-write-oneshot.R +++ b/tests/testthat/test-write-oneshot.R @@ -3,12 +3,16 @@ update_expectation <- FALSE test_that("Smoke Test", { testthat::skip_on_cran() + skip_if_onlyread() + start_clean_result <- REDCapR:::clean_start_simple(batch=FALSE) project <- start_clean_result$redcap_project }) test_that("default", { testthat::skip_on_cran() + skip_if_onlyread() + path_expected <- "test-data/specific-redcapr/write-oneshot/default.R" start_clean_result <- REDCapR:::clean_start_simple(batch=FALSE) project <- start_clean_result$redcap_project @@ -37,6 +41,8 @@ test_that("default", { test_that("one-field", { testthat::skip_on_cran() + skip_if_onlyread() + path_expected <- "test-data/specific-redcapr/write-oneshot/one-field.R" expected_outcome_message <- "\\d+ records and \\d+ columns were read from REDCap in \\d+(\\.\\d+\\W|\\W)seconds\\." @@ -77,6 +83,8 @@ test_that("one-field", { test_that("two-fields", { testthat::skip_on_cran() + skip_if_onlyread() + path_expected <- "test-data/specific-redcapr/write-oneshot/two-fields.R" start_clean_result <- REDCapR:::clean_start_simple(batch=FALSE) project <- start_clean_result$redcap_project @@ -117,6 +125,8 @@ test_that("two-fields", { test_that("overwrite-false", { testthat::skip_on_cran() + skip_if_onlyread() + path_expected <- "test-data/specific-redcapr/write-oneshot/default.R" expected_outcome_message <- "\\d+ records and \\d+ columns were read from REDCap in \\d+(\\.\\d+\\W|\\W)seconds\\." @@ -158,6 +168,8 @@ test_that("overwrite-false", { test_that("overwrite-true", { testthat::skip_on_cran() + skip_if_onlyread() + path_expected <- "test-data/specific-redcapr/write-oneshot/overwrite-true.R" expected_outcome_message <- "\\d+ records and \\d+ columns were read from REDCap in \\d+(\\.\\d+\\W|\\W)seconds\\." diff --git a/utility/refresh.R b/utility/refresh.R index fb2fefce..c4f0015e 100644 --- a/utility/refresh.R +++ b/utility/refresh.R @@ -12,7 +12,7 @@ devtools::build_vignettes() checks_to_exclude <- c( "covr", - "cyclocomp", + # "cyclocomp"#, "lintr_line_length_linter" ) gp <- @@ -33,9 +33,10 @@ pkgdown::build_site() devtools::run_examples(); #dev.off() #This overwrites the NAMESPACE file too # devtools::run_examples(, "redcap_read.Rd") test_results_checked <- devtools::test() -test_results_checked <- devtools::test(filter = "write-error") test_results_checked <- devtools::test(filter = "column") test_results_checked <- devtools::test(filter = "validate.*$") +withr::local_envvar(ONLYREADTESTS = "true") +test_results_checked <- devtools::test(filter = "write-batch") # testthat::test_dir("./tests/") test_results_not_checked <- testthat::test_dir("./tests/manual/")