@@ -9,85 +9,53 @@ without_internet({
9
9
})
10
10
11
11
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 ())
18
15
})
19
16
20
17
# 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 )
31
22
})
32
23
33
24
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" )
51
33
})
52
34
53
35
test_that(" errors for bad endpoint" , {
54
36
expect_error(coleo_request_general(endpoint = " not_an_endpoint" ))
55
37
})
56
38
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
67
44
expect_equal(length(names(resp_body )), 12 )
68
45
})
46
+ test_that(" can coleo_pluck_id correctly" , {
47
+ expect_equal(coleo_extract_id(real_site ), 94 )
48
+ })
69
49
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" )
91
59
})
92
60
93
61
0 commit comments