Skip to content

Commit

Permalink
add provider tests - check skip
Browse files Browse the repository at this point in the history
  • Loading branch information
russbiggs committed Jan 23, 2025
1 parent d74b4ff commit 392cfbc
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/fixtures/get_provider_119.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
http_interactions:
- request:
method: get
uri: https://api.openaq.org/v3/providers/119
body:
encoding: ''
string: ''
headers:
X-API-Key: <<<test_openaq_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
34 changes: 34 additions & 0 deletions tests/fixtures/get_provider_119_list.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
http_interactions:
- request:
method: get
uri: https://api.openaq.org/v3/providers/119
body:
encoding: ''
string: ''
headers:
X-API-Key: <<<test_openaq_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
34 changes: 34 additions & 0 deletions tests/fixtures/list_providers.yml
Original file line number Diff line number Diff line change
@@ -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: <<<test_openaq_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
34 changes: 34 additions & 0 deletions tests/fixtures/list_providers_list.yml
Original file line number Diff line number Diff line change
@@ -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: <<<test_openaq_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
36 changes: 36 additions & 0 deletions tests/testthat/test-providers.R
Original file line number Diff line number Diff line change
@@ -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)
})

0 comments on commit 392cfbc

Please sign in to comment.