Skip to content

Commit

Permalink
adjust to new server's error message
Browse files Browse the repository at this point in the history
I think all this is related to the web server, and how it handles non-SSL request.  I think it's unrelated to REDCap itself.

ref #396

https://stackoverflow.com/questions/51547900/rcurlgeturl-works-httrget-has-failure-when-receiving-data-from-the-peer/52465562

r-lib/httr#568
  • Loading branch information
wibeasley committed Jul 19, 2022
1 parent 4db9464 commit 2c0da3b
Showing 1 changed file with 46 additions and 34 deletions.
80 changes: 46 additions & 34 deletions tests/testthat/test-read-errors.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ credential <- retrieve_credential_testing()

test_that("One Shot: Bad Uri -Not HTTPS", {
testthat::skip_on_cran()
testthat::skip("Temporarily skip testing responses to the bad urls.")
expected_error <- "The url `http://bbmc.ouhsc.edu/redcap/api/` is not found or throws an error\\."
# expected_message_411 <- "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\"http://www.w3.org/TR/html4/strict.dtd\">\n<HTML><HEAD><TITLE>Length Required</TITLE>\n<META HTTP-EQUIV=\"Content-Type\" Content=\"text/html; charset=us-ascii\"></HEAD>\n<BODY><h2>Length Required</h2>\n<hr><p>HTTP Error 411. The request must be chunked or have a content length.</p>\n</BODY></HTML>\n"
# expected_message_501 <- "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><hash><error>The requested method is not implemented.</error></hash>"

expect_error(
redcap_read_oneshot(
redcap_uri = "http://bbmc.ouhsc.edu/redcap/api/", # Not HTTPS
token = credential$token
),
regexp=
# returned_object <-
redcap_read_oneshot(
redcap_uri = "http://bbmc.ouhsc.edu/redcap/api/", # Not HTTPS
token = credential$token
)
)

# expect_equal(returned_object$data, expected=data.frame(), label="An empty data.frame should be returned.")
Expand All @@ -28,30 +26,38 @@ test_that("One Shot: Bad Uri -Not HTTPS", {

test_that("One Shot: Bad Uri -wrong address", {
testthat::skip_on_cran()
testthat::skip("Temporarily skip testing responses to the bad urls.")
expected_message <- "The url `https://bbmc.ouhsc.edu/redcap/apiFFFFFFFFFFFFFF/` is not found or throws an error\\."

expect_error(
redcap_read_oneshot(
redcap_uri = "https://bbmc.ouhsc.edu/redcap/apiFFFFFFFFFFFFFF/", # Wrong url
token = credential$token
),
expected_message
# expected_message <- "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"/>\n<title>404 - File or directory not found.</title>\n<style type=\"text/css\">\n<!--\nbody{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}\nfieldset{padding:0 15px 10px 15px;} \nh1{font-size:2.4em;margin:0;color:#FFF;}\nh2{font-size:1.7em;margin:0;color:#CC0000;} \nh3{font-size:1.2em;margin:10px 0 0 0;color:#000000;} \n#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:\"trebuchet MS\", Verdana, sans-serif;color:#FFF;\nbackground-color:#555555;}\n#content{margin:0 0 0 2%;position:relative;}\n.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}\n-->\n</style>\n</head>\n<body>\n<div id=\"header\"><h1>Server Error</h1></div>\n<div id=\"content\">\n <div class=\"content-container\"><fieldset>\n <h2>404 - File or directory not found.</h2>\n <h3>The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.</h3>\n </fieldset></div>\n</div>\n</body>\n</html>\n"
expected_message <- "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n<title>404 Not Found</title>\n</head><body>\n<h1>Not Found</h1>\n<p>The requested URL was not found on this server.</p>\n</body></html>\n"

# expected_outcome_message <- "The initial call failed with the code: 404."
# expected_outcome_message <- "The requested URL was not found on this server."

expect_message(
returned_object <-
redcap_read_oneshot(
redcap_uri = "https://bbmc.ouhsc.edu/redcap/apiFFFFFFFFFFFFFF/", # Wrong url
token = credential$token
)
)

expect_equal(returned_object$data, expected=data.frame(), label="An empty data.frame should be returned.")
expect_equal(returned_object$status_code, expected=404L)
expect_equal(returned_object$raw_text, expected=expected_message)
expect_equal(returned_object$records_collapsed, "")
expect_equal(returned_object$fields_collapsed, "")
expect_false(returned_object$success)
})

test_that("Batch: Bad Uri -Not HTTPS", {
testthat::skip_on_cran()
testthat::skip("Temporarily skip testing responses to the bad urls.")
expected_error <- "The url `http://bbmc.ouhsc.edu/redcap/api/` is not found or throws an error\\."
# expected_outcome_message <- "The initial call failed with the code: (411|501)."

expect_error(
redcap_read(
redcap_uri = "http://bbmc.ouhsc.edu/redcap/api/", # Not HTTPS
token = credential$token
),
expected_error
# returned_object <-
redcap_read(
redcap_uri = "http://bbmc.ouhsc.edu/redcap/api/", # Not HTTPS
token = credential$token
)
)

# expect_equal(returned_object$data, expected=data.frame(), label="An empty data.frame should be returned.")
Expand All @@ -64,21 +70,28 @@ test_that("Batch: Bad Uri -Not HTTPS", {

test_that("Batch: Bad Uri -wrong address", {
testthat::skip_on_cran()
testthat::skip("Temporarily skip testing responses to the bad urls.")
expected_error <- "The url `https://bbmc.ouhsc.edu/redcap/apiFFFFFFFFFFFFFF/` is not found or throws an error."

expect_error(
redcap_read(
redcap_uri = "https://bbmc.ouhsc.edu/redcap/apiFFFFFFFFFFFFFF/", # Wrong url
token = credential$token
),
expected_error
expected_message <- "The initial call failed with the code: 404."
# expected_message <- "The requested URL was not found on this server."

expect_message(
returned_object <-
redcap_read(
redcap_uri = "https://bbmc.ouhsc.edu/redcap/apiFFFFFFFFFFFFFF/", # Wrong url
token = credential$token
),
"The requested URL was not found on this server."
)

expect_equal(returned_object$data, expected=data.frame(), label="An empty data.frame should be returned.")
expect_equal(returned_object$status_code, expected=404L)
expect_equal(returned_object$records_collapsed, "failed in initial batch call")
expect_equal(returned_object$fields_collapsed, "failed in initial batch call")
expect_equal(returned_object$outcome_messages, expected_message)
expect_false(returned_object$success)
})

test_that("hashed record -warn", {
testthat::skip_on_cran()
testthat::skip("Temporarily skip testing responses to the bad urls.")
# This dinky little test is mostly to check that the warning message has legal syntax.
expected_warning <- "^It appears that the REDCap record IDs have been hashed.+"

Expand All @@ -90,7 +103,6 @@ test_that("hashed record -warn", {

test_that("guess_max deprecated -warn", {
testthat::skip_on_cran()
testthat::skip("Temporarily skip testing responses to the bad urls.")
expected_outcome_message <- "The `guess_max` parameter in `REDCapR::redcap_read\\(\\)` is deprecated\\."

expect_warning(
Expand Down

0 comments on commit 2c0da3b

Please sign in to comment.