@@ -104,6 +104,109 @@ def verify_export_general(channel_path, http_submit, http_fetch):
104104 assert b"cdn.datatables.net" in deferred .result
105105
106106
107+ @pytest_twisted .inlineCallbacks
108+ @pytest .mark .http
109+ @pytest .mark .export
110+ def test_export_exclude_include (machinery , create_influxdb , reset_influxdb ):
111+ """
112+ Verify `exclude` and `include` transformation parameters of HTTP export API.
113+ """
114+
115+ # Submit a single measurement, with timestamp.
116+ data = {
117+ 'time' : 1583810982 ,
118+ 'temperature' : 25.26 ,
119+ 'humidity' : 51.8 ,
120+ }
121+ yield threads .deferToThread (http_json_sensor , settings .channel_path_data , data )
122+
123+ # Wait for some time to process the message.
124+ yield sleep (PROCESS_DELAY_MQTT )
125+
126+ # Excluding fields.
127+ deferred = threads .deferToThread (http_get_data , settings .channel_path_data , format = "json" , params = {
128+ "from" : ts_from ,
129+ "to" : ts_to ,
130+ "exclude" : "time,humidity" ,
131+ })
132+ yield deferred
133+ result = json .loads (deferred .result )
134+ assert_equal (result , [{"temperature" : 25.26 }])
135+
136+ # Including fields.
137+ deferred = threads .deferToThread (http_get_data , settings .channel_path_data , format = "json" , params = {
138+ "from" : ts_from ,
139+ "to" : ts_to ,
140+ "include" : "temperature" ,
141+ })
142+ yield deferred
143+ result = json .loads (deferred .result )
144+ assert_equal (result , [{"time" : "2020-03-10T03:29:42.000Z" , "temperature" : 25.26 }])
145+
146+
147+ @pytest_twisted .inlineCallbacks
148+ @pytest .mark .http
149+ @pytest .mark .export
150+ def test_export_sorting_limit_scalar (machinery , create_influxdb , reset_influxdb ):
151+ """
152+ Verify `sort` and `direction` transformation parameters of HTTP export API.
153+ """
154+
155+ # Submit two measurements, with timestamp.
156+ data = {
157+ 'time' : 1583810982 ,
158+ 'temperature' : 25.26 ,
159+ 'humidity' : 51.8 ,
160+ }
161+ yield threads .deferToThread (http_json_sensor , settings .channel_path_data , data )
162+
163+ data = {
164+ 'time' : 1583810993 ,
165+ 'temperature' : 32.26 ,
166+ 'humidity' : 64.8 ,
167+ }
168+ yield threads .deferToThread (http_json_sensor , settings .channel_path_data , data )
169+
170+ # Wait for some time to process the message.
171+ yield sleep (PROCESS_DELAY_MQTT )
172+
173+ # Sorting.
174+ deferred = threads .deferToThread (http_get_data , settings .channel_path_data , format = "json" , params = {
175+ "from" : ts_from ,
176+ "to" : ts_to ,
177+ "exclude" : "time,humidity" ,
178+ "sort" : "temperature" ,
179+ "direction" : "descending" ,
180+ })
181+ yield deferred
182+ result = json .loads (deferred .result )
183+ assert_equal (result , [{"temperature" : 32.26 }, {'temperature' : 25.26 }])
184+
185+ # Limit.
186+ deferred = threads .deferToThread (http_get_data , settings .channel_path_data , format = "json" , params = {
187+ "from" : ts_from ,
188+ "to" : ts_to ,
189+ "exclude" : "time,humidity" ,
190+ "sort" : "temperature" ,
191+ "direction" : "descending" ,
192+ "limit" : 1 ,
193+ })
194+ yield deferred
195+ result = json .loads (deferred .result )
196+ assert_equal (result , [{"temperature" : 32.26 }])
197+
198+ # Scalar.
199+ deferred = threads .deferToThread (http_get_data , settings .channel_path_data , format = "txt" , params = {
200+ "from" : ts_from ,
201+ "to" : ts_to ,
202+ "sort" : "temperature" ,
203+ "direction" : "descending" ,
204+ "scalar" : "temperature" ,
205+ })
206+ yield deferred
207+ assert deferred .result == "32.26"
208+
209+
107210@pytest_twisted .inlineCallbacks
108211@pytest .mark .http
109212@pytest .mark .export
0 commit comments