Code Duplication    Length = 45-46 lines in 2 locations

tests/unit/test_main.py 2 locations

@@ 359-404 (lines=46) @@
356
        response = await self.api_client.put(self.trace_endpoint, json=payload)
357
        assert response.status_code == 424
358
359
    @patch("napps.amlight.sdntrace_cp.main.get_stored_flows")
360
    async def test_get_traces(self, mock_stored_flows, event_loop):
361
        """Test traces rest call."""
362
        self.napp.controller.loop = event_loop
363
        payload = [{
364
            "trace": {
365
                "switch": {
366
                    "dpid": "00:00:00:00:00:00:00:01",
367
                    "in_port": 1
368
                    },
369
                "eth": {"dl_vlan": 100},
370
            }
371
        }]
372
373
        stored_flow = {
374
            "id": 1,
375
            "flow": {
376
                "table_id": 0,
377
                "cookie": 84114964,
378
                "hard_timeout": 0,
379
                "idle_timeout": 0,
380
                "priority": 10,
381
                "match": {"dl_vlan": 100, "in_port": 1},
382
                "actions": [
383
                    {"action_type": "pop_vlan"},
384
                    {"action_type": "output", "port": 2},
385
                ],
386
            }
387
        }
388
389
        mock_stored_flows.return_value = {
390
            "00:00:00:00:00:00:00:01": [stored_flow]
391
        }
392
393
        resp = await self.api_client.put(self.traces_endpoint, json=payload)
394
        assert resp.status_code == 200
395
        current_data = resp.json()
396
        result1 = current_data["result"]
397
398
        assert len(result1) == 1
399
        assert len(result1[0]) == 1
400
        assert result1[0][0]["dpid"] == "00:00:00:00:00:00:00:01"
401
        assert result1[0][0]["port"] == 1
402
        assert result1[0][0]["type"] == "last"
403
        assert result1[0][0]["vlan"] == 100
404
        assert result1[0][0]["out"] == {"port": 2}
405
406
    @patch("napps.amlight.sdntrace_cp.main.get_stored_flows")
407
    async def test_traces(self, mock_stored_flows, event_loop):
@@ 505-549 (lines=45) @@
502
        resp = await self.api_client.put(self.traces_endpoint, json=payload)
503
        assert resp.status_code == 424
504
505
    @patch("napps.amlight.sdntrace_cp.main.get_stored_flows")
506
    async def test_traces_with_loop(self, mock_stored_flows, event_loop):
507
        """Test traces rest call"""
508
        self.napp.controller.loop = event_loop
509
        payload = [
510
                    {
511
                        "trace": {
512
                            "switch": {
513
                                "dpid": "00:00:00:00:00:00:00:01",
514
                                "in_port": 1
515
                            },
516
                            "eth": {
517
                                "dl_vlan": 100
518
                            }
519
                        }
520
                    }
521
                ]
522
523
        stored_flow = {
524
            "id": 1,
525
            "flow": {
526
                "table_id": 0,
527
                "cookie": 84114964,
528
                "hard_timeout": 0,
529
                "idle_timeout": 0,
530
                "priority": 10,
531
                "match": {"dl_vlan": 100, "in_port": 1},
532
                "actions": [{"action_type": "output", "port": 1}],
533
            }
534
        }
535
536
        mock_stored_flows.return_value = {
537
            "00:00:00:00:00:00:00:01": [stored_flow],
538
        }
539
540
        resp = await self.api_client.put(self.traces_endpoint, json=payload)
541
        assert resp.status_code == 200
542
        current_data = resp.json()
543
        result = current_data["result"]
544
        assert len(result) == 1
545
        assert result[0][0]["dpid"] == "00:00:00:00:00:00:00:01"
546
        assert result[0][0]["port"] == 1
547
        assert result[0][0]["type"] == "loop"
548
        assert result[0][0]["vlan"] == 100
549
        assert result[0][0]["out"] == {"port": 1, "vlan": 100}
550
551
    @patch("napps.amlight.sdntrace_cp.main.get_stored_flows")
552
    async def test_traces_no_action(self, mock_stored_flows, event_loop):