@@ -79,6 +79,95 @@ def test_round_trip(self):
79
79
'message' : 'success' ,
80
80
})
81
81
82
+ def test_fields (self ):
83
+ """Test to limit fields field"""
84
+
85
+ # insert dummy data
86
+ self .cur .execute ('''
87
+ insert into covidcast values
88
+ (0, 'src', 'sig', 'day', 'county', 20200414, '01234',
89
+ 123, 1.5, 2.5, 3.5, 456, 4, 20200414, 0, 1, False)
90
+ ''' )
91
+ self .cnx .commit ()
92
+
93
+ # make the request
94
+ response = requests .get (BASE_URL , params = {
95
+ 'source' : 'covidcast' ,
96
+ 'data_source' : 'src' ,
97
+ 'signal' : 'sig' ,
98
+ 'time_type' : 'day' ,
99
+ 'geo_type' : 'county' ,
100
+ 'time_values' : 20200414 ,
101
+ 'geo_value' : '01234' ,
102
+ })
103
+ response .raise_for_status ()
104
+ response = response .json ()
105
+
106
+ # assert that the right data came back
107
+ self .assertEqual (response , {
108
+ 'result' : 1 ,
109
+ 'epidata' : [{
110
+ 'time_value' : 20200414 ,
111
+ 'geo_value' : '01234' ,
112
+ 'value' : 1.5 ,
113
+ 'stderr' : 2.5 ,
114
+ 'sample_size' : 3.5 ,
115
+ 'direction' : 4 ,
116
+ 'issue' : 20200414 ,
117
+ 'lag' : 0 ,
118
+ 'signal' : 'sig'
119
+ }],
120
+ 'message' : 'success' ,
121
+ })
122
+
123
+ # limit fields
124
+ response = requests .get (BASE_URL , params = {
125
+ 'source' : 'covidcast' ,
126
+ 'data_source' : 'src' ,
127
+ 'signal' : 'sig' ,
128
+ 'time_type' : 'day' ,
129
+ 'geo_type' : 'county' ,
130
+ 'time_values' : 20200414 ,
131
+ 'geo_value' : '01234' ,
132
+ 'fields' : 'time_value,geo_value'
133
+ })
134
+ response .raise_for_status ()
135
+ response = response .json ()
136
+
137
+ # assert that the right data came back
138
+ self .assertEqual (response , {
139
+ 'result' : 1 ,
140
+ 'epidata' : [{
141
+ 'time_value' : 20200414 ,
142
+ 'geo_value' : '01234'
143
+ }],
144
+ 'message' : 'success' ,
145
+ })
146
+
147
+ # limit invalid values
148
+ response = requests .get (BASE_URL , params = {
149
+ 'source' : 'covidcast' ,
150
+ 'data_source' : 'src' ,
151
+ 'signal' : 'sig' ,
152
+ 'time_type' : 'day' ,
153
+ 'geo_type' : 'county' ,
154
+ 'time_values' : 20200414 ,
155
+ 'geo_value' : '01234' ,
156
+ 'fields' : 'time_value,geo_value,dummy'
157
+ })
158
+ response .raise_for_status ()
159
+ response = response .json ()
160
+
161
+ # assert that the right data came back
162
+ self .assertEqual (response , {
163
+ 'result' : 1 ,
164
+ 'epidata' : [{
165
+ 'time_value' : 20200414 ,
166
+ 'geo_value' : '01234'
167
+ }],
168
+ 'message' : 'success' ,
169
+ })
170
+
82
171
def test_location_wildcard (self ):
83
172
"""Select all locations with a wildcard query."""
84
173
@@ -340,3 +429,120 @@ def test_temporal_partitioning(self):
340
429
}],
341
430
'message' : 'success' ,
342
431
})
432
+
433
+ def test_date_formats (self ):
434
+ """Request a signal using different time formats."""
435
+
436
+ # insert dummy data
437
+ self .cur .execute ('''
438
+ insert into covidcast values
439
+ (0, 'src', 'sig', 'day', 'county', 20200411, '01234',
440
+ 123, 10, 11, 12, 456, 13, 20200413, 0, 1, False),
441
+ (0, 'src', 'sig', 'day', 'county', 20200412, '01234',
442
+ 123, 20, 21, 22, 456, 23, 20200413, 0, 1, False),
443
+ (0, 'src', 'sig', 'day', 'county', 20200413, '01234',
444
+ 123, 30, 31, 32, 456, 33, 20200413, 0, 1, False),
445
+ (0, 'src', 'sig', 'day', 'county', 20200411, '11111',
446
+ 123, 40, 41, 42, 456, 43, 20200413, 0, 1, False),
447
+ (0, 'src', 'sig', 'day', 'county', 20200412, '22222',
448
+ 123, 50, 51, 52, 456, 53, 20200413, 0, 1, False),
449
+ (0, 'src', 'sig', 'day', 'county', 20200413, '33333',
450
+ 123, 60, 61, 62, 456, 63, 20200413, 0, 1, False)
451
+ ''' )
452
+ self .cnx .commit ()
453
+
454
+ # make the request
455
+ response = requests .get (BASE_URL , params = {
456
+ 'source' : 'covidcast' ,
457
+ 'data_source' : 'src' ,
458
+ 'signal' : 'sig' ,
459
+ 'time_type' : 'day' ,
460
+ 'geo_type' : 'county' ,
461
+ 'time_values' : '20200411' ,
462
+ 'geo_value' : '*' ,
463
+ })
464
+ response .raise_for_status ()
465
+ response = response .json ()
466
+
467
+ # assert that the right data came back
468
+ self .assertEqual (len (response ['epidata' ]), 2 )
469
+
470
+ # make the request
471
+ response = requests .get (BASE_URL , params = {
472
+ 'source' : 'covidcast' ,
473
+ 'data_source' : 'src' ,
474
+ 'signal' : 'sig' ,
475
+ 'time_type' : 'day' ,
476
+ 'geo_type' : 'county' ,
477
+ 'time_values' : '2020-04-11' ,
478
+ 'geo_value' : '*' ,
479
+ })
480
+ response .raise_for_status ()
481
+ response = response .json ()
482
+
483
+ # assert that the right data came back
484
+ self .assertEqual (len (response ['epidata' ]), 2 )
485
+
486
+ # make the request
487
+ response = requests .get (BASE_URL , params = {
488
+ 'source' : 'covidcast' ,
489
+ 'data_source' : 'src' ,
490
+ 'signal' : 'sig' ,
491
+ 'time_type' : 'day' ,
492
+ 'geo_type' : 'county' ,
493
+ 'time_values' : '20200411,20200412' ,
494
+ 'geo_value' : '*' ,
495
+ })
496
+ response .raise_for_status ()
497
+ response = response .json ()
498
+
499
+ # assert that the right data came back
500
+ self .assertEqual (len (response ['epidata' ]), 4 )
501
+
502
+ # make the request
503
+ response = requests .get (BASE_URL , params = {
504
+ 'source' : 'covidcast' ,
505
+ 'data_source' : 'src' ,
506
+ 'signal' : 'sig' ,
507
+ 'time_type' : 'day' ,
508
+ 'geo_type' : 'county' ,
509
+ 'time_values' : '2020-04-11,2020-04-12' ,
510
+ 'geo_value' : '*' ,
511
+ })
512
+ response .raise_for_status ()
513
+ response = response .json ()
514
+
515
+ # assert that the right data came back
516
+ self .assertEqual (len (response ['epidata' ]), 4 )
517
+
518
+ # make the request
519
+ response = requests .get (BASE_URL , params = {
520
+ 'source' : 'covidcast' ,
521
+ 'data_source' : 'src' ,
522
+ 'signal' : 'sig' ,
523
+ 'time_type' : 'day' ,
524
+ 'geo_type' : 'county' ,
525
+ 'time_values' : '20200411-20200413' ,
526
+ 'geo_value' : '*' ,
527
+ })
528
+ response .raise_for_status ()
529
+ response = response .json ()
530
+
531
+ # assert that the right data came back
532
+ self .assertEqual (len (response ['epidata' ]), 6 )
533
+
534
+ # make the request
535
+ response = requests .get (BASE_URL , params = {
536
+ 'source' : 'covidcast' ,
537
+ 'data_source' : 'src' ,
538
+ 'signal' : 'sig' ,
539
+ 'time_type' : 'day' ,
540
+ 'geo_type' : 'county' ,
541
+ 'time_values' : '2020-04-11:2020-04-13' ,
542
+ 'geo_value' : '*' ,
543
+ })
544
+ response .raise_for_status ()
545
+ response = response .json ()
546
+
547
+ # assert that the right data came back
548
+ self .assertEqual (len (response ['epidata' ]), 6 )
0 commit comments