Code Duplication    Length = 22-24 lines in 5 locations

tests/unit/test_main.py 5 locations

@@ 251-274 (lines=24) @@
248
        expected = flow_by_sw
249
        assert response.json() == expected
250
251
    @patch("napps.amlight.kytos_stats.main.Main.flow_stats_by_dpid_flow_id")
252
    async def test_flow_stats_by_dpid_flow_id_without_dpid(self,
253
                                                           mock_from_flow):
254
        """Test flow_stats rest call."""
255
        flow_info = {
256
            "byte_count": 10,
257
            "duration_sec": 20,
258
            "duration_nsec": 30,
259
            "packet_count": 40,
260
            "cookie": 12310228866111668291,
261
            "match": {"in_port": 1},
262
            "priority": 32768
263
            }
264
        flow_stats_dict_mock = {'6055f13593fad45e0b4699f49d56b105': flow_info}
265
        flow_by_sw = {"00:00:00:00:00:00:00:01": flow_stats_dict_mock}
266
        mock_from_flow.return_value = flow_by_sw
267
268
        endpoint = "/flow/stats"
269
        url = f"{self.base_endpoint}{endpoint}"
270
        response = await self.api_client.get(url)
271
        assert response.status_code == 200
272
273
        expected = flow_by_sw
274
        assert response.json() == expected
275
276
    @patch("napps.amlight.kytos_stats.main.Main.flow_stats_by_dpid_flow_id")
277
    async def test_flow_stats_by_dpid_flow_id_with_dpid(self, mock_from_flow):
@@ 276-298 (lines=23) @@
273
        expected = flow_by_sw
274
        assert response.json() == expected
275
276
    @patch("napps.amlight.kytos_stats.main.Main.flow_stats_by_dpid_flow_id")
277
    async def test_flow_stats_by_dpid_flow_id_with_dpid(self, mock_from_flow):
278
        """Test flow_stats rest call."""
279
        flow_info = {
280
            "byte_count": 10,
281
            "duration_sec": 20,
282
            "duration_nsec": 30,
283
            "packet_count": 40,
284
            "cookie": 12310228866111668291,
285
            "match": {"in_port": 1},
286
            "priority": 32768
287
            }
288
        flow_stats_dict_mock = {'6055f13593fad45e0b4699f49d56b105': flow_info}
289
        flow_by_sw = {"00:00:00:00:00:00:00:01": flow_stats_dict_mock}
290
        mock_from_flow.return_value = flow_by_sw
291
292
        endpoint = "/flow/stats?dpid=00:00:00:00:00:00:00:01"
293
        url = f"{self.base_endpoint}{endpoint}"
294
        response = await self.api_client.get(url)
295
        assert response.status_code == 200
296
297
        expected = flow_by_sw
298
        assert response.json() == expected
299
300
    @patch("napps.amlight.kytos_stats.main.Main.flow_stats_by_dpid_flow_id")
301
    async def test_flow_stats_by_dpid_flow_id_not_found(self, mock_from_flow):
@@ 228-249 (lines=22) @@
225
        assert response.status_code == 200
226
        assert len(response.json()) == 1
227
228
    @patch("napps.amlight.kytos_stats.main.Main.flow_stats_by_dpid_flow_id")
229
    async def test_flow_stats_by_dpid_flow_id(self, mock_from_flow):
230
        """Test flow_stats rest call."""
231
        flow_info = {
232
            "byte_count": 10,
233
            "duration_sec": 20,
234
            "duration_nsec": 30,
235
            "packet_count": 40,
236
            "cookie": 12310228866111668291,
237
            "match": {"in_port": 1},
238
            "priority": 32768
239
            }
240
        flow_stats_dict_mock = {'6055f13593fad45e0b4699f49d56b105': flow_info}
241
        flow_by_sw = {"00:00:00:00:00:00:00:01": flow_stats_dict_mock}
242
        mock_from_flow.return_value = flow_by_sw
243
244
        endpoint = "/flow/stats?dpid=00:00:00:00:00:00:00:01"
245
        url = f"{self.base_endpoint}{endpoint}"
246
        response = await self.api_client.get(url)
247
        assert response.status_code == 200
248
        expected = flow_by_sw
249
        assert response.json() == expected
250
251
    @patch("napps.amlight.kytos_stats.main.Main.flow_stats_by_dpid_flow_id")
252
    async def test_flow_stats_by_dpid_flow_id_without_dpid(self,
@@ 205-226 (lines=22) @@
202
        assert response.status_code == 200
203
        assert len(response.json()) == 1
204
205
    @patch("napps.amlight.kytos_stats.main.Main.flow_stats_by_dpid_flow_id")
206
    async def test_flows_counters_bytes(self, mock_from_flow):
207
        """Test flows_counters function for bytes"""
208
        flow_info = {
209
            "byte_count": 10,
210
            "duration_sec": 20,
211
            "duration_nsec": 30,
212
            "packet_count": 40,
213
            "cookie": 12310228866111668291,
214
            "match": {"in_port": 1},
215
            "priority": 32768
216
            }
217
        flow_id = '6055f13593fad45e0b4699f49d56b105'
218
        flow_stats_dict_mock = {flow_id: flow_info}
219
        dpid = "00:00:00:00:00:00:00:01"
220
        flow_by_sw = {dpid: flow_stats_dict_mock}
221
        mock_from_flow.return_value = flow_by_sw
222
223
        endpoint = f"{self.base_endpoint}/bytes_count/per_flow/{dpid}"
224
        response = await self.api_client.get(endpoint)
225
        assert response.status_code == 200
226
        assert len(response.json()) == 1
227
228
    @patch("napps.amlight.kytos_stats.main.Main.flow_stats_by_dpid_flow_id")
229
    async def test_flow_stats_by_dpid_flow_id(self, mock_from_flow):
@@ 182-203 (lines=22) @@
179
        assert json_response[0]["bytes_counter"] == 10
180
        assert json_response[0]["bits_per_second"] == 4.0
181
182
    @patch("napps.amlight.kytos_stats.main.Main.flow_stats_by_dpid_flow_id")
183
    async def test_flows_counters_packet(self, mock_from_flow):
184
        """Test flows_counters function for packet"""
185
        flow_info = {
186
            "byte_count": 10,
187
            "duration_sec": 20,
188
            "duration_nsec": 30,
189
            "packet_count": 40,
190
            "cookie": 12310228866111668291,
191
            "match": {"in_port": 1},
192
            "priority": 32768
193
            }
194
        flow_id = '6055f13593fad45e0b4699f49d56b105'
195
        flow_stats_dict_mock = {flow_id: flow_info}
196
        dpid = "00:00:00:00:00:00:00:01"
197
        flow_by_sw = {dpid: flow_stats_dict_mock}
198
        mock_from_flow.return_value = flow_by_sw
199
200
        endpoint = f"{self.base_endpoint}/packet_count/per_flow/{dpid}"
201
        response = await self.api_client.get(endpoint)
202
        assert response.status_code == 200
203
        assert len(response.json()) == 1
204
205
    @patch("napps.amlight.kytos_stats.main.Main.flow_stats_by_dpid_flow_id")
206
    async def test_flows_counters_bytes(self, mock_from_flow):