Code Duplication    Length = 45-46 lines in 2 locations

tests/unit/test_main.py 2 locations

@@ 440-485 (lines=46) @@
437
        result = current_data["result"]
438
        assert result == []
439
440
    @patch("napps.amlight.sdntrace_cp.main.get_stored_flows")
441
    async def test_get_traces(self, mock_stored_flows):
442
        """Test traces rest call."""
443
        self.napp.controller.loop = asyncio.get_running_loop()
444
        payload = [{
445
            "trace": {
446
                "switch": {
447
                    "dpid": "00:00:00:00:00:00:00:01",
448
                    "in_port": 1
449
                    },
450
                "eth": {"dl_vlan": 100},
451
            }
452
        }]
453
454
        stored_flow = {
455
            "id": 1,
456
            "flow": {
457
                "table_id": 0,
458
                "cookie": 84114964,
459
                "hard_timeout": 0,
460
                "idle_timeout": 0,
461
                "priority": 10,
462
                "match": {"dl_vlan": 100, "in_port": 1},
463
                "actions": [
464
                    {"action_type": "pop_vlan"},
465
                    {"action_type": "output", "port": 2},
466
                ],
467
            }
468
        }
469
470
        mock_stored_flows.return_value = {
471
            "00:00:00:00:00:00:00:01": [stored_flow]
472
        }
473
474
        resp = await self.api_client.put(self.traces_endpoint, json=payload)
475
        assert resp.status_code == 200
476
        current_data = resp.json()
477
        result1 = current_data["result"]
478
479
        assert len(result1) == 1
480
        assert len(result1[0]) == 1
481
        assert result1[0][0]["dpid"] == "00:00:00:00:00:00:00:01"
482
        assert result1[0][0]["port"] == 1
483
        assert result1[0][0]["type"] == "last"
484
        assert result1[0][0]["vlan"] == 100
485
        assert result1[0][0]["out"] == {"port": 2}
486
487
    @patch("napps.amlight.sdntrace_cp.main.get_stored_flows")
488
    async def test_traces(self, mock_stored_flows):
@@ 582-626 (lines=45) @@
579
        resp = await self.api_client.put(self.traces_endpoint, json=payload)
580
        assert resp.status_code == 424
581
582
    @patch("napps.amlight.sdntrace_cp.main.get_stored_flows")
583
    async def test_traces_with_loop(self, mock_stored_flows):
584
        """Test traces rest call"""
585
        self.napp.controller.loop = asyncio.get_running_loop()
586
        payload = [
587
                    {
588
                        "trace": {
589
                            "switch": {
590
                                "dpid": "00:00:00:00:00:00:00:01",
591
                                "in_port": 1
592
                            },
593
                            "eth": {
594
                                "dl_vlan": 100
595
                            }
596
                        }
597
                    }
598
                ]
599
600
        stored_flow = {
601
            "id": 1,
602
            "flow": {
603
                "table_id": 0,
604
                "cookie": 84114964,
605
                "hard_timeout": 0,
606
                "idle_timeout": 0,
607
                "priority": 10,
608
                "match": {"dl_vlan": 100, "in_port": 1},
609
                "actions": [{"action_type": "output", "port": 1}],
610
            }
611
        }
612
613
        mock_stored_flows.return_value = {
614
            "00:00:00:00:00:00:00:01": [stored_flow],
615
        }
616
617
        resp = await self.api_client.put(self.traces_endpoint, json=payload)
618
        assert resp.status_code == 200
619
        current_data = resp.json()
620
        result = current_data["result"]
621
        assert len(result) == 1
622
        assert result[0][0]["dpid"] == "00:00:00:00:00:00:00:01"
623
        assert result[0][0]["port"] == 1
624
        assert result[0][0]["type"] == "loop"
625
        assert result[0][0]["vlan"] == 100
626
        assert result[0][0]["out"] == {"port": 1, "vlan": 100}
627
628
    @patch("napps.amlight.sdntrace_cp.main.get_stored_flows")
629
    async def test_traces_no_action(self, mock_stored_flows):