@@ -79,6 +79,76 @@ def test_round_trip(self):
79
79
'message' : 'success' ,
80
80
})
81
81
82
+
83
+ def test_csv_format (self ):
84
+ """Test generate csv data."""
85
+
86
+ # insert dummy data
87
+ self .cur .execute ('''
88
+ insert into covidcast values
89
+ (0, 'src', 'sig', 'day', 'county', 20200414, '01234',
90
+ 123, 1.5, 2.5, 3.5, 456, 4, 20200414, 0, 1, False)
91
+ ''' )
92
+ self .cnx .commit ()
93
+
94
+ # make the request
95
+ response = requests .get (BASE_URL , params = {
96
+ 'source' : 'covidcast' ,
97
+ 'data_source' : 'src' ,
98
+ 'signal' : 'sig' ,
99
+ 'time_type' : 'day' ,
100
+ 'geo_type' : 'county' ,
101
+ 'time_values' : 20200414 ,
102
+ 'geo_value' : '01234' ,
103
+ 'format' : 'csv'
104
+ })
105
+ response .raise_for_status ()
106
+ response = response .text
107
+
108
+ # assert that the right data came back
109
+ self .assertEqual (response ,
110
+ """geo_value,signal,time_value,direction,issue,lag,value,stderr,sample_size
111
+ 01234,sig,20200414,4,20200414,0,1.5,2.5,3.5
112
+ """ )
113
+
114
+ def test_raw_json_format (self ):
115
+ """Test generate raw json data."""
116
+
117
+ # insert dummy data
118
+ self .cur .execute ('''
119
+ insert into covidcast values
120
+ (0, 'src', 'sig', 'day', 'county', 20200414, '01234',
121
+ 123, 1.5, 2.5, 3.5, 456, 4, 20200414, 0, 1, False)
122
+ ''' )
123
+ self .cnx .commit ()
124
+
125
+ # make the request
126
+ response = requests .get (BASE_URL , params = {
127
+ 'source' : 'covidcast' ,
128
+ 'data_source' : 'src' ,
129
+ 'signal' : 'sig' ,
130
+ 'time_type' : 'day' ,
131
+ 'geo_type' : 'county' ,
132
+ 'time_values' : 20200414 ,
133
+ 'geo_value' : '01234' ,
134
+ 'format' : 'json'
135
+ })
136
+ response .raise_for_status ()
137
+ response = response .json ()
138
+
139
+ # assert that the right data came back
140
+ self .assertEqual (response , [{
141
+ 'time_value' : 20200414 ,
142
+ 'geo_value' : '01234' ,
143
+ 'value' : 1.5 ,
144
+ 'stderr' : 2.5 ,
145
+ 'sample_size' : 3.5 ,
146
+ 'direction' : 4 ,
147
+ 'issue' : 20200414 ,
148
+ 'lag' : 0 ,
149
+ 'signal' : 'sig' ,
150
+ }])
151
+
82
152
def test_fields (self ):
83
153
"""Test to limit fields field"""
84
154
0 commit comments