Skip to content

Commit b4b709e

Browse files
authored
Merge pull request #216 from cmu-delphi/ndefries/check-dots-empty
Check that endpoint `...` are empty
2 parents 4235c9d + b07e3e3 commit b4b709e

File tree

3 files changed

+130
-0
lines changed

3 files changed

+130
-0
lines changed

R/endpoints.R

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ pub_covid_hosp_facility_lookup <- function(
8989
zip = NULL,
9090
fips_code = NULL,
9191
fetch_args = fetch_args_list()) {
92+
rlang::check_dots_empty()
93+
9294
assert_character_param("state", state, len = 1, required = FALSE)
9395
assert_character_param("ccn", ccn, len = 1, required = FALSE)
9496
assert_character_param("city", city, len = 1, required = FALSE)
@@ -171,6 +173,8 @@ pub_covid_hosp_facility <- function(
171173
...,
172174
publication_dates = NULL,
173175
fetch_args = fetch_args_list()) {
176+
rlang::check_dots_empty()
177+
174178
assert_character_param("hospital_pks", hospital_pks)
175179
assert_timeset_param("collection_weeks", collection_weeks)
176180
assert_timeset_param("publication_dates", publication_dates, required = FALSE)
@@ -465,6 +469,8 @@ pub_covid_hosp_facility <- function(
465469
#' @export
466470
#
467471
pub_covid_hosp_state_timeseries <- function(states, dates, ..., issues = NULL, fetch_args = fetch_args_list()) {
472+
rlang::check_dots_empty()
473+
468474
assert_character_param("states", states)
469475
assert_timeset_param("dates", dates)
470476
assert_timeset_param("issues", issues, required = FALSE)
@@ -711,6 +717,8 @@ pub_covidcast <- function(
711717
issues = NULL,
712718
lag = NULL,
713719
fetch_args = fetch_args_list()) {
720+
rlang::check_dots_empty()
721+
714722
# Check parameters
715723
if (
716724
missing(source) ||
@@ -919,6 +927,8 @@ pvt_dengue_sensors <- function(auth, names, locations, epiweeks, fetch_args = fe
919927
#' @keywords endpoint
920928
#' @export
921929
pub_ecdc_ili <- function(regions, epiweeks, ..., issues = NULL, lag = NULL, fetch_args = fetch_args_list()) {
930+
rlang::check_dots_empty()
931+
922932
assert_character_param("regions", regions)
923933
assert_timeset_param("epiweeks", epiweeks)
924934
assert_timeset_param("issues", issues, required = FALSE)
@@ -976,6 +986,8 @@ pub_ecdc_ili <- function(regions, epiweeks, ..., issues = NULL, lag = NULL, fetc
976986
#' @keywords endpoint
977987
#' @export
978988
pub_flusurv <- function(locations, epiweeks, ..., issues = NULL, lag = NULL, fetch_args = fetch_args_list()) {
989+
rlang::check_dots_empty()
990+
979991
assert_character_param("locations", locations)
980992
assert_timeset_param("epiweeks", epiweeks)
981993
assert_timeset_param("issues", issues, required = FALSE)
@@ -1032,6 +1044,8 @@ pub_flusurv <- function(locations, epiweeks, ..., issues = NULL, lag = NULL, fet
10321044
#' @keywords endpoint
10331045
#' @export
10341046
pub_fluview_clinical <- function(regions, epiweeks, ..., issues = NULL, lag = NULL, fetch_args = fetch_args_list()) {
1047+
rlang::check_dots_empty()
1048+
10351049
assert_character_param("regions", regions)
10361050
assert_timeset_param("epiweeks", epiweeks)
10371051
assert_timeset_param("issues", issues, required = FALSE)
@@ -1135,6 +1149,8 @@ pub_fluview <- function(
11351149
lag = NULL,
11361150
auth = NULL,
11371151
fetch_args = fetch_args_list()) {
1152+
rlang::check_dots_empty()
1153+
11381154
assert_character_param("regions", regions)
11391155
assert_timeset_param("epiweeks", epiweeks)
11401156
assert_timeset_param("issues", issues, required = FALSE)
@@ -1285,6 +1301,8 @@ pvt_ght <- function(auth, locations, epiweeks, query, fetch_args = fetch_args_li
12851301
#' @keywords endpoint
12861302
#' @export
12871303
pub_kcdc_ili <- function(regions, epiweeks, ..., issues = NULL, lag = NULL, fetch_args = fetch_args_list()) {
1304+
rlang::check_dots_empty()
1305+
12881306
assert_character_param("regions", regions)
12891307
assert_timeset_param("epiweeks", epiweeks)
12901308
assert_timeset_param("issues", issues, required = FALSE)
@@ -1414,6 +1432,8 @@ pub_nidss_dengue <- function(locations, epiweeks, fetch_args = fetch_args_list()
14141432
#' @keywords endpoint
14151433
#' @export
14161434
pub_nidss_flu <- function(regions, epiweeks, ..., issues = NULL, lag = NULL, fetch_args = fetch_args_list()) {
1435+
rlang::check_dots_empty()
1436+
14171437
assert_character_param("regions", regions)
14181438
assert_timeset_param("epiweeks", epiweeks)
14191439
assert_timeset_param("issues", issues, required = FALSE)
@@ -1545,6 +1565,8 @@ pub_nowcast <- function(locations, epiweeks, fetch_args = fetch_args_list()) {
15451565
#' @keywords endpoint
15461566
#' @export
15471567
pub_paho_dengue <- function(regions, epiweeks, ..., issues = NULL, lag = NULL, fetch_args = fetch_args_list()) {
1568+
rlang::check_dots_empty()
1569+
15481570
assert_character_param("regions", regions)
15491571
assert_timeset_param("epiweeks", epiweeks)
15501572
assert_timeset_param("issues", issues, required = FALSE)
@@ -1700,6 +1722,8 @@ pvt_sensors <- function(auth, names, locations, epiweeks, fetch_args = fetch_arg
17001722
#' @keywords endpoint
17011723
#' @export
17021724
pvt_twitter <- function(auth, locations, ..., dates = NULL, epiweeks = NULL, fetch_args = fetch_args_list()) {
1725+
rlang::check_dots_empty()
1726+
17031727
assert_character_param("auth", auth, len = 1)
17041728
assert_character_param("locations", locations)
17051729
assert_timeset_param("dates", dates, required = FALSE)
@@ -1768,6 +1792,8 @@ pub_wiki <- function(
17681792
hours = NULL,
17691793
language = "en",
17701794
fetch_args = fetch_args_list()) {
1795+
rlang::check_dots_empty()
1796+
17711797
assert_character_param("articles", articles)
17721798
assert_timeset_param("dates", dates, required = FALSE)
17731799
assert_timeset_param("epiweeks", epiweeks, required = FALSE)

R/epidatacall.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ fetch_args_list <- function(
144144
dry_run = FALSE,
145145
debug = FALSE,
146146
format_type = c("json", "classic", "csv")) {
147+
rlang::check_dots_empty()
148+
147149
assert_character(fields, null.ok = TRUE, any.missing = FALSE)
148150
assert_logical(disable_date_parsing, null.ok = FALSE, len = 1L, any.missing = FALSE)
149151
assert_logical(disable_data_frame_parsing, null.ok = FALSE, len = 1L, any.missing = FALSE)

tests/testthat/test-endpoints.R

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,105 @@ test_that("basic_epidata_call", {
146146
fetch_args = fetch_args_list(dry_run = TRUE)
147147
) %>% request_url())
148148
})
149+
150+
test_that("endpoints fail when given args via dots", {
151+
dots_error <- "`...` must be empty"
152+
153+
# time value/epiweek arg is passed erroneously as `date_range`
154+
expect_error(
155+
pub_covid_hosp_facility_lookup(
156+
state = "fl",
157+
date_range = 20200101
158+
),
159+
regexp = dots_error
160+
)
161+
expect_error(
162+
pub_covid_hosp_facility(
163+
hospital_pks = "100075",
164+
date_range = epirange(20200101, 20200501)
165+
),
166+
regexp = dots_error
167+
)
168+
expect_error(
169+
pub_covid_hosp_state_timeseries(
170+
states = "fl",
171+
date_range = epirange(20200101, 20200501)
172+
),
173+
regexp = dots_error
174+
)
175+
expect_error(
176+
pub_covidcast(
177+
source = "jhu-csse",
178+
signals = "confirmed_7dav_incidence_prop",
179+
time_type = "day",
180+
geo_type = "state",
181+
date_range = epirange(20200601, 20200801),
182+
geo_values = "ca,fl"
183+
),
184+
regexp = dots_error
185+
)
186+
expect_error(
187+
pub_ecdc_ili(
188+
regions = "austria",
189+
date_range = epirange(201201, 202001)
190+
),
191+
regexp = dots_error
192+
)
193+
expect_error(
194+
pub_flusurv(
195+
locations = "CA",
196+
date_range = epirange(201201, 202001)
197+
),
198+
regexp = dots_error
199+
)
200+
expect_error(
201+
pub_fluview_clinical(
202+
regions = "nat",
203+
date_range = epirange(201601, 201701)
204+
),
205+
regexp = dots_error
206+
)
207+
expect_error(
208+
pub_fluview(
209+
regions = "nat",
210+
date_range = epirange(201601, 201701)
211+
),
212+
regexp = dots_error
213+
)
214+
expect_error(
215+
pub_kcdc_ili(
216+
regions = "?",
217+
date_range = epirange(201201, 202001)
218+
),
219+
regexp = dots_error
220+
)
221+
expect_error(
222+
pub_nidss_flu(
223+
regions = "taipei",
224+
date_range = epirange(201201, 202001)
225+
),
226+
regexp = dots_error
227+
)
228+
expect_error(
229+
pub_paho_dengue(
230+
regions = "ca",
231+
date_range = epirange(201201, 202001)
232+
),
233+
regexp = dots_error
234+
)
235+
expect_error(
236+
pvt_twitter(
237+
auth = "yourkey",
238+
locations = "CA",
239+
date_range = epirange(201501, 202001)
240+
),
241+
regexp = dots_error
242+
)
243+
expect_error(
244+
pub_wiki(
245+
articles = "avian_influenza",
246+
date_range = epirange(201501, 202001)
247+
),
248+
regexp = dots_error
249+
)
250+
})

0 commit comments

Comments
 (0)