Skip to content

Commit

Permalink
updated httptest and mock tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarneche committed May 20, 2023
1 parent e5ac9bf commit 11f85dd
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 118 deletions.
19 changes: 2 additions & 17 deletions test_running_updating.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,17 @@
From `dataaimsr/`, run

```{r}
library(httptest) # installed from https://github.com/nealrichardson/httptest/commit/5fc2be9f8627fa36d04ee06de0291c1d7633d1a8
library(testthat)
library(roxygen2)
library(devtools)
system("rm -rf tests/api")
roxygen2::roxygenise()
devtools::install(build_vignettes = FALSE)
testthat::test_local(".")
all_mock_dirs <- dir("tests/api", full.names = TRUE, recursive = TRUE) |>
dirname() |>
unique()
new_mock_dirs <- gsub(
"api.aims.gov.au/data-v2.0/10.25845", "a", all_mock_dirs, fixed = TRUE
)
for (i in seq_along(all_mock_dirs)) {
system(paste0("mkdir -p ", new_mock_dirs[i]))
system(paste0(
"cp -R ", all_mock_dirs[i], "/* ", new_mock_dirs[i], "/" , collapse = ""
))
to_rm <- dirname(all_mock_dirs[i]) |>
dirname() |>
dirname()
system(paste0("rm -rf ", to_rm))
}
```

This will delete all existing mock files and regenerate them. Then return to root directory and check if it all passes:
The above block will delete all existing mock files and regenerate them. Then return to root directory and check if it all passes:

```{r}
rm(list = ls())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
{
"series_id": 55,
"series": "Cleveland Bay Weather Station Maximum Wind Speed 10 Minutes",
"series_short": "Max Wind Speed 10 mins"
"series_short": "Wind Speed 10 mins"
},
{
"series_id": 57,
Expand Down Expand Up @@ -5201,8 +5201,8 @@
},
{
"series_id": 112711,
"series": "Masig Island Weather Station Depth @3m",
"series_short": "Depth @3m"
"series": "CHANNEL 112711",
"series_short": "CHANNEL 112711"
},
{
"series_id": 113847,
Expand Down
20 changes: 10 additions & 10 deletions tests/api/Correctly-process-requests/a/5c09bf93f315d/wrong.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
structure(list(url = "https://api.aims.gov.au/data-v2.0/10.25845/5c09bf93f315d/wrong",
status_code = 403L, headers = structure(list(date = "Fri, 19 May 2023 03:36:12 GMT",
status_code = 403L, headers = structure(list(date = "Fri, 19 May 2023 05:57:03 GMT",
`content-type` = "application/json", `content-length` = "42",
`x-amzn-requestid` = "fd777f58-dedd-4cd9-b280-aedfcee9b141",
`x-amzn-requestid` = "64a48c61-4f38-4100-b948-d50d1654c7c9",
`x-amzn-errortype` = "MissingAuthenticationTokenException",
`x-amz-apigw-id` = "FJo6_FssSwMF-Ig="), class = c("insensitive",
`x-amz-apigw-id` = "FJ9jhG4dSwMF13A="), class = c("insensitive",
"list")), all_headers = list(list(status = 403L, version = "HTTP/2",
headers = structure(list(date = "Fri, 19 May 2023 03:36:12 GMT",
headers = structure(list(date = "Fri, 19 May 2023 05:57:03 GMT",
`content-type` = "application/json", `content-length` = "42",
`x-amzn-requestid` = "fd777f58-dedd-4cd9-b280-aedfcee9b141",
`x-amzn-requestid` = "64a48c61-4f38-4100-b948-d50d1654c7c9",
`x-amzn-errortype` = "MissingAuthenticationTokenException",
`x-amz-apigw-id` = "FJo6_FssSwMF-Ig="), class = c("insensitive",
`x-amz-apigw-id` = "FJ9jhG4dSwMF13A="), class = c("insensitive",
"list")))), cookies = structure(list(domain = logical(0),
flag = logical(0), path = logical(0), secure = logical(0),
expiration = structure(numeric(0), class = c("POSIXct",
"POSIXt")), name = logical(0), value = logical(0)), row.names = integer(0), class = "data.frame"),
content = charToRaw("{\"message\":\"Missing Authentication Token\"}"),
date = structure(1684467372, class = c("POSIXct", "POSIXt"
), tzone = "GMT"), times = c(redirect = 0, namelookup = 5.4e-05,
connect = 0, pretransfer = 0.000249, starttransfer = 0.060357,
total = 0.060455)), class = "response")
date = structure(1684475823, class = c("POSIXct", "POSIXt"
), tzone = "GMT"), times = c(redirect = 0, namelookup = 7.1e-05,
connect = 0, pretransfer = 0.000223, starttransfer = 0.066316,
total = 0.067288)), class = "response")
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
structure(list(url = "https://api.aims.gov.au/data-v2.0/10.25845/5c09bf93f315d/wrong",
status_code = 403L, headers = structure(list(date = "Fri, 19 May 2023 03:36:13 GMT",
status_code = 403L, headers = structure(list(date = "Fri, 19 May 2023 05:57:04 GMT",
`content-type` = "application/json", `content-length` = "42",
`x-amzn-requestid` = "ae56f5ca-ba75-4bd0-9b91-f38a371e413f",
`x-amzn-requestid` = "23a99114-d55f-4f9c-9085-0ff6a9a83c49",
`x-amzn-errortype` = "MissingAuthenticationTokenException",
`x-amz-apigw-id` = "FJo7JGKjSwMFesw="), class = c("insensitive",
`x-amz-apigw-id` = "FJ9jrE56ywMFujQ="), class = c("insensitive",
"list")), all_headers = list(list(status = 403L, version = "HTTP/2",
headers = structure(list(date = "Fri, 19 May 2023 03:36:13 GMT",
headers = structure(list(date = "Fri, 19 May 2023 05:57:04 GMT",
`content-type` = "application/json", `content-length` = "42",
`x-amzn-requestid` = "ae56f5ca-ba75-4bd0-9b91-f38a371e413f",
`x-amzn-requestid` = "23a99114-d55f-4f9c-9085-0ff6a9a83c49",
`x-amzn-errortype` = "MissingAuthenticationTokenException",
`x-amz-apigw-id` = "FJo7JGKjSwMFesw="), class = c("insensitive",
`x-amz-apigw-id` = "FJ9jrE56ywMFujQ="), class = c("insensitive",
"list")))), cookies = structure(list(domain = logical(0),
flag = logical(0), path = logical(0), secure = logical(0),
expiration = structure(numeric(0), class = c("POSIXct",
"POSIXt")), name = logical(0), value = logical(0)), row.names = integer(0), class = "data.frame"),
content = charToRaw("{\"message\":\"Missing Authentication Token\"}"),
date = structure(1684467373, class = c("POSIXct", "POSIXt"
), tzone = "GMT"), times = c(redirect = 0, namelookup = 5.4e-05,
connect = 0, pretransfer = 0.000249, starttransfer = 0.059326,
total = 0.059432)), class = "response")
date = structure(1684475824, class = c("POSIXct", "POSIXt"
), tzone = "GMT"), times = c(redirect = 0, namelookup = 2.5e-05,
connect = 0, pretransfer = 0.000111, starttransfer = 0.060877,
total = 0.061022)), class = "response")
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
structure(list(url = "https://api.aims.gov.au/data-v2.0/10.25845/5c09bf93f315d/wrong",
status_code = 403L, headers = structure(list(date = "Fri, 19 May 2023 03:36:11 GMT",
status_code = 403L, headers = structure(list(date = "Fri, 19 May 2023 05:57:02 GMT",
`content-type` = "application/json", `content-length` = "42",
`x-amzn-requestid` = "ef8928da-761e-44dd-b819-12b164e7d5c0",
`x-amzn-requestid` = "2212242a-1cd6-4c5d-acb2-638375388e7a",
`x-amzn-errortype` = "MissingAuthenticationTokenException",
`x-amz-apigw-id` = "FJo62ECJywMF7_A="), class = c("insensitive",
`x-amz-apigw-id` = "FJ9jYH4mSwMFY9A="), class = c("insensitive",
"list")), all_headers = list(list(status = 403L, version = "HTTP/2",
headers = structure(list(date = "Fri, 19 May 2023 03:36:11 GMT",
headers = structure(list(date = "Fri, 19 May 2023 05:57:02 GMT",
`content-type` = "application/json", `content-length` = "42",
`x-amzn-requestid` = "ef8928da-761e-44dd-b819-12b164e7d5c0",
`x-amzn-requestid` = "2212242a-1cd6-4c5d-acb2-638375388e7a",
`x-amzn-errortype` = "MissingAuthenticationTokenException",
`x-amz-apigw-id` = "FJo62ECJywMF7_A="), class = c("insensitive",
`x-amz-apigw-id` = "FJ9jYH4mSwMFY9A="), class = c("insensitive",
"list")))), cookies = structure(list(domain = logical(0),
flag = logical(0), path = logical(0), secure = logical(0),
expiration = structure(numeric(0), class = c("POSIXct",
"POSIXt")), name = logical(0), value = logical(0)), row.names = integer(0), class = "data.frame"),
content = charToRaw("{\"message\":\"Missing Authentication Token\"}"),
date = structure(1684467371, class = c("POSIXct", "POSIXt"
), tzone = "GMT"), times = c(redirect = 0, namelookup = 5.4e-05,
connect = 0, pretransfer = 0.000264, starttransfer = 0.060373,
total = 0.060442)), class = "response")
date = structure(1684475822, class = c("POSIXct", "POSIXt"
), tzone = "GMT"), times = c(redirect = 0, namelookup = 2.5e-05,
connect = 0, pretransfer = 0.000103, starttransfer = 0.060823,
total = 0.060888)), class = "response")
24 changes: 12 additions & 12 deletions tests/api/Wrong-filters-aimsdata/a/5c09bf93f315d/data-3f57c4.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
structure(list(url = "https://api.aims.gov.au/data-v2.0/10.25845/5c09bf93f315d/data?series=2687",
status_code = 422L, headers = structure(list(date = "Fri, 19 May 2023 03:29:56 GMT",
status_code = 422L, headers = structure(list(date = "Fri, 19 May 2023 05:50:55 GMT",
`content-type` = "application/json", `content-length` = "176",
`x-amzn-requestid` = "eba48af2-71d5-4e55-8ef1-17d9dbf28e76",
`x-amzn-remapped-content-length` = "176", `x-amz-apigw-id` = "FJoAOG50SwMFaAA=",
`x-amzn-trace-id` = "Root=1-6466ed34-1d9826083a1e73c64c3ef612;Sampled=0;lineage=31aaf29f:0"), class = c("insensitive",
`x-amzn-requestid` = "015f3bf8-c487-4e68-9fe3-1f319ab59b90",
`x-amzn-remapped-content-length` = "176", `x-amz-apigw-id` = "FJ8p-GW-ywMFSxg=",
`x-amzn-trace-id` = "Root=1-64670e3f-0ebf2596038f2f42623d5b34;Sampled=0;lineage=31aaf29f:0"), class = c("insensitive",
"list")), all_headers = list(list(status = 422L, version = "HTTP/2",
headers = structure(list(date = "Fri, 19 May 2023 03:29:56 GMT",
headers = structure(list(date = "Fri, 19 May 2023 05:50:55 GMT",
`content-type` = "application/json", `content-length` = "176",
`x-amzn-requestid` = "eba48af2-71d5-4e55-8ef1-17d9dbf28e76",
`x-amzn-remapped-content-length` = "176", `x-amz-apigw-id` = "FJoAOG50SwMFaAA=",
`x-amzn-trace-id` = "Root=1-6466ed34-1d9826083a1e73c64c3ef612;Sampled=0;lineage=31aaf29f:0"), class = c("insensitive",
`x-amzn-requestid` = "015f3bf8-c487-4e68-9fe3-1f319ab59b90",
`x-amzn-remapped-content-length` = "176", `x-amz-apigw-id` = "FJ8p-GW-ywMFSxg=",
`x-amzn-trace-id` = "Root=1-64670e3f-0ebf2596038f2f42623d5b34;Sampled=0;lineage=31aaf29f:0"), class = c("insensitive",
"list")))), cookies = structure(list(domain = logical(0),
flag = logical(0), path = logical(0), secure = logical(0),
expiration = structure(numeric(0), class = c("POSIXct",
"POSIXt")), name = logical(0), value = logical(0)), row.names = integer(0), class = "data.frame"),
content = charToRaw("{\"detail\":[{\"loc\":[\"query\",\"from_date\"],\"msg\":\"field required\",\"type\":\"value_error.missing\"},{\"loc\":[\"query\",\"thru_date\"],\"msg\":\"field required\",\"type\":\"value_error.missing\"}]}"),
date = structure(1684466996, class = c("POSIXct", "POSIXt"
), tzone = "GMT"), times = c(redirect = 0, namelookup = 4.5e-05,
connect = 0, pretransfer = 0.000135, starttransfer = 0.137363,
total = 0.137447)), class = "response")
date = structure(1684475455, class = c("POSIXct", "POSIXt"
), tzone = "GMT"), times = c(redirect = 0, namelookup = 2.5e-05,
connect = 0, pretransfer = 0.000112, starttransfer = 0.141456,
total = 0.141584)), class = "response")
24 changes: 12 additions & 12 deletions tests/api/Wrong-filters-aimsdata/a/5c09bf93f315d/data-aa36ae.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
structure(list(url = "https://api.aims.gov.au/data-v2.0/10.25845/5c09bf93f315d/data?series_id=2687&from_date=1900-01-01&thru_date=1900-01-10",
status_code = 500L, headers = structure(list(date = "Fri, 19 May 2023 03:29:56 GMT",
status_code = 500L, headers = structure(list(date = "Fri, 19 May 2023 05:50:55 GMT",
`content-type` = "text/plain; charset=utf-8", `content-length` = "21",
`x-amzn-requestid` = "e7c91009-5e37-44bd-a441-80742ccfdf74",
`x-amzn-remapped-content-length` = "21", `x-amz-apigw-id` = "FJoAQFsDSwMFbnA=",
`x-amzn-trace-id` = "Root=1-6466ed34-616fd7d016f61c3b72584f47;Sampled=0;lineage=31aaf29f:0"), class = c("insensitive",
`x-amzn-requestid` = "a0190d2d-2115-4662-945b-6ae1567897fc",
`x-amzn-remapped-content-length` = "21", `x-amz-apigw-id` = "FJ8p_H84ywMFWIQ=",
`x-amzn-trace-id` = "Root=1-64670e3f-0f303f32637c42770dde5b8a;Sampled=0;lineage=31aaf29f:0"), class = c("insensitive",
"list")), all_headers = list(list(status = 500L, version = "HTTP/2",
headers = structure(list(date = "Fri, 19 May 2023 03:29:56 GMT",
headers = structure(list(date = "Fri, 19 May 2023 05:50:55 GMT",
`content-type` = "text/plain; charset=utf-8", `content-length` = "21",
`x-amzn-requestid` = "e7c91009-5e37-44bd-a441-80742ccfdf74",
`x-amzn-remapped-content-length` = "21", `x-amz-apigw-id` = "FJoAQFsDSwMFbnA=",
`x-amzn-trace-id` = "Root=1-6466ed34-616fd7d016f61c3b72584f47;Sampled=0;lineage=31aaf29f:0"), class = c("insensitive",
`x-amzn-requestid` = "a0190d2d-2115-4662-945b-6ae1567897fc",
`x-amzn-remapped-content-length` = "21", `x-amz-apigw-id` = "FJ8p_H84ywMFWIQ=",
`x-amzn-trace-id` = "Root=1-64670e3f-0f303f32637c42770dde5b8a;Sampled=0;lineage=31aaf29f:0"), class = c("insensitive",
"list")))), cookies = structure(list(domain = logical(0),
flag = logical(0), path = logical(0), secure = logical(0),
expiration = structure(numeric(0), class = c("POSIXct",
"POSIXt")), name = logical(0), value = logical(0)), row.names = integer(0), class = "data.frame"),
content = charToRaw("Internal Server Error"), date = structure(1684466996, class = c("POSIXct",
"POSIXt"), tzone = "GMT"), times = c(redirect = 0, namelookup = 0.000172,
connect = 0, pretransfer = 0.000249, starttransfer = 0.151445,
total = 0.151627)), class = "response")
content = charToRaw("Internal Server Error"), date = structure(1684475455, class = c("POSIXct",
"POSIXt"), tzone = "GMT"), times = c(redirect = 0, namelookup = 3.7e-05,
connect = 0, pretransfer = 0.000146, starttransfer = 0.146226,
total = 0.146561)), class = "response")
24 changes: 12 additions & 12 deletions tests/api/Wrong-filters-pagedata/a/5c09bf93f315d/data-3f57c4.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
structure(list(url = "https://api.aims.gov.au/data-v2.0/10.25845/5c09bf93f315d/data?series=2687",
status_code = 422L, headers = structure(list(date = "Fri, 19 May 2023 03:36:19 GMT",
status_code = 422L, headers = structure(list(date = "Fri, 19 May 2023 05:57:11 GMT",
`content-type` = "application/json", `content-length` = "176",
`x-amzn-requestid` = "c248aa8a-df40-4fa1-8ba8-9e346d5f815f",
`x-amzn-remapped-content-length` = "176", `x-amz-apigw-id` = "FJo8FGv-ywMFYGg=",
`x-amzn-trace-id` = "Root=1-6466eeb3-5eb001192634e611511939e6;Sampled=0;lineage=31aaf29f:0"), class = c("insensitive",
`x-amzn-requestid` = "5f380260-8f5d-44da-8435-b1132a3ad633",
`x-amzn-remapped-content-length` = "176", `x-amz-apigw-id` = "FJ9ktETkSwMFcuQ=",
`x-amzn-trace-id` = "Root=1-64670fb7-0e081065431dbe33401f0f0a;Sampled=0;lineage=31aaf29f:0"), class = c("insensitive",
"list")), all_headers = list(list(status = 422L, version = "HTTP/2",
headers = structure(list(date = "Fri, 19 May 2023 03:36:19 GMT",
headers = structure(list(date = "Fri, 19 May 2023 05:57:11 GMT",
`content-type` = "application/json", `content-length` = "176",
`x-amzn-requestid` = "c248aa8a-df40-4fa1-8ba8-9e346d5f815f",
`x-amzn-remapped-content-length` = "176", `x-amz-apigw-id` = "FJo8FGv-ywMFYGg=",
`x-amzn-trace-id` = "Root=1-6466eeb3-5eb001192634e611511939e6;Sampled=0;lineage=31aaf29f:0"), class = c("insensitive",
`x-amzn-requestid` = "5f380260-8f5d-44da-8435-b1132a3ad633",
`x-amzn-remapped-content-length` = "176", `x-amz-apigw-id` = "FJ9ktETkSwMFcuQ=",
`x-amzn-trace-id` = "Root=1-64670fb7-0e081065431dbe33401f0f0a;Sampled=0;lineage=31aaf29f:0"), class = c("insensitive",
"list")))), cookies = structure(list(domain = logical(0),
flag = logical(0), path = logical(0), secure = logical(0),
expiration = structure(numeric(0), class = c("POSIXct",
"POSIXt")), name = logical(0), value = logical(0)), row.names = integer(0), class = "data.frame"),
content = charToRaw("{\"detail\":[{\"loc\":[\"query\",\"from_date\"],\"msg\":\"field required\",\"type\":\"value_error.missing\"},{\"loc\":[\"query\",\"thru_date\"],\"msg\":\"field required\",\"type\":\"value_error.missing\"}]}"),
date = structure(1684467379, class = c("POSIXct", "POSIXt"
), tzone = "GMT"), times = c(redirect = 0, namelookup = 2.6e-05,
connect = 0, pretransfer = 0.000123, starttransfer = 0.165076,
total = 0.165162)), class = "response")
date = structure(1684475831, class = c("POSIXct", "POSIXt"
), tzone = "GMT"), times = c(redirect = 0, namelookup = 2.7e-05,
connect = 0, pretransfer = 9.7e-05, starttransfer = 0.145398,
total = 0.145453)), class = "response")
24 changes: 12 additions & 12 deletions tests/api/Wrong-filters-pagedata/a/5c09bf93f315d/data-aa36ae.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
structure(list(url = "https://api.aims.gov.au/data-v2.0/10.25845/5c09bf93f315d/data?series_id=2687&from_date=1900-01-01&thru_date=1900-01-10",
status_code = 500L, headers = structure(list(date = "Fri, 19 May 2023 03:36:19 GMT",
status_code = 500L, headers = structure(list(date = "Fri, 19 May 2023 05:57:11 GMT",
`content-type` = "text/plain; charset=utf-8", `content-length` = "21",
`x-amzn-requestid` = "23273b1d-4a61-4815-b519-fe37a5576138",
`x-amzn-remapped-content-length` = "21", `x-amz-apigw-id` = "FJo8HE4JywMFaAA=",
`x-amzn-trace-id` = "Root=1-6466eeb3-1dd3a891190586f664c8bc89;Sampled=0;lineage=31aaf29f:0"), class = c("insensitive",
`x-amzn-requestid` = "824b7281-c4e9-4173-a31d-ada3ef3e510c",
`x-amzn-remapped-content-length` = "21", `x-amz-apigw-id` = "FJ9kvHlzSwMF6zw=",
`x-amzn-trace-id` = "Root=1-64670fb7-5daa8ec65c0afa4c66e243fa;Sampled=0;lineage=31aaf29f:0"), class = c("insensitive",
"list")), all_headers = list(list(status = 500L, version = "HTTP/2",
headers = structure(list(date = "Fri, 19 May 2023 03:36:19 GMT",
headers = structure(list(date = "Fri, 19 May 2023 05:57:11 GMT",
`content-type` = "text/plain; charset=utf-8", `content-length` = "21",
`x-amzn-requestid` = "23273b1d-4a61-4815-b519-fe37a5576138",
`x-amzn-remapped-content-length` = "21", `x-amz-apigw-id` = "FJo8HE4JywMFaAA=",
`x-amzn-trace-id` = "Root=1-6466eeb3-1dd3a891190586f664c8bc89;Sampled=0;lineage=31aaf29f:0"), class = c("insensitive",
`x-amzn-requestid` = "824b7281-c4e9-4173-a31d-ada3ef3e510c",
`x-amzn-remapped-content-length` = "21", `x-amz-apigw-id` = "FJ9kvHlzSwMF6zw=",
`x-amzn-trace-id` = "Root=1-64670fb7-5daa8ec65c0afa4c66e243fa;Sampled=0;lineage=31aaf29f:0"), class = c("insensitive",
"list")))), cookies = structure(list(domain = logical(0),
flag = logical(0), path = logical(0), secure = logical(0),
expiration = structure(numeric(0), class = c("POSIXct",
"POSIXt")), name = logical(0), value = logical(0)), row.names = integer(0), class = "data.frame"),
content = charToRaw("Internal Server Error"), date = structure(1684467379, class = c("POSIXct",
"POSIXt"), tzone = "GMT"), times = c(redirect = 0, namelookup = 5.5e-05,
connect = 0, pretransfer = 0.000295, starttransfer = 0.1582,
total = 0.158513)), class = "response")
content = charToRaw("Internal Server Error"), date = structure(1684475831, class = c("POSIXct",
"POSIXt"), tzone = "GMT"), times = c(redirect = 0, namelookup = 2.5e-05,
connect = 0, pretransfer = 0.000122, starttransfer = 0.154859,
total = 0.154926)), class = "response")
Loading

0 comments on commit 11f85dd

Please sign in to comment.