tests/testthat/helper-vcr.R

library("vcr")

vcr_dir <- vcr::vcr_test_path("fixtures")

# set_base_url("http://localhost:8000") # nolint uncomment when generating vcr cassettes to point test cases to local DB

if (!nzchar(Sys.getenv("OPENAQ_API_KEY"))) {
  if (dir.exists(vcr_dir)) {
    Sys.setenv("OPENAQ_API_KEY" = "test-api-key-0123456789-0123456789-0123456789-0123456789-0123456")
  } else {
    # If there's no mock files nor API token, impossible to run tests
    stop("No API key nor cassettes, tests cannot be run.",
      call. = FALSE
    )
  }
}

invisible(vcr::vcr_configure(
  dir = vcr_dir,
  filter_sensitive_data = list(
    "<<<test_openaq_api_key>>>" = Sys.getenv("OPENAQ_API_KEY")
  )
))

Try the openaq package in your browser

Any scripts or data that you put into this service are public.

openaq documentation built on March 19, 2026, 5:08 p.m.