Skip to content

Commit

Permalink
bad URIs now throw an error
Browse files Browse the repository at this point in the history
  • Loading branch information
wibeasley committed Aug 14, 2019
1 parent e47f4f6 commit e542155
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Authors@R: c(person("Will", "Beasley", role = c("aut", "cre"), email =
"[email protected]"), person("Benjamin", "Nutter",
role = "ctb"), person("Andrew", "Peters",
role = "ctb"), person("Hao", "Zhu",
role = "ctb"),
comment = c(ORCID = '0000-0002-3386-6076'))
role = "ctb",
comment = c(ORCID = '0000-0002-3386-6076')))
Author: Will Beasley [aut, cre],
David Bard [ctb],
Thomas Wilson [ctb],
Expand Down
2 changes: 1 addition & 1 deletion tests/test-all.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Modeled after the R6 testing structure: https://github.com/wch/R6/blob/master/tests/testthat.R
# Modeled after the R6 testing structure: https://github.com/wch/R6/blob/master/tests/testthat.R
library(testthat)
library(REDCapR)

Expand Down
21 changes: 12 additions & 9 deletions tests/testthat/test-variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,24 @@ test_that("All Records -Default", {

test_that("Bad URI", {
testthat::skip_on_cran()
bad_uri <- "google.com"
bad_uri <- "https://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com"
expected_data_frame <- structure(list(), .Names = character(0), row.names = integer(0), class = "data.frame")

expected_outcome_message <- "The REDCapR variable retrieval was not successful\\..+?Error 405 \\(Method Not Allowed\\).+"
expected_outcome_message <- "Failed to connect to aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com port 44" #
# "The REDCapR variable retrieval was not successful\\..+?Error 405 \\(Method Not Allowed\\).+"
# expected_outcome_message <- "(?s)The REDCapR variable retrieval was not successful\\..+?.+"

expect_message(
expect_error(
returned_object <- redcap_variables(redcap_uri=bad_uri, token=credential$token),
regexp = expected_outcome_message
)
expected_outcome_message <- paste0("(?s)", expected_outcome_message)

expect_equal(returned_object$data, expected=expected_data_frame, label="The returned data.frame should be correct") # dput(returned_object$data)
expect_equal(returned_object$status_code, expected=405L)
# expect_equivalent(returned_object$raw_text, expected="") # dput(returned_object$raw_text)
expect_match(returned_object$outcome_message, regexp=expected_outcome_message, perl=TRUE)
expect_false(returned_object$success)
# Now thean error is thrown with a bad URI.
# expected_outcome_message <- paste0("(?s)", expected_outcome_message)
#
# expect_equal(returned_object$data, expected=expected_data_frame, label="The returned data.frame should be correct") # dput(returned_object$data)
# expect_equal(returned_object$status_code, expected=405L)
# # expect_equivalent(returned_object$raw_text, expected="") # dput(returned_object$raw_text)
# expect_match(returned_object$outcome_message, regexp=expected_outcome_message, perl=TRUE)
# expect_false(returned_object$success)
})

0 comments on commit e542155

Please sign in to comment.