Skip to content

Commit

Permalink
vcr tests for ebirdregionspecies
Browse files Browse the repository at this point in the history
  • Loading branch information
slager committed Mar 8, 2024
1 parent 737ff5a commit 35007a0
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 26 deletions.
112 changes: 112 additions & 0 deletions tests/fixtures/ebirdregionspecies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
http_interactions:
- request:
method: get
uri: https://ebird.org/ws2.0/product/spplist/HM
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: '210'
content-type: application/json;charset=utf-8
date: Fri, 08 Mar 2024 06:49:47 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: '["blfshe1","brnsku3","sopsku1","kelgul","antter1","kinpen1","genpen1","chipen2","macpen1","rocpen1","royalb2","wanalb1","antalb1","wanalb5","sooalb1","limalb1","yenalb3","gyhalb","bkbalb","wispet","gybstp1","bbspet1","angpet1","norgip1","souful1","antpet1","cappet","kerpet2","grwpet3","soppet1","whhpet1","motpet","blupet1","brbpri1","dovpri1","slbpri1","fulpri1","grapet","whcpet1","codpet1","sgdpet1","heisha1"]'
recorded_at: 2024-03-08 06:53:22 GMT
recorded_with: vcr/1.2.2, webmockr/0.9.0
- request:
method: get
uri: https://ebird.org/ws2.0/product/spplist/SH-SH
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: '200'
content-type: application/json;charset=utf-8
date: Fri, 08 Mar 2024 06:49: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: '["musduc","rinphe1","chukar","rocpig","zebdov","commoo3","purgal2","sthplo1","lotjae","fragul","whiter","brnnod","blknod","sooter1","arcter","whttro","rebtro","jacpen1","lcspet","barpet","souful1","cappet","bulpet","corshe","greshe","sooshe","refboo","brnboo","masboo","categr1","commyn","redfod1","javspa","comwax","yelcan1"]'
recorded_at: 2024-03-08 06:53:22 GMT
recorded_with: vcr/1.2.2, webmockr/0.9.0
- request:
method: get
uri: https://ebird.org/ws2.0/product/spplist/L2549512
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: '211'
content-type: application/json;charset=utf-8
date: Fri, 08 Mar 2024 06:49: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: '["pabduc1","x00458","brnsku3","kelgul","antter1","kinpen1","adepen1","genpen1","chipen2","macpen1","roypen1","rocpen1","royalb2","wanalb1","antalb1","sooalb1","limalb1","gyhalb","whcalb1","bkbalb","wispet","angpet1","norgip1","souful1","cappet","kerpet2","soppet1","whhpet1","motpet","dovpri1","slbpri1","whcpet1","sooshe","grecor","macsha1","eursta","sonthr1","eurbla","lesred1"]'
recorded_at: 2024-03-08 06:53:22 GMT
recorded_with: vcr/1.2.2, webmockr/0.9.0
45 changes: 19 additions & 26 deletions tests/testthat/test-ebirdregionspecies.R
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
context("ebirdregionspecies")
vcr::use_cassette("ebirdregionspecies", {
test_that("ebirdregionspecies works correctly", {
country <- ebirdregionspecies("HM")
subnat1 <- ebirdregionspecies("SH-SH")
hotspot <- ebirdregionspecies("L2549512")

test_that("ebirdregionspecies works correctly", {
skip_on_cran()
skip_on_ci()
expect_is(country, "data.frame")
expect_gt(NROW(country), 30)
expect_equal(NCOL(country), 1)
expect_is(country$speciesCode, "character")

eng <- ebirdregionspecies("GB-ENG")
lon <- ebirdregionspecies("GB-ENG-LND")
hotspot <- ebirdregionspecies("L5803024")
expect_is(subnat1, "data.frame")
expect_gt(NROW(subnat1), 30)

expect_is(eng, "data.frame")
expect_gt(NROW(eng), 500)
expect_equal(NCOL(eng), 1)
expect_is(eng$speciesCode, "character")
expect_is(hotspot, "data.frame")
expect_gt(NROW(hotspot), 20)
})

expect_is(lon, "data.frame")
expect_gt(NROW(lon), 300)
expect_gt(NROW(eng), NROW(lon))

expect_is(hotspot, "data.frame")
expect_gt(NROW(hotspot), 100)
expect_gt(NROW(lon), NROW(hotspot))
})

test_that("ebirdregionspecies fails correctly", {
skip_on_cran()

expect_error(suppressWarnings(ebirdregionspecies()))
expect_error(suppressWarnings(ebirdregionspecies("")))
expect_error(suppressWarnings(ebirdregionspecies(c("GB", "FR"))))
test_that("ebirdregionspecies fails correctly", {
expect_error(ebirdregionspecies(), 'is missing')
expect_error(ebirdregionspecies(""), 'No location')
expect_error(ebirdregionspecies(letters), 'More than one')
})
})

0 comments on commit 35007a0

Please sign in to comment.