Skip to content

Commit f035d67

Browse files
committed
fix texts: make real requests in request tests
1 parent 74a0de9 commit f035d67

File tree

1 file changed

+32
-64
lines changed

1 file changed

+32
-64
lines changed

tests/testthat/test-coleo_request.R

+32-64
Original file line numberDiff line numberDiff line change
@@ -9,85 +9,53 @@ without_internet({
99
})
1010

1111

12-
with_mock_dir("coleo_request", {
13-
test_that("no answer for a nonsense code", {
14-
nonsense_request <- coleo_request_general(endpoint = "cells", response_as_df = FALSE, schema = "public", 'cell_code' = "eq.foo")
15-
16-
expect_equal(httr2::resp_body_json(nonsense_request), list())
17-
})
12+
test_that("no answer for a nonsense code", {
13+
nonsense_request <- coleo_request_general(endpoint = "cells", response_as_df = FALSE, schema = "public", 'cell_code' = "eq.foo")
14+
expect_equal(httr2::resp_body_json(nonsense_request), list())
1815
})
1916

2017
# query for a real site
21-
22-
with_mock_dir("coleo_request_real", {
23-
test_that("returns answer for a real code",{
24-
real_site <- coleo_request_general(endpoint = "cells", schema = "public", "cell_code" = "eq.139_87")
25-
26-
answer <- httr2::resp_body_json(real_site)[[1]]
27-
28-
expect_equal(length(answer), 6)
29-
30-
})
18+
test_that("returns answer for a real code",{
19+
real_site <- coleo_request_general(endpoint = "cells", schema = "public", "cell_code" = "eq.139_87")
20+
answer <- httr2::resp_body_json(real_site)[[1]]
21+
expect_equal(length(answer), 6)
3122
})
3223

3324

34-
with_mock_dir("coleo_request_real", {
35-
real_cell <- coleo_request_general(endpoint = "cells", schema = "public", "cell_code" = "eq.139_87")
36-
real_cell_df <- coleo_request_general(endpoint = "cells", schema = "public", "cell_code" = "eq.139_87", response_as_df = TRUE)
37-
38-
resp_body <- httr2::resp_body_json(real_cell)[[1]]
39-
40-
41-
test_that("response is in expected format", {
42-
expect_equal(length(resp_body), 6)
43-
44-
# can pluck one id successfully from site request
45-
expect_equal(coleo_extract_id(real_cell), 161)
46-
47-
expect_type(real_cell_df, "list")
48-
49-
})
50-
25+
real_cell <- coleo_request_general(endpoint = "cells", schema = "public", "cell_code" = "eq.139_87")
26+
real_cell_df <- coleo_request_general(endpoint = "cells", schema = "public", "cell_code" = "eq.139_87", response_as_df = TRUE)
27+
resp_body <- httr2::resp_body_json(real_cell)[[1]]
28+
test_that("response is in expected format", {
29+
expect_equal(length(resp_body), 6)
30+
# can pluck one id successfully from site request
31+
expect_equal(coleo_extract_id(real_cell), 161)
32+
expect_type(real_cell_df, "list")
5133
})
5234

5335
test_that("errors for bad endpoint", {
5436
expect_error(coleo_request_general(endpoint = "not_an_endpoint"))
5537
})
5638

57-
with_mock_dir("site id download and extraction", {
58-
59-
real_site <- coleo_request_general(endpoint = "sites", schema = "public", "site_code" = "eq.139_87_F01")
60-
61-
test_that("request_general works for a valid site", {
62-
63-
64-
resp_body <- httr2::resp_body_json(real_site)[[1]]
65-
66-
# should be 11 columns of info for this site
39+
# Site id download and extraction
40+
real_site <- coleo_request_general(endpoint = "sites", schema = "public", "site_code" = "eq.139_87_F01")
41+
test_that("request_general works for a valid site", {
42+
resp_body <- httr2::resp_body_json(real_site)[[1]]
43+
# should be 11 columns of info for this site
6744
expect_equal(length(names(resp_body)), 12)
6845
})
46+
test_that("can coleo_pluck_id correctly", {
47+
expect_equal(coleo_extract_id(real_site), 94)
48+
})
6949

70-
test_that("can coleo_pluck_id correctly", {
71-
expect_equal(coleo_extract_id(real_site), 94)
72-
})
73-
74-
})
75-
76-
77-
with_mock_dir("Site processing works correctly", {
78-
79-
resp_df <- coleo_request_general(endpoint = "sites", response_as_df = TRUE, schema = "public", "site_code" = "eq.137_107_H02")
80-
81-
test_that("resp is easily processed", {
82-
# This processing step returns everything in one row
83-
expect_equal(nrow(resp_df), 1)
84-
# things should be unnested now; here is one example
85-
expect_equal(length(resp_df$id), 1)
86-
# coluns should be of the right class
87-
expect_type(resp_df$type, "character")
88-
})
89-
90-
50+
# Site processing works correctly
51+
resp_df <- coleo_request_general(endpoint = "sites", response_as_df = TRUE, schema = "public", "site_code" = "eq.137_107_H02")
52+
test_that("resp is easily processed", {
53+
# This processing step returns everything in one row
54+
expect_equal(nrow(resp_df), 1)
55+
# things should be unnested now; here is one example
56+
expect_equal(length(resp_df$id), 1)
57+
# coluns should be of the right class
58+
expect_type(resp_df$type, "character")
9159
})
9260

9361

0 commit comments

Comments
 (0)