@@ -4,99 +4,66 @@ without_internet({
4
4
test_that(" coleo_request makes a good request" , {
5
5
6
6
expect_GET(coleo_request_general(endpoint = " cells" , response_as_df = FALSE , schema = " public" , ' cell_code' = " eq.foo" ),
7
- url = " https://coleo.biodiversite-quebec.ca/newapi/v1 /cells?cell_code=eq.foo" )
7
+ url = " https://coleo.biodiversite-quebec.ca/newapi/v2 /cells?cell_code=eq.foo" )
8
8
})
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
67
- expect_equal(length(names(resp_body )), 11 )
68
-
69
- })
70
-
71
- test_that(" can coleo_pluck_id correctly" , {
72
- expect_equal(coleo_extract_id(real_site ), 94 )
73
- })
74
-
75
- })
76
-
77
-
78
- with_mock_dir(" Site processing works correctly" , {
79
-
80
- resp_df <- coleo_request_general(endpoint = " sites" , response_as_df = TRUE , schema = " public" , " site_code" = " eq.137_107_H02" )
81
-
82
- test_that(" resp is easily processed" , {
83
- # This processing step returns everything in one row
84
- expect_equal(nrow(resp_df ), 1 )
85
- # things should be unnested now; here is one example
86
- expect_equal(length(resp_df $ id ), 1 )
87
- # coluns should be of the right class
88
- expect_type(resp_df $ type , " character" )
89
- })
90
-
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
44
+ expect_equal(length(names(resp_body )), 12 )
45
+ })
46
+ test_that(" can coleo_pluck_id correctly" , {
47
+ expect_equal(coleo_extract_id(real_site ), 94 )
48
+ })
91
49
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" )
92
59
})
93
60
94
61
95
62
test_that(" coleo_request_data returns expected output" , {
96
63
# Test case 1: survey_type = 'vegetation', view = 'short'
97
64
result1 <- coleo_request_data(survey_type = ' vegetation' , view = ' short' )
98
65
expect_is(result1 , " tbl_df" )
99
- expect_equal(ncol(result1 ), 18 ) # Assuming there are 18 columns of data for vegetation inventory
66
+ expect_equal(ncol(result1 ), 20 ) # Assuming there are 18 columns of data for vegetation inventory
100
67
101
68
# Test case 2: survey_type = 'acoustique_anoures', view = 'long'
102
69
result2 <- coleo_request_data(survey_type = ' acoustique_anoures' , view = ' long' )
0 commit comments