Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #183 #185

Merged
merged 8 commits into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Description: Provides easier interaction with
format and manages throttling by 'Socrata'.
Users can upload data to 'Socrata' portals directly
from R.
Version: 1.7.9-5
Date: 2019-06-24
Version: 1.7.10-6
Date: 2019-10-23
Author: Hugh Devlin, Ph. D., Tom Schenk, Jr., Gene Leynes, Nick Lucius, John Malc, Mark Silverberg, and Peter Schmeideskamp
Maintainer: "Tom Schenk Jr." <[email protected]>
Depends:
Expand Down
40 changes: 30 additions & 10 deletions tests/testthat/test-all.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,36 @@ test_that("read Socrata CSV from New Backend (NBE) endpoint", {
})

test_that("Warn instead of fail if X-SODA2-* headers are missing", {
expect_warning(dfCsv <- read.socrata("https://data.healthcare.gov/resource/enx3-h2qp.csv?$limit=1000"),
info="https://github.com/Chicago/RSocrata/issues/118")
expect_warning(dfJson <- read.socrata("https://data.healthcare.gov/resource/enx3-h2qp.json?$limit=1000"),
info="https://github.com/Chicago/RSocrata/issues/118")
expect_silent(df <- read.socrata("https://odn.data.socrata.com/resource/pvug-y23y.csv"))
expect_silent(df <- read.socrata("https://odn.data.socrata.com/resource/pvug-y23y.json"))
expect_equal("data.frame", class(dfCsv), label="class", info="https://github.com/Chicago/RSocrata/issues/118")
expect_equal("data.frame", class(dfJson), label="class", info="https://github.com/Chicago/RSocrata/issues/118")
expect_equal(150, ncol(dfCsv), label="columns", info="https://github.com/Chicago/RSocrata/issues/118")
expect_equal(140, ncol(dfJson), label="columns", info="https://github.com/Chicago/RSocrata/issues/118")

## These data sets are identified in #118 as data sets with missing soda
## headers. The missing header should cause the data set to return character
## columns instead of columns cast into their appropriate classes.
## RSocrata should also warn the user when the header is missing.
url_csv_missing <- "https://data.healthcare.gov/resource/enx3-h2qp.csv?$limit=1000"
url_json_missing <- "https://data.healthcare.gov/resource/enx3-h2qp.json?$limit=1000"
## These URLs should have soda types in the header
url_csv_complete <- "https://odn.data.socrata.com/resource/pvug-y23y.csv"
url_json_complete <- "https://odn.data.socrata.com/resource/pvug-y23y.json"

msg <- "https://github.com/Chicago/RSocrata/issues/118"

## Check that the soda2 headers are missing
expect_null(RSocrata:::getResponse(url_csv_missing)$headers[['x-soda2-types']], info=msg)
expect_null(RSocrata:::getResponse(url_json_missing)$headers[['x-soda2-types']], info=msg)

## Check for warning that the header is missing, which causes the column
## classes to be returned as character
expect_warning(dfCsv <- read.socrata(url_csv_missing), info=msg)
expect_warning(dfJson <- read.socrata(url_json_missing), info=msg)

## Check that the soda2 headers are present
expect_false(is.null(RSocrata:::getResponse(url_csv_complete)$headers[['x-soda2-types']]), info=msg)
expect_false(is.null(RSocrata:::getResponse(url_json_complete)$headers[['x-soda2-types']]), info=msg)

## Check that they return results without warning
expect_silent(df <- read.socrata(url_csv_complete))
expect_silent(df <- read.socrata(url_json_complete))

})

test_that("read Socrata CSV as character", {
Expand Down