Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vcr tests for ebirdgeo #119

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions tests/fixtures/ebirdgeo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
http_interactions:
- request:
method: get
uri: https://ebird.org/ws2.0/data/obs/geo/recent/amegfi?speciesCode=amegfi&lat=42.45&lng=-76.5&dist=50&maxResults=2
body:
encoding: ''
string: ''
headers:
Accept: application/json, text/xml, application/xml, */*
X-eBirdApiToken: <<<redacted>>>
response:
status:
status_code: 200
category: Success
reason: OK
message: 'Success: (200) OK'
headers:
cache-control: no-cache, no-store, max-age=0, must-revalidate
content-encoding: gzip
content-length: '322'
content-type: application/json;charset=utf-8
date: Sat, 09 Mar 2024 06:43:48 GMT
expires: '0'
pragma: no-cache
server: Apache
strict-transport-security: max-age=31536000 ; includeSubDomains
vary:
- Accept-Encoding
- Accept-Encoding,Origin,Access-Control-Request-Method,Access-Control-Request-Headers
x-content-type-options: nosniff
x-frame-options: DENY
x-xss-protection: 1; mode=block
body:
encoding: ''
file: no
string: '[{"speciesCode":"amegfi","comName":"American Goldfinch","sciName":"Spinus
tristis","locId":"L12963789","locName":"380 Snyder Hill Road Yard","obsDt":"2024-03-08
16:01","howMany":1,"lat":42.422177,"lng":-76.438978,"obsValid":true,"obsReviewed":false,"locationPrivate":true,"subId":"S164133162"},{"speciesCode":"amegfi","comName":"American
Goldfinch","sciName":"Spinus tristis","locId":"L22710256","locName":"Fall
Creek-West Campus loop","obsDt":"2024-03-08 15:31","howMany":7,"lat":42.446819,"lng":-76.495329,"obsValid":true,"obsReviewed":false,"locationPrivate":true,"subId":"S164139574"}]'
recorded_at: 2024-03-09 06:47:26 GMT
recorded_with: vcr/1.2.2, webmockr/0.9.0
- request:
method: get
uri: https://ebird.org/ws2.0/data/obs/geo/recent?lat=42.45&lng=-76.5&back=30&maxResults=2&includeProvisional=true&hotspot=true
body:
encoding: ''
string: ''
headers:
Accept: application/json, text/xml, application/xml, */*
X-eBirdApiToken: <<<redacted>>>
response:
status:
status_code: 200
category: Success
reason: OK
message: 'Success: (200) OK'
headers:
cache-control: no-cache, no-store, max-age=0, must-revalidate
content-encoding: gzip
content-length: '286'
content-type: application/json;charset=utf-8
date: Sat, 09 Mar 2024 06:43:48 GMT
expires: '0'
pragma: no-cache
server: Apache
strict-transport-security: max-age=31536000 ; includeSubDomains
vary:
- Accept-Encoding
- Accept-Encoding,Origin,Access-Control-Request-Method,Access-Control-Request-Headers
x-content-type-options: nosniff
x-frame-options: DENY
x-xss-protection: 1; mode=block
body:
encoding: ''
file: no
string: '[{"speciesCode":"haiwoo","comName":"Hairy Woodpecker","sciName":"Dryobates
villosus","locId":"L99398","locName":"Ithaca City Cemetery","obsDt":"2024-03-08
17:21","howMany":1,"lat":42.4447668,"lng":-76.4912709,"obsValid":true,"obsReviewed":false,"locationPrivate":false,"subId":"S164140884"},{"speciesCode":"blujay","comName":"Blue
Jay","sciName":"Cyanocitta cristata","locId":"L99398","locName":"Ithaca City
Cemetery","obsDt":"2024-03-08 17:21","howMany":1,"lat":42.4447668,"lng":-76.4912709,"obsValid":true,"obsReviewed":false,"locationPrivate":false,"subId":"S164140884"}]'
recorded_at: 2024-03-09 06:47:26 GMT
recorded_with: vcr/1.2.2, webmockr/0.9.0
32 changes: 17 additions & 15 deletions tests/testthat/test-ebirdgeo.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
context("ebirdgeo")

test_that("ebirdgeo works correctly", {
skip_on_cran()
skip_on_ci()

egeo <- ebirdgeo('amegfi',42,-76)
expect_is(egeo, "data.frame")
expect_gt(NCOL(egeo), 10)
expect_is(egeo$locName, "character")
expect_is(egeo$howMany, "integer")
expect_is(ebirdgeo(lat = 42, lng = -76, max=10, provisional=TRUE, hotspot=TRUE), "data.frame")
expect_equal(NROW(ebirdgeo(lat = 42, lng = -76, max=10, provisional=TRUE, hotspot=TRUE)), 10)
expect_silent(ebirdgeo(lat = 40, lng = -120, dist = 50))
expect_warning(ebirdgeo(lat = 30, lng = -120, dist = 100), "Distance supplied was >50km")
vcr::use_cassette("ebirdgeo", {
test_that("ebirdgeo works correctly", {
expect_warning(egeo <- ebirdgeo('amegfi', 42.45, -76.50, dist = 51, max = 2),
"Distance supplied was >50km")
expect_true(inherits(egeo, "data.frame"))
expect_gt(NCOL(egeo), 10)
expect_equal(nrow(egeo), 2)
expect_true(inherits(egeo$locName, "character"))
expect_true(inherits(egeo$howMany, "integer"))
expect_warning(
prov <- ebirdgeo(
lat = 42.45, lng = -76.50, max=2,
provisional=TRUE, hotspot=TRUE, back = 31.5),
"using 30 days"
)
expect_true(inherits(prov, "data.frame"))
})
})
Loading