Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: use httptest for API mocking #410

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ Maintainer: Tamás Stirling <[email protected]>
LazyLoad: yes
LazyData: yes
Encoding: UTF-8
Depends:
Depends:
R (>= 3.0)
Imports:
Imports:
xml2,
httr,
rvest,
Expand All @@ -41,14 +41,15 @@ Imports:
base64enc,
rlang,
utils
Suggests:
testthat,
rcdk,
Suggests:
covr,
robotstxt,
httptest,
knitr,
rmarkdown,
plot.matrix,
rcdk,
rmarkdown,
robotstxt,
testthat,
usethis,
vcr
RoxygenNote: 7.2.3
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

* `pc_prop()` returned `NA` without much further explanation if any of the queries were not positive integers. The updated function attempts to coerce queries to positive integers, only progresses valid queries, and prints informative messages along the way if verbose messages are enabled.

## MINOR CHANGES
* The `test_service_down` argument has been removed from `chembl_query()`. Since it was only intended for use in testing, it shouldn't impact code using this function.

# webchem 1.3.0

## NEW FEATURES
Expand Down
7 changes: 2 additions & 5 deletions R/chembl.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#' @param cache_file character; the name of the cache file without the file
#' extension. If \code{NULL}, results are not cached.
#' @param verbose logical; should a verbose output be printed on the console?
#' @param test_service_down logical; this argument is only used for testing.
#' @return The function returns a list of lists, where each element of the list
#' contains a list of respective query results. Results are simplified, if
#' possible.
Expand Down Expand Up @@ -56,8 +55,7 @@
chembl_query <- function(query,
resource = "molecule",
cache_file = NULL,
verbose = getOption("verbose"),
test_service_down = FALSE) {
verbose = getOption("verbose")) {
resource <- match.arg(resource, chembl_resources())
stem <- "https://www.ebi.ac.uk/chembl/api/data"
foo <- function(query, verbose) {
Expand All @@ -70,8 +68,7 @@ chembl_query <- function(query,
return(NA)
}
if (verbose) webchem_message("query", query, appendLF = FALSE)
url <- ifelse(
test_service_down, "", paste0(stem, "/", resource, "/", query, ".json"))
url <- paste0(stem, "/", resource, "/", query, ".json")
webchem_sleep(type = "API")
res <- try(httr::RETRY("GET",
url,
Expand Down
11 changes: 11 additions & 0 deletions inst/httptest/redact.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#shortens file paths created by httptest so that R CMD check doesn't complain
httptest::set_redactor(
function (resp) {
resp |>
httptest::gsub_response("property/.*/", "property/") |>
httptest::gsub_response("www.ebi.ac.uk-80/webservices/chebi/2.0/", "chebi/") |>
httptest::gsub_response("www.ebi.ac.uk/chembl/api/data/", "chembl/") |>
httptest::gsub_response("api.rsc.org/compounds/v1/filter/", "cs/") |>
httptest::gsub_response("webetox.uba.de/webETOX/public/search/", "etox/")
}
)
5 changes: 1 addition & 4 deletions man/chembl_query.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading