From 35007a06e7c06a76c08e512a4772faefd940c9eb Mon Sep 17 00:00:00 2001 From: Dave Slager Date: Thu, 7 Mar 2024 22:57:04 -0800 Subject: [PATCH] vcr tests for ebirdregionspecies --- tests/fixtures/ebirdregionspecies.yml | 112 +++++++++++++++++++++++ tests/testthat/test-ebirdregionspecies.R | 45 ++++----- 2 files changed, 131 insertions(+), 26 deletions(-) create mode 100644 tests/fixtures/ebirdregionspecies.yml diff --git a/tests/fixtures/ebirdregionspecies.yml b/tests/fixtures/ebirdregionspecies.yml new file mode 100644 index 0000000..152db89 --- /dev/null +++ b/tests/fixtures/ebirdregionspecies.yml @@ -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: <<>> + 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: <<>> + 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: <<>> + 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 diff --git a/tests/testthat/test-ebirdregionspecies.R b/tests/testthat/test-ebirdregionspecies.R index fb2795f..94a0483 100644 --- a/tests/testthat/test-ebirdregionspecies.R +++ b/tests/testthat/test-ebirdregionspecies.R @@ -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') + }) })