Skip to content

Commit

Permalink
Fixes #183 (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklucius authored Oct 23, 2019
1 parent 8befd4f commit 7791891
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
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

0 comments on commit 7791891

Please sign in to comment.