Skip to content

Commit

Permalink
Merge pull request #110 from ropensci/vcr_ebirdhotspot
Browse files Browse the repository at this point in the history
vcr tests for ebirdhotspot
  • Loading branch information
slager authored Mar 6, 2024
2 parents 82771e6 + 1ebe35d commit 0503114
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 11 deletions.
82 changes: 82 additions & 0 deletions tests/fixtures/ebirdhotspot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
http_interactions:
- request:
method: get
uri: https://ebird.org/ws2.0/data/obs/hotspot/recent?fmt=json&maxResults=3&r=L99381&includeProvisional=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: '299'
content-type: application/json;charset=utf-8
date: Wed, 06 Mar 2024 06:30:44 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":"cangoo","comName":"Canada Goose","sciName":"Branta
canadensis","locId":"L99381","locName":"Stewart Park","obsDt":"2024-03-05
16:38","howMany":2,"lat":42.460791,"lng":-76.5068525,"obsValid":true,"obsReviewed":false,"locationPrivate":false,"subId":"S163830741"},{"speciesCode":"mallar3","comName":"Mallard","sciName":"Anas
platyrhynchos","locId":"L99381","locName":"Stewart Park","obsDt":"2024-03-05
16:38","howMany":2,"lat":42.460791,"lng":-76.5068525,"obsValid":true,"obsReviewed":false,"locationPrivate":false,"subId":"S163830741"},{"speciesCode":"commer","comName":"Common
Merganser","sciName":"Mergus merganser","locId":"L99381","locName":"Stewart
Park","obsDt":"2024-03-05 16:38","howMany":2,"lat":42.460791,"lng":-76.5068525,"obsValid":true,"obsReviewed":false,"locationPrivate":false,"subId":"S163830741"}]'
recorded_at: 2024-03-06 06:34:11 GMT
recorded_with: vcr/1.2.2, webmockr/0.9.0
- request:
method: get
uri: https://ebird.org/ws2.0/data/obs/hotspot/recent?fmt=json&back=40&r=L99381
body:
encoding: ''
string: ''
headers:
Accept: application/json, text/xml, application/xml, */*
X-eBirdApiToken: <<<redacted>>>
response:
status:
status_code: 400
category: Client error
reason: Bad Request
message: 'Client error: (400) Bad Request'
headers:
cache-control: no-cache, no-store, max-age=0, must-revalidate
content-encoding: gzip
content-length: '146'
content-type: application/json
date: Wed, 06 Mar 2024 06:30:45 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: '{"errors":[{"status":"400 BAD_REQUEST","code":"error.data.too_many_back","title":"Field
back of rawDataCmd: The maximum number of days back is 30"}]}'
recorded_at: 2024-03-06 06:34:11 GMT
recorded_with: vcr/1.2.2, webmockr/0.9.0
19 changes: 8 additions & 11 deletions tests/testthat/test-ebirdhotspot.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
context("ebirdhotspot")
vcr::use_cassette("ebirdhotspot", {
test_that("ebirdhotspot works correctly", {

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

expect_warning(out <- ebirdhotspot('L99381', max = 10, provisional = TRUE))
expect_is(out, "data.frame")
expect_is(out$comName, "character")
expect_warning(ebirdhotspot('L99381'))

expect_warning(expect_error(ebirdhotspot(locID = 'L99381', back = 40)))
expect_warning(out <- ebirdhotspot('L99381', max = 3, provisional = TRUE))
expect_is(out, "data.frame")
expect_is(out$comName, "character")
expect_warning(expect_error(ebirdhotspot(locID = letters)))
expect_warning(expect_error(ebirdhotspot(locID = 'L99381', back = 40)))
})
})

0 comments on commit 0503114

Please sign in to comment.