From 392cfbc34f2944e234f8790d68302d88029dd2f5 Mon Sep 17 00:00:00 2001 From: Russ Biggs Date: Thu, 23 Jan 2025 16:33:29 -0700 Subject: [PATCH] add provider tests - check skip --- tests/fixtures/get_provider_119.yml | 34 ++++++++++++++++++++++ tests/fixtures/get_provider_119_list.yml | 34 ++++++++++++++++++++++ tests/fixtures/list_providers.yml | 34 ++++++++++++++++++++++ tests/fixtures/list_providers_list.yml | 34 ++++++++++++++++++++++ tests/testthat/test-providers.R | 36 ++++++++++++++++++++++++ 5 files changed, 172 insertions(+) create mode 100644 tests/fixtures/get_provider_119.yml create mode 100644 tests/fixtures/get_provider_119_list.yml create mode 100644 tests/fixtures/list_providers.yml create mode 100644 tests/fixtures/list_providers_list.yml create mode 100644 tests/testthat/test-providers.R diff --git a/tests/fixtures/get_provider_119.yml b/tests/fixtures/get_provider_119.yml new file mode 100644 index 0000000..b00c94b --- /dev/null +++ b/tests/fixtures/get_provider_119.yml @@ -0,0 +1,34 @@ +http_interactions: +- request: + method: get + uri: https://api.openaq.org/v3/providers/119 + body: + encoding: '' + string: '' + headers: + X-API-Key: <<>> + User-Agent: openaq-r + Content-Type: application/json + Accept: application/json + response: + status: + status_code: 200 + message: OK + headers: + date: Thu, 23 Jan 2025 23:25:06 GMT + server: uvicorn + content-type: application/json + x-ratelimit-limit: '100' + x-ratelimit-remaining: '99' + x-ratelimit-used: '1' + x-ratelimit-reset: '60' + cache-control: public, max-age=900 + content-encoding: gzip + vary: Accept-Encoding + Transfer-Encoding: chunked + body: + encoding: '' + file: no + string: '{"meta":{"name":"openaq-api","website":"/","page":1,"limit":100,"found":1},"results":[{"id":119,"name":"AirNow","sourceName":"AirNow","exportPrefix":"airnow","datetimeAdded":"2025-01-13T23:09:48.596722Z","datetimeFirst":"2021-12-15T10:00:00Z","datetimeLast":"2025-01-14T09:30:00Z","entitiesId":1,"parameters":[{"id":2,"name":"pm25","units":"µg/m³","displayName":null}],"bbox":{"type":"Polygon","coordinates":[[[-151.76306,-20.248716],[-151.76306,51.487236],[185.199922,51.487236],[185.199922,-20.248716],[-151.76306,-20.248716]]]}}]}' + recorded_at: 2025-01-23 23:25:07 GMT + recorded_with: vcr/1.6.0, webmockr/1.0.0 diff --git a/tests/fixtures/get_provider_119_list.yml b/tests/fixtures/get_provider_119_list.yml new file mode 100644 index 0000000..b909893 --- /dev/null +++ b/tests/fixtures/get_provider_119_list.yml @@ -0,0 +1,34 @@ +http_interactions: +- request: + method: get + uri: https://api.openaq.org/v3/providers/119 + body: + encoding: '' + string: '' + headers: + X-API-Key: <<>> + User-Agent: openaq-r + Content-Type: application/json + Accept: application/json + response: + status: + status_code: 200 + message: OK + headers: + date: Thu, 23 Jan 2025 23:25:06 GMT + server: uvicorn + content-type: application/json + x-ratelimit-limit: '100' + x-ratelimit-remaining: '98' + x-ratelimit-used: '2' + x-ratelimit-reset: '59' + cache-control: public, max-age=900 + content-encoding: gzip + vary: Accept-Encoding + Transfer-Encoding: chunked + body: + encoding: '' + file: no + string: '{"meta":{"name":"openaq-api","website":"/","page":1,"limit":100,"found":1},"results":[{"id":119,"name":"AirNow","sourceName":"AirNow","exportPrefix":"airnow","datetimeAdded":"2025-01-13T23:09:48.596722Z","datetimeFirst":"2021-12-15T10:00:00Z","datetimeLast":"2025-01-14T09:30:00Z","entitiesId":1,"parameters":[{"id":2,"name":"pm25","units":"µg/m³","displayName":null}],"bbox":{"type":"Polygon","coordinates":[[[-151.76306,-20.248716],[-151.76306,51.487236],[185.199922,51.487236],[185.199922,-20.248716],[-151.76306,-20.248716]]]}}]}' + recorded_at: 2025-01-23 23:25:07 GMT + recorded_with: vcr/1.6.0, webmockr/1.0.0 diff --git a/tests/fixtures/list_providers.yml b/tests/fixtures/list_providers.yml new file mode 100644 index 0000000..bb098c7 --- /dev/null +++ b/tests/fixtures/list_providers.yml @@ -0,0 +1,34 @@ +http_interactions: +- request: + method: get + uri: https://api.openaq.org/v3/providers?limit=100&page=1 + body: + encoding: '' + string: '' + headers: + X-API-Key: <<>> + User-Agent: openaq-r + Content-Type: application/json + Accept: application/json + response: + status: + status_code: 200 + message: OK + headers: + date: Thu, 23 Jan 2025 23:24:18 GMT + server: uvicorn + content-type: application/json + x-ratelimit-limit: '100' + x-ratelimit-remaining: '98' + x-ratelimit-used: '2' + x-ratelimit-reset: '59' + cache-control: public, max-age=900 + content-encoding: gzip + vary: Accept-Encoding + Transfer-Encoding: chunked + body: + encoding: '' + file: no + string: '{"meta":{"name":"openaq-api","website":"/","page":1,"limit":100,"found":1},"results":[{"id":119,"name":"AirNow","sourceName":"AirNow","exportPrefix":"airnow","datetimeAdded":"2025-01-13T23:09:48.596722Z","datetimeFirst":"2021-12-15T10:00:00Z","datetimeLast":"2025-01-14T09:30:00Z","entitiesId":1,"parameters":[{"id":2,"name":"pm25","units":"µg/m³","displayName":null}],"bbox":{"type":"Polygon","coordinates":[[[-151.76306,-20.248716],[-151.76306,51.487236],[185.199922,51.487236],[185.199922,-20.248716],[-151.76306,-20.248716]]]}}]}' + recorded_at: 2025-01-23 23:24:20 GMT + recorded_with: vcr/1.6.0, webmockr/1.0.0 diff --git a/tests/fixtures/list_providers_list.yml b/tests/fixtures/list_providers_list.yml new file mode 100644 index 0000000..b522c51 --- /dev/null +++ b/tests/fixtures/list_providers_list.yml @@ -0,0 +1,34 @@ +http_interactions: +- request: + method: get + uri: https://api.openaq.org/v3/providers?limit=100&page=1 + body: + encoding: '' + string: '' + headers: + X-API-Key: <<>> + User-Agent: openaq-r + Content-Type: application/json + Accept: application/json + response: + status: + status_code: 200 + message: OK + headers: + date: Thu, 23 Jan 2025 23:24:18 GMT + server: uvicorn + content-type: application/json + x-ratelimit-limit: '100' + x-ratelimit-remaining: '96' + x-ratelimit-used: '4' + x-ratelimit-reset: '59' + cache-control: public, max-age=900 + content-encoding: gzip + vary: Accept-Encoding + Transfer-Encoding: chunked + body: + encoding: '' + file: no + string: '{"meta":{"name":"openaq-api","website":"/","page":1,"limit":100,"found":1},"results":[{"id":119,"name":"AirNow","sourceName":"AirNow","exportPrefix":"airnow","datetimeAdded":"2025-01-13T23:09:48.596722Z","datetimeFirst":"2021-12-15T10:00:00Z","datetimeLast":"2025-01-14T09:30:00Z","entitiesId":1,"parameters":[{"id":2,"name":"pm25","units":"µg/m³","displayName":null}],"bbox":{"type":"Polygon","coordinates":[[[-151.76306,-20.248716],[-151.76306,51.487236],[185.199922,51.487236],[185.199922,-20.248716],[-151.76306,-20.248716]]]}}]}' + recorded_at: 2025-01-23 23:24:20 GMT + recorded_with: vcr/1.6.0, webmockr/1.0.0 diff --git a/tests/testthat/test-providers.R b/tests/testthat/test-providers.R new file mode 100644 index 0000000..d4a26cc --- /dev/null +++ b/tests/testthat/test-providers.R @@ -0,0 +1,36 @@ +test_that("get_provider(119) works", { + vcr::use_cassette("get_provider_119", { + provider <- get_provider(119) + }) + testthat::expect_type(provider, "list") + testthat::expect_true(is.data.frame(provider)) + testthat::expect_true(nrow(provider) == 1) +}) + +test_that("list_providers() works", { + vcr::use_cassette("list_providers", { + providers <- list_providers() + }) + testthat::expect_type(providers, "list") + testthat::expect_true(is.data.frame(providers)) + testthat::expect_true(nrow(providers) == 1) +}) + +test_that("get_provider(119) as list works", { + vcr::use_cassette("get_provider_119_list", { + provider <- get_provider(119, as_data_frame = FALSE) + }) + testthat::expect_type(provider, "list") + testthat::expect_false(is.data.frame(provider)) + testthat::expect_true(length(provider) == 1) +}) + + +test_that("list_providers() as list works", { + vcr::use_cassette("list_providers_list", { + providers <- list_providers(as_data_frame = FALSE) + }) + testthat::expect_type(providers, "list") + testthat::expect_false(is.data.frame(providers)) + testthat::expect_true(length(providers) == 1) +})