Code Duplication    Length = 45-46 lines in 2 locations

tests/unit/test_main.py 2 locations

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