tests_userFriendly_fxns.R 19.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
context("Unit values")

test_that("Unit value data returns correct types", {
  testthat::skip_on_cran()
  
  siteNumber <- '05114000'
  parameterCd <- '00060'
  startDate <- "2014-10-10"
  endDate <- "2014-10-10"

  rawData <- readNWISuv(siteNumber,parameterCd,startDate,endDate)
12
  rawData <- renameNWISColumns(rawData)
13
14
15
16
17
18
19
  
  spreadOver120 <- readNWISuv(siteNumber,parameterCd,
                              as.Date(Sys.Date()-200),
                              Sys.Date())
  
  expect_true(min(spreadOver120$dateTime) < as.POSIXct(Sys.Date(), tz="UTC"))
  
20
  timeZoneChange <- readNWISuv(c('04024430','04024000'),parameterCd,
21
22
23
24
25
                               "2013-11-03","2013-11-03", 
                               tz="America/Chicago")
  
  
  timeZoneChange <- renameNWISColumns(timeZoneChange)
26
  expect_is(rawData$dateTime, 'POSIXct')
27
  expect_is(rawData$Flow_Inst, 'numeric')
Laura A DeCicco's avatar
Laura A DeCicco committed
28
  expect_equal(attr(rawData, "url"), "https://nwis.waterservices.usgs.gov/nwis/iv/?site=05114000&format=waterml,1.1&ParameterCd=00060&startDT=2014-10-10&endDT=2014-10-10")
29
30
31
#   #First switchover to standard time:
#   expect_that(as.numeric(timeZoneChange[which(timeZoneChange$tz_cd == "America/Chicago")[1],"dateTime"]),
#               equals(as.numeric(as.POSIXct("2013-11-03 01:00:00", tz="UTC")+60*60*6)))
32
  
33
34
35
36
37
38
  site <- "04087170"
  pCode <- "63680"
  startDate <- "2012-07-10"
  endDate <- "2012-07-17"
  dd_2 <- readNWISuv(site, pCode, startDate, endDate)
  expect_true(all(names(dd_2) %in% c("agency_cd","site_no",                   
David Watkins's avatar
David Watkins committed
39
40
41
                                 "dateTime","X_.YSI.6136.UP._63680_00000",   
                                 "X_YSI.6136.DOWN_63680_00000","X_.YSI.6136.UP._63680_00000_cd",
                                 "X_YSI.6136.DOWN_63680_00000_cd","tz_cd")))
42
  
Laura A DeCicco's avatar
Laura A DeCicco committed
43
  noData <- readNWISuv("01196500","00010", "2016-06-15", "2016-06-15")
Laura A DeCicco's avatar
Laura A DeCicco committed
44
  # expect_equal(noData$X_00010_00000[1], as.numeric(NA))
45
  
46
47
})

Laura A DeCicco's avatar
Laura A DeCicco committed
48
context("Peak, rating, meas, site")
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
test_that("peak, rating curves, surface-water measurements", {
  testthat::skip_on_cran()
  
  siteNumbers <- c('01594440','040851325')
  data <- readNWISpeak(siteNumbers)
  expect_is(data$agency_cd, 'character')
  
  #Rating curvs:
  siteNumber <- '01594440'
  data <- readNWISrating(siteNumber, "base")
  expect_that(length(attr(data, "RATING")),equals(7))
  
  #Surface meas:
  siteNumbers <- c('01594440','040851325')
  data <- readNWISmeas(siteNumbers)
  expect_is(data$agency_cd, 'character')
Laura A DeCicco's avatar
Laura A DeCicco committed
65
66
67
68
69
70
71
  
  siteINFO <- readNWISsite('05114000')
  expect_is(siteINFO$agency_cd, 'character')
  
  siteINFOMulti <- readNWISsite(c('05114000','09423350'))
  expect_that(nrow(siteINFOMulti) == 2, is_true())
  
72
73
74
75
76
77
78
  Meas07227500.ex <- readNWISmeas("07227500",expanded=TRUE)
  expect_is(Meas07227500.ex$measurement_dt, 'Date')
  expect_is(Meas07227500.ex$measurement_dateTime, 'POSIXct')
  
  emptyDF <- whatNWISdata("10312000",parameterCd = "50286")
  expect_that(nrow(emptyDF) == 0, is_true())
  
Laura A DeCicco's avatar
Laura A DeCicco committed
79
  url <- "https://waterservices.usgs.gov/nwis/site/?format=rdb&seriesCatalogOutput=true&sites=05114000"
80
81
  x <- importRDB1(url)

82
83
})

Laura A DeCicco's avatar
Laura A DeCicco committed
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
context("qw")

test_that("NWIS qw tests", {
  testthat::skip_on_cran()
  siteNumbers <- c('04024430','04024000')
  startDate <- '2010-01-01'
  endDate <- ''
  parameterCd <- c('34247','30234','32104','34220')
  
  rawNWISqwData <- readNWISqw(siteNumbers,parameterCd,startDate,endDate)
  expect_is(rawNWISqwData$startDateTime, 'POSIXct')
  
  rawNWISqwDataReshaped <- readNWISqw(siteNumbers,parameterCd,
            startDate,endDate,reshape=TRUE)
  expect_is(rawNWISqwDataReshaped$startDateTime, 'POSIXct')
  
  parameterCd <- "all"
  rawNWISall <- readNWISqw(siteNumbers,parameterCd,
           startDate,"2011-01-01",reshape=TRUE)
  expect_is(rawNWISall$startDateTime, 'POSIXct')
  
Laura A DeCicco's avatar
Laura A DeCicco committed
105
106
107
  pgroup <- c("NUT")
  rawNWISNutrients <- readNWISqw(siteNumbers,pgroup,
           startDate,endDate)
Laura A DeCicco's avatar
Laura A DeCicco committed
108
  expect_is(rawNWISNutrients$startDateTime, 'POSIXct')
Laura A DeCicco's avatar
Laura A DeCicco committed
109
  
110
111
112
  qwret <- readNWISqw("413437087150601", parameterCd = c("NUT","INN"),startDate = "",endDate = "")
  expect_that(nrow(qwret) == 0, is_true())
  
Laura A DeCicco's avatar
Laura A DeCicco committed
113
114
115
116
117
118
119
120
121
122
123
124
  siteNumber <- '455638089034501'
  wy_start <- paste0(2014, "-10-01")
  wy_end <- paste0(2015, "-09-30")
  
  #No data test:
  no.data <- readNWISqw(siteNumbers = siteNumber, 
                  parameterCd = '00060', 
                  startDate = wy_start, 
                  endDat = wy_end)
  
  expect_that(nrow(no.data) == 0, is_true())
  
Laura A DeCicco's avatar
Laura A DeCicco committed
125
})
Laura A DeCicco's avatar
Laura A DeCicco committed
126

Laura A DeCicco's avatar
Laura A DeCicco committed
127
128
129
130
131
132
133
134
135
136
137
138
context("dv")

test_that("NWIS dv tests", {
  testthat::skip_on_cran()
  
  siteNumber <- '04085427'
  startDate <- '2012-01-01'
  endDate <- '2012-06-30'
  pCode <- '00060'
  
  rawDailyQ <- readNWISdv(siteNumber,pCode, startDate, endDate)
  expect_is(rawDailyQ$Date, 'Date')
Laura A DeCicco's avatar
Laura A DeCicco committed
139
  
Laura A DeCicco's avatar
Laura A DeCicco committed
140
141
142
143
144
145
146
147
148
149
  rawDailyQAndTempMeanMax <- readNWISdv(siteNumber,c('00010','00060'),
        startDate, endDate, statCd=c('00001','00003'))
  expect_that(length(grep("00060", names(rawDailyQAndTempMeanMax))) >= 2 & 
                length(grep("00010", names(rawDailyQAndTempMeanMax))) >= 2, is_true())
  

  rawDailyMultiSites<- readNWISdv(c("01491000","01645000"),c('00010','00060'),
        startDate, endDate, statCd=c('00001','00003'))
  expect_that(length(unique(rawDailyMultiSites$site_no)) > 1, is_true())
  
Laura A DeCicco's avatar
Laura A DeCicco committed
150
151
152
#   # Site with no data:
#   x <- readNWISdv("10258500","00060", "2015-02-08", "2015-02-14")
#   expect_that(sum(is.na(x$X_00060_00003)) > 0, is_true())
Laura A DeCicco's avatar
Laura A DeCicco committed
153
154
155
156
157
158
  
  site <- "05212700"
  notActive <- readNWISdv(site, "00060", "2014-01-01","2014-01-07")
  expect_that(nrow(notActive) == 0, is_true())
})

Laura A DeCicco's avatar
Laura A DeCicco committed
159
160
161
162
163
164
165
166
167
168
169
170
test_that("WQP qw tests", {
  testthat::skip_on_cran()
  nameToUse <- 'Specific conductance'
  pcodeToUse <- '00095'
  
  INFO_WQP <- readWQPqw('USGS-04024315',pcodeToUse, startDate = "", endDate = "")
  expect_is(INFO_WQP$ActivityStartDateTime, 'POSIXct')
  
  INFO2 <- readWQPqw('WIDNR_WQX-10032762',nameToUse, startDate = "", endDate = "")
  expect_is(INFO2$ActivityStartDateTime, 'POSIXct')
  
})
David Watkins's avatar
David Watkins committed
171

David Watkins's avatar
David Watkins committed
172
context("readNWISstat tests")
David Watkins's avatar
David Watkins committed
173
174
175
176
test_that("readNWISstat tests", {
  testthat::skip_on_cran()
  data <- readNWISstat(siteNumbers=c("02171500"),parameterCd=c("00010","00060"),
                    statReportType="daily",statType=c("mean","p75","p25"),startDate="2000",endDate="2010")
David Watkins's avatar
David Watkins committed
177
  expect_is(data$begin_yr, 'integer')
David Watkins's avatar
David Watkins committed
178
  expect_that(length(data) > 3, is_true())
David Watkins's avatar
David Watkins committed
179
180
181
182
183
184
185
186
  
  monthData <- readNWISstat(siteNumbers=c("02171500"),parameterCd=c("00010","00060"),
                                                  statReportType="monthly",startDate="2000",endDate="2010")
  expect_is(monthData$mean_va, 'numeric')
  
  annualData <- readNWISstat(siteNumbers=c("02171500"),parameterCd=c("00010","00060"),statReportType="annual",
                             startDate="2000",endDate="2010")
  expect_gt(nrow(annualData),2)
David Watkins's avatar
David Watkins committed
187
})
David Watkins's avatar
David Watkins committed
188
189
190
191

context("readNWISuse tests")
test_that("readNWISuse tests", {
  testthat::skip_on_cran()
David Watkins's avatar
David Watkins committed
192
  dc <- readNWISuse(years=c(2000,2005,2010),stateCd = "DC", countyCd = NULL)
David Watkins's avatar
David Watkins committed
193
194
195
  expect_that(nrow(dc)==3, is_true())
  expect_is(dc$state_cd, 'character')
  
David Watkins's avatar
David Watkins committed
196
  ohio <- readNWISuse(years=2005,stateCd="OH",countyCd="ALL")
David Watkins's avatar
David Watkins committed
197
198
  expect_that(nrow(ohio)==88, is_true())
  
David Watkins's avatar
David Watkins committed
199
  twoCounties <- readNWISuse(years=2010,stateCd="PA",countyCd=c("Cambria","Indiana"))
David Watkins's avatar
David Watkins committed
200
201
  expect_that(nrow(twoCounties)==2, is_true())
})
Laura A DeCicco's avatar
Laura A DeCicco committed
202
203
204

context("state tests")
test_that("state county tests",{
205
206
  testthat::skip_on_cran()
  
Laura A DeCicco's avatar
Laura A DeCicco committed
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
  fullName <- stateCdLookup("wi", "fullName")
  expect_equal(fullName, "Wisconsin")
  
  abbriev <- stateCdLookup("Wisconsin", "postal")
  expect_equal(abbriev, "WI")
  id <- stateCdLookup("WI", "id")
  expect_equal(id, 55)
  name <- stateCdLookup(55, "fullName")
  expect_equal(name, "Wisconsin")
  multipleStates <- stateCdLookup(c("West Virginia", "Wisconsin", 55, "MN"))
  expect_equal(multipleStates, c("WV","WI","WI","MN"))
  
  id <- countyCdLookup(state = "WI", county = "Dane")
  expect_equal(id, "025")
  name <- countyCdLookup(state = "OH", county = 13, output = "fullName")
  expect_equal(name, "Belmont County")
  index <- countyCdLookup(state = "Pennsylvania", county = "ALLEGHENY COUNTY", output = "tableIndex")
  expect_equal(index, 2246)
  fromIDs <- countyCdLookup(state = 13, county = 5, output = "fullName")
  expect_equal(fromIDs, "Bacon County")
Laura A DeCicco's avatar
Laura A DeCicco committed
227
228
229
  counties <-  c("51001","51003")
  already_ready <- countyCdLookup(county = counties)
  expect_equal(counties, already_ready)
Laura A DeCicco's avatar
Laura A DeCicco committed
230
})
David Watkins's avatar
David Watkins committed
231

Lindsay R Carr's avatar
Lindsay R Carr committed
232
233
234
235
236
237
238
239
context("water year column")

df_test <- data.frame(site_no = as.character(1:13),
                      dateTime = seq(as.Date("2010-01-01"),as.Date("2011-01-31"), 
                                     by="months"),
                      result_va = 1:13, stringsAsFactors = FALSE)

test_that("addWaterYear works with Date, POSIXct, character, but breaks with numeric", {
240
  testthat::skip_on_cran()
Lindsay R Carr's avatar
Lindsay R Carr committed
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
  library(dplyr)
  
  df_date <- df_test
  df_date_wy <- addWaterYear(df_date)
  expect_equal(ncol(df_date_wy), ncol(df_date) + 1)
  
  df_posixct <- mutate(df_test, dateTime = as.POSIXct(dateTime))
  df_posixct_wy <- addWaterYear(df_posixct)
  expect_equal(ncol(df_posixct_wy), ncol(df_posixct) + 1)
  
  df_char <- mutate(df_test, dateTime = as.character(dateTime))
  df_char_wy <- addWaterYear(df_char)
  expect_equal(ncol(df_char_wy), ncol(df_char) + 1)
  
  df_num <- mutate(df_test, dateTime = as.numeric(dateTime))
  expect_error(addWaterYear(df_num), "'origin' must be supplied")
})

259
test_that("addWaterYear works for each column name", {
260
  testthat::skip_on_cran()
261
262
263
264
265
266
267
268
269
270
  nwisqw_style <- df_test
  nwisqw_style_wy <- addWaterYear(nwisqw_style)
  expect_equal(ncol(nwisqw_style_wy), ncol(nwisqw_style) + 1)
  
  nwisdata_style <- df_test
  names(nwisdata_style)[2] <- "Date"
  nwisdata_style_wy <- addWaterYear(nwisdata_style)
  expect_equal(ncol(nwisdata_style_wy), ncol(nwisdata_style) + 1)
  
  wqp_style <- df_test
271
272
273
274
  names(wqp_style)[2] <- "ActivityStartDate"
  wqp_style[['ActivityEndDate']] <- wqp_style[["ActivityStartDate"]]
  wqp_style_wy <- addWaterYear(wqp_style)
  expect_equal(ncol(wqp_style_wy), ncol(wqp_style) + 2)
275
276
277
278
279
280
281
  
  userspecified_style <- df_test
  names(userspecified_style)[2] <- "MyDateCol"
  expect_error(addWaterYear(userspecified_style),
               "specified date column does not exist in supplied data frame")
})

Lindsay R Carr's avatar
Lindsay R Carr committed
282
test_that("addWaterYear correctly calculates the WY and is numeric", {
283
  testthat::skip_on_cran()
284
  df_test_wy <- addWaterYear(df_test)
285
286
287
  expect_is(df_test_wy[['waterYear']], "numeric")
  expect_true(all(df_test_wy[['waterYear']][1:9] == 2010))
  expect_true(all(df_test_wy[['waterYear']][10:13] == 2011))
Lindsay R Carr's avatar
Lindsay R Carr committed
288
289
290
})

test_that("addWaterYear adds column next to dateTime", {
291
  testthat::skip_on_cran()
292
293
  df_test_wy <- addWaterYear(df_test)
  dateTime_col <- which(names(df_test_wy) == "dateTime")
294
  expect_equal(names(df_test_wy)[dateTime_col + 1], "waterYear")
Lindsay R Carr's avatar
Lindsay R Carr committed
295
296
297
})

test_that("addWaterYear can be used with pipes", {
298
  testthat::skip_on_cran()
Lindsay R Carr's avatar
Lindsay R Carr committed
299
  library(dplyr)
300
301
  df_test_wy <- df_test %>% addWaterYear()
  expect_equal(ncol(df_test_wy), ncol(df_test) + 1)
Lindsay R Carr's avatar
Lindsay R Carr committed
302
303
304
})

test_that("addWaterYear doesn't add another WY column if it exists", {
305
  testthat::skip_on_cran()
306
307
308
309
310
311
312
  df_test_wy <- addWaterYear(df_test)
  expect_equal(ncol(df_test_wy), ncol(df_test) + 1)
  df_test_wy2 <- addWaterYear(df_test_wy)
  expect_equal(ncol(df_test_wy2), ncol(df_test_wy))
})

test_that("calcWaterYear can handle missing values", {
313
  testthat::skip_on_cran()
314
315
316
317
318
319
  dateVec <- seq(as.Date("2010-01-01"),as.Date("2011-01-31"), by="months")
  dateVec[c(3,7,12)] <- NA
  wyVec <- dataRetrieval:::calcWaterYear(dateVec)
  
  expect_is(wyVec, "numeric")
  expect_true(all(is.na(wyVec[c(3,7,12)])))
Lindsay R Carr's avatar
Lindsay R Carr committed
320
})
Laura A DeCicco's avatar
Laura A DeCicco committed
321
322
323
324


context("Construct NWIS urls")
test_that("Construct NWIS urls", {
325
  testthat::skip_on_cran()
Laura A DeCicco's avatar
Laura A DeCicco committed
326
327
328
329
330
331
332
333
  
  siteNumber <- '01594440'
  startDate <- '1985-01-01'
  endDate <- ''
  pCode <- c("00060","00010")
  url_daily <- constructNWISURL(siteNumber,pCode,
             startDate,endDate,'dv',statCd=c("00003","00001"))
  
Laura A DeCicco's avatar
Laura A DeCicco committed
334
  expect_equal(url_daily, "https://waterservices.usgs.gov/nwis/dv/?site=01594440&format=waterml,1.1&ParameterCd=00060,00010&StatCd=00003,00001&startDT=1985-01-01")
Laura A DeCicco's avatar
Laura A DeCicco committed
335
336
  
  url_unit <- constructNWISURL(siteNumber,pCode,"2012-06-28","2012-06-30",'iv')
Laura A DeCicco's avatar
Laura A DeCicco committed
337
  expect_equal(url_unit, "https://nwis.waterservices.usgs.gov/nwis/iv/?site=01594440&format=waterml,1.1&ParameterCd=00060,00010&startDT=2012-06-28&endDT=2012-06-30")
Laura A DeCicco's avatar
Laura A DeCicco committed
338
339
  
  url_qw_single <- constructNWISURL(siteNumber,"01075",startDate,endDate,'qw')
Laura A DeCicco's avatar
Laura A DeCicco committed
340
  expect_equal(url_qw_single, "https://nwis.waterdata.usgs.gov/nwis/qwdata?search_site_no=01594440&search_site_no_match_type=exact&multiple_parameter_cds=01075&param_cd_operator=AND&list_of_search_criteria=search_site_no,multiple_parameter_cds&group_key=NONE&sitefile_output_format=html_table&column_name=agency_cd&column_name=site_no&column_name=station_nm&inventory_output=0&rdb_inventory_output=file&TZoutput=0&pm_cd_compare=Greater%20than&radio_parm_cds=previous_parm_cds&qw_attributes=0&format=rdb&rdb_qw_attributes=expanded&date_format=YYYY-MM-DD&rdb_compression=value&qw_sample_wide=0&begin_date=1985-01-01")
Laura A DeCicco's avatar
Laura A DeCicco committed
341
342
343
  
  url_qw <- constructNWISURL(siteNumber,c('01075','00029','00453'),
             startDate,endDate,'qw')
Laura A DeCicco's avatar
Laura A DeCicco committed
344
  expect_equal(url_qw, "https://nwis.waterdata.usgs.gov/nwis/qwdata?search_site_no=01594440&search_site_no_match_type=exact&multiple_parameter_cds=01075,00029,00453&param_cd_operator=OR&list_of_search_criteria=search_site_no,multiple_parameter_cds&group_key=NONE&sitefile_output_format=html_table&column_name=agency_cd&column_name=site_no&column_name=station_nm&inventory_output=0&rdb_inventory_output=file&TZoutput=0&pm_cd_compare=Greater%20than&radio_parm_cds=previous_parm_cds&qw_attributes=0&format=rdb&rdb_qw_attributes=expanded&date_format=YYYY-MM-DD&rdb_compression=value&qw_sample_wide=0&begin_date=1985-01-01")
Laura A DeCicco's avatar
Laura A DeCicco committed
345
346
347
  
  url_daily_tsv <- constructNWISURL(siteNumber,pCode,startDate,endDate,'dv',
             statCd=c("00003","00001"),format="tsv")
Laura A DeCicco's avatar
Laura A DeCicco committed
348
  expect_equal(url_daily_tsv, "https://waterservices.usgs.gov/nwis/dv/?site=01594440&format=rdb,1.0&ParameterCd=00060,00010&StatCd=00003,00001&startDT=1985-01-01")
Laura A DeCicco's avatar
Laura A DeCicco committed
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
  
  setAccess("internal")
  url_rating <- constructNWISURL(siteNumber,service="rating",ratingType="base")
  expect_equal(url_rating, "https://waterdata.usgs.gov/nwisweb/get_ratings/?Access=3&site_no=01594440&file_type=base")
  url_peak <- constructNWISURL(siteNumber, service="peak")
  expect_equal(url_peak, "https://nwis.waterdata.usgs.gov/usa/nwis/peak/?Access=3&site_no=01594440&range_selection=date_range&format=rdb")
  
  url_meas <- constructNWISURL(siteNumber, service="meas")
  expect_equal(url_meas, "https://waterdata.usgs.gov/nwis/measurements/?Access=3&site_no=01594440&range_selection=date_range&format=rdb_expanded")
  
  urlQW <- constructNWISURL("450456092225801","70300",startDate="",endDate="","qw",expanded=TRUE)
  expect_equal(urlQW, "https://nwis.waterdata.usgs.gov/nwis/qwdata?Access=3&search_site_no=450456092225801&search_site_no_match_type=exact&multiple_parameter_cds=70300&param_cd_operator=AND&list_of_search_criteria=search_site_no,multiple_parameter_cds&group_key=NONE&sitefile_output_format=html_table&column_name=agency_cd&column_name=site_no&column_name=station_nm&inventory_output=0&rdb_inventory_output=file&TZoutput=0&pm_cd_compare=Greater%20than&radio_parm_cds=previous_parm_cds&qw_attributes=0&format=rdb&rdb_qw_attributes=expanded&date_format=YYYY-MM-DD&rdb_compression=value&qw_sample_wide=0")
  
  setAccess("cooperator")
  urlQW <- constructNWISURL("450456092225801","70300",startDate="",endDate="","qw",expanded=TRUE)
  expect_equal(urlQW, "https://nwis.waterdata.usgs.gov/nwis/qwdata?Access=1&search_site_no=450456092225801&search_site_no_match_type=exact&multiple_parameter_cds=70300&param_cd_operator=AND&list_of_search_criteria=search_site_no,multiple_parameter_cds&group_key=NONE&sitefile_output_format=html_table&column_name=agency_cd&column_name=site_no&column_name=station_nm&inventory_output=0&rdb_inventory_output=file&TZoutput=0&pm_cd_compare=Greater%20than&radio_parm_cds=previous_parm_cds&qw_attributes=0&format=rdb&rdb_qw_attributes=expanded&date_format=YYYY-MM-DD&rdb_compression=value&qw_sample_wide=0")
  
  setAccess("USGS")
  urlQW <- constructNWISURL("450456092225801","70300",startDate="",endDate="","qw",expanded=TRUE)
  expect_equal(urlQW, "https://nwis.waterdata.usgs.gov/nwis/qwdata?Access=2&search_site_no=450456092225801&search_site_no_match_type=exact&multiple_parameter_cds=70300&param_cd_operator=AND&list_of_search_criteria=search_site_no,multiple_parameter_cds&group_key=NONE&sitefile_output_format=html_table&column_name=agency_cd&column_name=site_no&column_name=station_nm&inventory_output=0&rdb_inventory_output=file&TZoutput=0&pm_cd_compare=Greater%20than&radio_parm_cds=previous_parm_cds&qw_attributes=0&format=rdb&rdb_qw_attributes=expanded&date_format=YYYY-MM-DD&rdb_compression=value&qw_sample_wide=0")
  
  setAccess("public")
  urlQW <- constructNWISURL("450456092225801","70300",startDate="",endDate="","qw",expanded=TRUE)
Laura A DeCicco's avatar
Laura A DeCicco committed
372
  expect_equal(urlQW, "https://nwis.waterdata.usgs.gov/nwis/qwdata?search_site_no=450456092225801&search_site_no_match_type=exact&multiple_parameter_cds=70300&param_cd_operator=AND&list_of_search_criteria=search_site_no,multiple_parameter_cds&group_key=NONE&sitefile_output_format=html_table&column_name=agency_cd&column_name=site_no&column_name=station_nm&inventory_output=0&rdb_inventory_output=file&TZoutput=0&pm_cd_compare=Greater%20than&radio_parm_cds=previous_parm_cds&qw_attributes=0&format=rdb&rdb_qw_attributes=expanded&date_format=YYYY-MM-DD&rdb_compression=value&qw_sample_wide=0")
Laura A DeCicco's avatar
Laura A DeCicco committed
373
  
Laura A DeCicco's avatar
Laura A DeCicco committed
374
375
376
377
378
379
  url_use <- constructUseURL(years=c(1990,1995),stateCd="Ohio",countyCd = c(1,3), categories = "ALL")
  expect_equal(url_use, "https://waterdata.usgs.gov/OH/nwis/water_use?format=rdb&rdb_compression=value&wu_area=county&wu_county=1%2C3&wu_year=1990%2C1995&wu_category=ALL")
})

context("Construct WQP urls")
test_that("Construct WQP urls", {
380
381
382
383
384
385
386
387
388
  testthat::skip_on_cran()
  
  site_id <- '01594440'
  startDate <- '1985-01-01'
  endDate <- ''
  pCode <- c("00060","00010")
  url_wqp <- constructWQPURL(paste("USGS",site_id,sep="-"),
             c('01075','00029','00453'),
             startDate,endDate)
Laura A DeCicco's avatar
Laura A DeCicco committed
389
  
390
  expect_equal(url_wqp, "https://www.waterqualitydata.us/Result/search?siteid=USGS-01594440&pCode=01075;00029;00453&startDateLo=01-01-1985&sorted=no&mimeType=tsv")
Laura A DeCicco's avatar
Laura A DeCicco committed
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
})

context("checkWQPdates")
test_that("checkWQPdates", {
  values <- list(startDateLo="01-01-2002", characteristicName="Phosphorous",
            endDate=as.Date("2014-01-01"))
  values1 <- checkWQPdates(values)
  expect_equal(values1$startDateHi, "01-01-2014")
  expect_equal(values1$startDateLo, "01-01-2002")
})

context("Construct NWIS urls")
test_that("Construct NWIS urls", {
  siteNumber <- '01594440'
  startDate <- '1985-01-01'
  endDate <- ''
  pCode <- c("00060","00010")
  url_wqp <- constructWQPURL(paste("USGS",siteNumber,sep="-"),
             c('01075','00029','00453'),
             startDate,endDate)
Laura A DeCicco's avatar
Laura A DeCicco committed
411
  
Laura A DeCicco's avatar
Laura A DeCicco committed
412
413
414
415
  expect_equal(url_wqp, "https://www.waterqualitydata.us/Result/search?siteid=USGS-01594440&pCode=01075;00029;00453&startDateLo=01-01-1985&sorted=no&mimeType=tsv")

  rawSampleURL_Zip <- constructWQPURL('USGS-01594440','01075', '', '', TRUE)
  expect_equal(rawSampleURL_Zip, "https://www.waterqualitydata.us/Result/search?siteid=USGS-01594440&pCode=01075&sorted=no&mimeType=tsv&zip=yes")
Laura A DeCicco's avatar
Laura A DeCicco committed
416
417
418
419
420
})


context("pCode Stuff")
test_that("pCode Stuff", {
421
422
423
  
  testthat::skip_on_cran()
  
Laura A DeCicco's avatar
Laura A DeCicco committed
424
425
426
427
  paramINFO <- readNWISpCode(c('01075','00060','00931', NA))
  expect_equal(nrow(paramINFO), 4)
  
  paramINFO <- readNWISpCode("all")
428
  expect_equal(attr(paramINFO, "url"),"https://nwis.waterdata.usgs.gov/nwis/pmcodes/pmcodes?radio_pm_search=param_group&pm_group=All+--+include+all+parameter+groups&show=parameter_group_nm&show=parameter_nm&show=casrn&show=srsname&show=parameter_units&format=rdb")
Laura A DeCicco's avatar
Laura A DeCicco committed
429
})