diff --git a/tests/fixtures/occ_count.yml b/tests/fixtures/occ_count.yml new file mode 100644 index 00000000..acad32c6 --- /dev/null +++ b/tests/fixtures/occ_count.yml @@ -0,0 +1,145 @@ +http_interactions: +- request: + method: get + uri: https://api.gbif.org/v1/occurrence/search?occurrenceStatus=PRESENT&limit=0&offset=0&facetLimit= + body: + encoding: '' + string: '' + headers: + Accept-Encoding: gzip, deflate + Accept: application/json, text/xml, application/xml, */* + response: + status: + status_code: '200' + message: OK + explanation: Request fulfilled, document follows + headers: + status: HTTP/1.1 200 OK + content-type: application/json + body: + encoding: '' + file: no + base64_string: eyJvZmZzZXQiOjAsImxpbWl0IjowLCJlbmRPZlJlY29yZHMiOmZhbHNlLCJjb3VudCI6MjI4NDgyMDU2 + NiwicmVzdWx0cyI6W10sImZhY2V0cyI6W119 + recorded_at: 2023-03-09 14:40:20 GMT + recorded_with: vcr/1.2.0, webmockr/0.8.2 +- request: + method: get + uri: https://api.gbif.org/v1/occurrence/search?occurrenceStatus=PRESENT&limit=0&offset=0&facetLimit=&year=2000%2C2011&taxonKey=212 + body: + encoding: '' + string: '' + headers: + Accept-Encoding: gzip, deflate + Accept: application/json, text/xml, application/xml, */* + response: + status: + status_code: '200' + message: OK + explanation: Request fulfilled, document follows + headers: + status: HTTP/1.1 200 OK + content-type: application/json + body: + encoding: '' + file: no + base64_string: eyJvZmZzZXQiOjAsImxpbWl0IjowLCJlbmRPZlJlY29yZHMiOmZhbHNlLCJjb3VudCI6MjIyODMzOTM4 + LCJyZXN1bHRzIjpbXSwiZmFjZXRzIjpbXX0= + recorded_at: 2023-03-09 14:40:20 GMT + recorded_with: vcr/1.2.0, webmockr/0.8.2 +- request: + method: get + uri: https://api.gbif.org/v1/occurrence/search?occurrenceStatus=PRESENT&limit=0&offset=0&facetLimit=&year=2012 + body: + encoding: '' + string: '' + headers: + Accept-Encoding: gzip, deflate + Accept: application/json, text/xml, application/xml, */* + response: + status: + status_code: '200' + message: OK + explanation: Request fulfilled, document follows + headers: + status: HTTP/1.1 200 OK + content-type: application/json + body: + encoding: '' + file: no + base64_string: eyJvZmZzZXQiOjAsImxpbWl0IjowLCJlbmRPZlJlY29yZHMiOmZhbHNlLCJjb3VudCI6Njc4ODY4MjMs + InJlc3VsdHMiOltdLCJmYWNldHMiOltdfQ== + recorded_at: 2023-03-09 14:40:20 GMT + recorded_with: vcr/1.2.0, webmockr/0.8.2 +- request: + method: get + uri: https://api.gbif.org/v1/occurrence/search?occurrenceStatus=ABSENT&limit=0&offset=0&facetLimit= + body: + encoding: '' + string: '' + headers: + Accept-Encoding: gzip, deflate + Accept: application/json, text/xml, application/xml, */* + response: + status: + status_code: '200' + message: OK + explanation: Request fulfilled, document follows + headers: + status: HTTP/1.1 200 OK + content-type: application/json + body: + encoding: '' + file: no + base64_string: eyJvZmZzZXQiOjAsImxpbWl0IjowLCJlbmRPZlJlY29yZHMiOmZhbHNlLCJjb3VudCI6MjkwMTc3MTcs + InJlc3VsdHMiOltdLCJmYWNldHMiOltdfQ== + recorded_at: 2023-03-09 14:40:20 GMT + recorded_with: vcr/1.2.0, webmockr/0.8.2 +- request: + method: get + uri: https://api.gbif.org/v1/occurrence/search?occurrenceStatus=PRESENT&limit=0&offset=0&facetLimit=&organismQuantity=5&basisOfRecord=MATERIAL_SAMPLE + body: + encoding: '' + string: '' + headers: + Accept-Encoding: gzip, deflate + Accept: application/json, text/xml, application/xml, */* + response: + status: + status_code: '200' + message: OK + explanation: Request fulfilled, document follows + headers: + status: HTTP/1.1 200 OK + content-type: application/json + body: + encoding: '' + file: no + base64_string: eyJvZmZzZXQiOjAsImxpbWl0IjowLCJlbmRPZlJlY29yZHMiOmZhbHNlLCJjb3VudCI6OTQxNTM5LCJy + ZXN1bHRzIjpbXSwiZmFjZXRzIjpbXX0= + recorded_at: 2023-03-09 14:40:20 GMT + recorded_with: vcr/1.2.0, webmockr/0.8.2 +- request: + method: get + uri: https://api.gbif.org/v1/occurrence/search?occurrenceStatus=PRESENT&limit=0&offset=0&facetLimit=&verbatimScientificName=Calopteryx%20splendens&verbatimScientificName=Calopteryx%20virgo + body: + encoding: '' + string: '' + headers: + Accept-Encoding: gzip, deflate + Accept: application/json, text/xml, application/xml, */* + response: + status: + status_code: '200' + message: OK + explanation: Request fulfilled, document follows + headers: + status: HTTP/1.1 200 OK + content-type: application/json + body: + encoding: '' + file: no + base64_string: eyJvZmZzZXQiOjAsImxpbWl0IjowLCJlbmRPZlJlY29yZHMiOmZhbHNlLCJjb3VudCI6MjY1OTA1LCJy + ZXN1bHRzIjpbXSwiZmFjZXRzIjpbXX0= + recorded_at: 2023-03-09 14:40:20 GMT + recorded_with: vcr/1.2.0, webmockr/0.8.2 diff --git a/tests/fixtures/occ_count_facet.yml b/tests/fixtures/occ_count_facet.yml new file mode 100644 index 00000000..9dd18a1f --- /dev/null +++ b/tests/fixtures/occ_count_facet.yml @@ -0,0 +1,166 @@ +http_interactions: +- request: + method: get + uri: https://api.gbif.org/v1/occurrence/search?limit=0&offset=0&facet=year&facetLimit= + body: + encoding: '' + string: '' + headers: + Accept-Encoding: gzip, deflate + Accept: application/json, text/xml, application/xml, */* + response: + status: + status_code: '200' + message: OK + explanation: Request fulfilled, document follows + headers: + status: HTTP/1.1 200 OK + content-type: application/json + body: + encoding: '' + file: no + base64_string: eyJvZmZzZXQiOjAsImxpbWl0IjowLCJlbmRPZlJlY29yZHMiOmZhbHNlLCJjb3VudCI6MjMxMzgzODI4 + MywicmVzdWx0cyI6W10sImZhY2V0cyI6W3siZmllbGQiOiJZRUFSIiwiY291bnRzIjpbeyJuYW1lIjoi + MjAyMSIsImNvdW50IjoyMzEyNDU3Njl9LHsibmFtZSI6IjIwMjAiLCJjb3VudCI6MjA3MDg0NTAwfSx7 + Im5hbWUiOiIyMDE5IiwiY291bnQiOjE3MjkxMjM3OX0seyJuYW1lIjoiMjAxOCIsImNvdW50IjoxNTUw + MjI0MzJ9LHsibmFtZSI6IjIwMTciLCJjb3VudCI6MTMwODAzNTQ3fSx7Im5hbWUiOiIyMDE2IiwiY291 + bnQiOjExNjM3ODY4NH0seyJuYW1lIjoiMjAxNSIsImNvdW50IjoxMDI1NTEyNTl9LHsibmFtZSI6IjIw + MTQiLCJjb3VudCI6OTIxNzYwMDV9LHsibmFtZSI6IjIwMTMiLCJjb3VudCI6Nzc4MTk1ODZ9LHsibmFt + ZSI6IjIwMTIiLCJjb3VudCI6NjkzMjQzNzF9XX1dfQ== + recorded_at: 2023-03-09 14:40:22 GMT + recorded_with: vcr/1.2.0, webmockr/0.8.2 +- request: + method: get + uri: https://api.gbif.org/v1/occurrence/search?occurrenceStatus=PRESENT&limit=0&offset=0&facet=year&facetLimit=&year=2000%2C2003&taxonKey=212 + body: + encoding: '' + string: '' + headers: + Accept-Encoding: gzip, deflate + Accept: application/json, text/xml, application/xml, */* + response: + status: + status_code: '200' + message: OK + explanation: Request fulfilled, document follows + headers: + status: HTTP/1.1 200 OK + content-type: application/json + body: + encoding: '' + file: no + base64_string: eyJvZmZzZXQiOjAsImxpbWl0IjowLCJlbmRPZlJlY29yZHMiOmZhbHNlLCJjb3VudCI6Mzg3MDU3NDks + InJlc3VsdHMiOltdLCJmYWNldHMiOlt7ImZpZWxkIjoiWUVBUiIsImNvdW50cyI6W3sibmFtZSI6IjIw + MDMiLCJjb3VudCI6MTA3ODQ1ODl9LHsibmFtZSI6IjIwMDIiLCJjb3VudCI6OTU3ODk5OX0seyJuYW1l + IjoiMjAwMSIsImNvdW50Ijo5NDAwMzg3fSx7Im5hbWUiOiIyMDAwIiwiY291bnQiOjg5NDE3NzR9XX1d + fQ== + recorded_at: 2023-03-09 14:40:22 GMT + recorded_with: vcr/1.2.0, webmockr/0.8.2 +- request: + method: get + uri: https://api.gbif.org/v1/occurrence/search?occurrenceStatus=PRESENT&limit=0&offset=0&facet=country&facetLimit=2 + body: + encoding: '' + string: '' + headers: + Accept-Encoding: gzip, deflate + Accept: application/json, text/xml, application/xml, */* + response: + status: + status_code: '200' + message: OK + explanation: Request fulfilled, document follows + headers: + status: HTTP/1.1 200 OK + content-type: application/json + body: + encoding: '' + file: no + base64_string: eyJvZmZzZXQiOjAsImxpbWl0IjowLCJlbmRPZlJlY29yZHMiOmZhbHNlLCJjb3VudCI6MjI4NDgyMDU2 + NiwicmVzdWx0cyI6W10sImZhY2V0cyI6W3siZmllbGQiOiJDT1VOVFJZIiwiY291bnRzIjpbeyJuYW1l + IjoiVVMiLCJjb3VudCI6ODEwNjI5MjQyfSx7Im5hbWUiOiJGUiIsImNvdW50IjoxMzkyMzQyNzl9XX1d + fQ== + recorded_at: 2023-03-09 14:40:22 GMT + recorded_with: vcr/1.2.0, webmockr/0.8.2 +- request: + method: get + uri: https://api.gbif.org/v1/occurrence/search?limit=0&offset=0&facet=occurrenceStatus&facetLimit= + body: + encoding: '' + string: '' + headers: + Accept-Encoding: gzip, deflate + Accept: application/json, text/xml, application/xml, */* + response: + status: + status_code: '200' + message: OK + explanation: Request fulfilled, document follows + headers: + status: HTTP/1.1 200 OK + content-type: application/json + body: + encoding: '' + file: no + base64_string: eyJvZmZzZXQiOjAsImxpbWl0IjowLCJlbmRPZlJlY29yZHMiOmZhbHNlLCJjb3VudCI6MjMxMzgzODI4 + MywicmVzdWx0cyI6W10sImZhY2V0cyI6W3siZmllbGQiOiJPQ0NVUlJFTkNFX1NUQVRVUyIsImNvdW50 + cyI6W3sibmFtZSI6IlBSRVNFTlQiLCJjb3VudCI6MjI4NDgyMDU2Nn0seyJuYW1lIjoiQUJTRU5UIiwi + Y291bnQiOjI5MDE3NzE3fV19XX0= + recorded_at: 2023-03-09 14:40:22 GMT + recorded_with: vcr/1.2.0, webmockr/0.8.2 +- request: + method: get + uri: https://api.gbif.org/v1/occurrence/search?occurrenceStatus=PRESENT&limit=0&offset=0&facet=basisOfRecord&facetLimit=&organismQuantity=5&basisOfRecord=MATERIAL_SAMPLE + body: + encoding: '' + string: '' + headers: + Accept-Encoding: gzip, deflate + Accept: application/json, text/xml, application/xml, */* + response: + status: + status_code: '200' + message: OK + explanation: Request fulfilled, document follows + headers: + status: HTTP/1.1 200 OK + content-type: application/json + body: + encoding: '' + file: no + base64_string: eyJvZmZzZXQiOjAsImxpbWl0IjowLCJlbmRPZlJlY29yZHMiOmZhbHNlLCJjb3VudCI6OTQxNTM5LCJy + ZXN1bHRzIjpbXSwiZmFjZXRzIjpbeyJmaWVsZCI6IkJBU0lTX09GX1JFQ09SRCIsImNvdW50cyI6W3si + bmFtZSI6Ik1BVEVSSUFMX1NBTVBMRSIsImNvdW50Ijo5NDE1Mzl9XX1dfQ== + recorded_at: 2023-03-09 14:40:22 GMT + recorded_with: vcr/1.2.0, webmockr/0.8.2 +- request: + method: get + uri: https://api.gbif.org/v1/occurrence/search?occurrenceStatus=PRESENT&limit=0&offset=0&facet=coordinateUncertaintyInMeters&facetLimit= + body: + encoding: '' + string: '' + headers: + Accept-Encoding: gzip, deflate + Accept: application/json, text/xml, application/xml, */* + response: + status: + status_code: '200' + message: OK + explanation: Request fulfilled, document follows + headers: + status: HTTP/1.1 200 OK + content-type: application/json + body: + encoding: '' + file: no + base64_string: eyJvZmZzZXQiOjAsImxpbWl0IjowLCJlbmRPZlJlY29yZHMiOmZhbHNlLCJjb3VudCI6MjI4NDgyMDU2 + NiwicmVzdWx0cyI6W10sImZhY2V0cyI6W3siZmllbGQiOiJDT09SRElOQVRFX1VOQ0VSVEFJTlRZX0lO + X01FVEVSUyIsImNvdW50cyI6W3sibmFtZSI6IjUwMDAuMCIsImNvdW50IjoxMDg3OTE2MzZ9LHsibmFt + ZSI6IjEwMC4wIiwiY291bnQiOjQ3OTE4MDU4fSx7Im5hbWUiOiIxMDAwLjAiLCJjb3VudCI6MzE3MjA5 + MTZ9LHsibmFtZSI6IjEwLjAiLCJjb3VudCI6Mjc0MDUzNjZ9LHsibmFtZSI6IjUwMC4wIiwiY291bnQi + OjIxNzQzOTM1fSx7Im5hbWUiOiI3MDcuMSIsImNvdW50IjoyMTA1NDM3OX0seyJuYW1lIjoiMTQxNC4y + IiwiY291bnQiOjIwOTIzMjM2fSx7Im5hbWUiOiIxMDAwMC4wIiwiY291bnQiOjIwMzUxOTkxfSx7Im5h + bWUiOiI3MC43IiwiY291bnQiOjE4Mzk3MzE1fSx7Im5hbWUiOiI3MDcxLjEiLCJjb3VudCI6MTcxNDM4 + NDJ9XX1dfQ== + recorded_at: 2023-03-09 14:40:22 GMT + recorded_with: vcr/1.2.0, webmockr/0.8.2 diff --git a/tests/fixtures/occ_count_legacy_params.yml b/tests/fixtures/occ_count_legacy_params.yml new file mode 100644 index 00000000..5c372594 --- /dev/null +++ b/tests/fixtures/occ_count_legacy_params.yml @@ -0,0 +1,97 @@ +http_interactions: +- request: + method: get + uri: https://api.gbif.org/v1/occurrence/search?hasCoordinate=FALSE&hasGeospatialIssue=FALSE&occurrenceStatus=PRESENT&limit=0&offset=0&facetLimit= + body: + encoding: '' + string: '' + headers: + Accept-Encoding: gzip, deflate + Accept: application/json, text/xml, application/xml, */* + response: + status: + status_code: '200' + message: OK + explanation: Request fulfilled, document follows + headers: + status: HTTP/1.1 200 OK + content-type: application/json + body: + encoding: '' + file: no + base64_string: eyJvZmZzZXQiOjAsImxpbWl0IjowLCJlbmRPZlJlY29yZHMiOmZhbHNlLCJjb3VudCI6MTI2OTE0ODM4 + LCJyZXN1bHRzIjpbXSwiZmFjZXRzIjpbXX0= + recorded_at: 2023-03-09 14:40:24 GMT + recorded_with: vcr/1.2.0, webmockr/0.8.2 +- request: + method: get + uri: https://api.gbif.org/v1/occurrence/search?occurrenceStatus=PRESENT&limit=0&offset=0&facetLimit=&eventDate=2010 + body: + encoding: '' + string: '' + headers: + Accept-Encoding: gzip, deflate + Accept: application/json, text/xml, application/xml, */* + response: + status: + status_code: '200' + message: OK + explanation: Request fulfilled, document follows + headers: + status: HTTP/1.1 200 OK + content-type: application/json + body: + encoding: '' + file: no + base64_string: eyJvZmZzZXQiOjAsImxpbWl0IjowLCJlbmRPZlJlY29yZHMiOmZhbHNlLCJjb3VudCI6MjYzOTI3NCwi + cmVzdWx0cyI6W10sImZhY2V0cyI6W119 + recorded_at: 2023-03-09 14:40:24 GMT + recorded_with: vcr/1.2.0, webmockr/0.8.2 +- request: + method: get + uri: https://api.gbif.org/v1/occurrence/search?occurrenceStatus=PRESENT&limit=0&offset=0&facetLimit= + body: + encoding: '' + string: '' + headers: + Accept-Encoding: gzip, deflate + Accept: application/json, text/xml, application/xml, */* + response: + status: + status_code: '200' + message: OK + explanation: Request fulfilled, document follows + headers: + status: HTTP/1.1 200 OK + content-type: application/json + body: + encoding: '' + file: no + base64_string: eyJvZmZzZXQiOjAsImxpbWl0IjowLCJlbmRPZlJlY29yZHMiOmZhbHNlLCJjb3VudCI6MjI4NDgyMDU2 + NiwicmVzdWx0cyI6W10sImZhY2V0cyI6W119 + recorded_at: 2023-03-09 14:40:24 GMT + recorded_with: vcr/1.2.0, webmockr/0.8.2 +- request: + method: get + uri: https://api.gbif.org/v1/occurrence/search?occurrenceStatus=PRESENT&limit=0&offset=0&facetLimit=&year=2000%2C2001 + body: + encoding: '' + string: '' + headers: + Accept-Encoding: gzip, deflate + Accept: application/json, text/xml, application/xml, */* + response: + status: + status_code: '200' + message: OK + explanation: Request fulfilled, document follows + headers: + status: HTTP/1.1 200 OK + content-type: application/json + body: + encoding: '' + file: no + base64_string: eyJvZmZzZXQiOjAsImxpbWl0IjowLCJlbmRPZlJlY29yZHMiOmZhbHNlLCJjb3VudCI6Mzk1NDg2OTgs + InJlc3VsdHMiOltdLCJmYWNldHMiOltdfQ== + recorded_at: 2023-03-09 14:40:24 GMT + recorded_with: vcr/1.2.0, webmockr/0.8.2 diff --git a/tests/testthat/test-occ_count.r b/tests/testthat/test-occ_count.r index bdb12b47..eaf9367c 100644 --- a/tests/testthat/test-occ_count.r +++ b/tests/testthat/test-occ_count.r @@ -3,27 +3,13 @@ context("occ_count") test_that("occ_count", { vcr::use_cassette("occ_count", { aa <- occ_count() - aaa <- occ_search(limit=0)$meta$count bb <- occ_count(taxonKey=212, year="2000,2011") - bbb <- occ_search(taxonKey=212, year="2000,2011",limit=0)$meta$count cc <- occ_count(year=2012) - ccc <- occ_search(year=2012,limit=0)$meta$count dd <- occ_count(occurrenceStatus = "ABSENT") - ddd <- occ_search(occurrenceStatus = "ABSENT",limit=0)$meta$count ee <- occ_count(basisOfRecord="MATERIAL_SAMPLE",organismQuantity=5) - eee <- occ_search(basisOfRecord="MATERIAL_SAMPLE",organismQuantity=5,limit=0)$meta$count ff <- occ_count(verbatimScientificName="Calopteryx splendens;Calopteryx virgo") - fff <- occ_search(verbatimScientificName="Calopteryx splendens;Calopteryx virgo",limit=0)$meta$count }, preserve_exact_body_bytes = TRUE) - # results should be the same for occ_search(limit=0)$meta$count and occ_count()$ - expect_equal(aaa,aa) - expect_equal(bbb,bb) - expect_equal(ccc,cc) - expect_equal(ddd,dd) - expect_equal(eee,ee) - expect_equal(fff,ff) - # returns the correct class expect_is(aa, "numeric") expect_is(bb, "numeric") @@ -51,27 +37,13 @@ test_that("occ_count", { test_that("occ_count facets work", { vcr::use_cassette("occ_count_facet", { aa <- occ_count(facet="year",occurrenceStatus = NULL) - aaa <- occ_search(facet="year",occurrenceStatus = NULL,limit=0)$facet$year bb <- occ_count(facet="year",taxonKey=212, year="2000,2003") - bbb <- occ_search(facet="year",taxonKey=212, year="2000,2003",limit=0)$facet$year cc <- occ_count(facet="country",facetLimit=2) - ccc <- occ_search(facet="country",facetLimit=2,limit=0)$facet$country dd <- occ_count(facet="occurrenceStatus",occurrenceStatus=NULL) - ddd <- occ_search(facet="occurrenceStatus",occurrenceStatus=NULL,limit=0)$facet$occurrenceStatus ee <- occ_count(facet="basisOfRecord",basisOfRecord="MATERIAL_SAMPLE",organismQuantity=5) - eee <- occ_search(facet="basisOfRecord",basisOfRecord="MATERIAL_SAMPLE",organismQuantity=5,limit=0)$facet$basisOfRecord ff <- occ_count(facet="coordinateUncertaintyInMeters",facetverbatimScientificName="Calopteryx splendens;Calopteryx virgo") - fff <- occ_search(facet="coordinateUncertaintyInMeters",facetverbatimScientificName="Calopteryx splendens;Calopteryx virgo",limit=0)$facet$coordinateUncertaintyInMeters }, preserve_exact_body_bytes = TRUE) - # occ_search(facet="x",limit=0)$facet$x should return the same - expect_equal(aaa$count[1],aa$count[1]) - expect_equal(bbb$count[1],bb$count[1]) - expect_equal(ccc$count[1],cc$count[1]) - expect_equal(ddd$count[1],dd$count[1]) - expect_equal(eee$count[1],ee$count[1]) - expect_equal(fff$count[1],ff$count[1]) - # returns the correct class expect_is(aa, "data.frame") expect_is(bb, "data.frame")