Code Duplication    Length = 61-63 lines in 2 locations

tests/unit/test_main.py 2 locations

@@ 511-573 (lines=63) @@
508
        assert result2[0][0]["type"] == "starting"
509
        assert result2[0][0]["vlan"] == 100
510
511
    @patch("napps.amlight.sdntrace_cp.utils.get_stored_flows")
512
    @patch("napps.amlight.sdntrace_cp.utils.requests")
513
    def test_traces_same_switch(self, mock_request_get, mock_stored_flows):
514
        """Test traces rest call for two traces with samw switches."""
515
        api = get_test_client(get_controller_mock(), self.napp)
516
        url = f"{self.server_name_url}/traces/"
517
518
        payload = [
519
            {
520
                "trace": {
521
                    "switch": {
522
                        "dpid": "00:00:00:00:00:00:00:01",
523
                        "in_port": 1
524
                    },
525
                    "eth": {"dl_vlan": 100},
526
                }
527
            },
528
            {
529
                "trace": {
530
                    "switch": {
531
                        "dpid": "00:00:00:00:00:00:00:01",
532
                        "in_port": 2
533
                    },
534
                    "eth": {"dl_vlan": 100},
535
                }
536
            }
537
        ]
538
539
        stored_flow = {
540
                "id": 1,
541
                "table_id": 0,
542
                "cookie": 84114964,
543
                "hard_timeout": 0,
544
                "idle_timeout": 0,
545
                "priority": 10,
546
        }
547
548
        mock_stored_flows.return_value = {
549
            "00:00:00:00:00:00:00:01": [stored_flow]
550
        }
551
        mock_json = MagicMock()
552
        mock_json.json.return_value = {
553
            "00:00:00:00:00:00:00:01": [stored_flow]
554
        }
555
        mock_request_get.get.return_value = mock_json
556
557
        response = api.put(
558
            url, data=json.dumps(payload), content_type="application/json"
559
        )
560
        current_data = json.loads(response.data)
561
        result = current_data["00:00:00:00:00:00:00:01"]
562
563
        assert len(current_data) == 1
564
565
        assert result[0][0]["dpid"] == "00:00:00:00:00:00:00:01"
566
        assert result[0][0]["port"] == 1
567
        assert result[0][0]["type"] == "starting"
568
        assert result[0][0]["vlan"] == 100
569
570
        assert result[1][0]["dpid"] == "00:00:00:00:00:00:00:01"
571
        assert result[1][0]["port"] == 2
572
        assert result[1][0]["type"] == "starting"
573
        assert result[1][0]["vlan"] == 100
574
575
    @patch("napps.amlight.sdntrace_cp.utils.get_stored_flows")
576
    @patch("napps.amlight.sdntrace_cp.utils.requests")
@@ 449-509 (lines=61) @@
446
        assert result1[0][0]["vlan"] == 100
447
        assert result1[0][0]["out"] is None
448
449
    @patch("napps.amlight.sdntrace_cp.utils.get_stored_flows")
450
    @patch("napps.amlight.sdntrace_cp.utils.requests")
451
    def test_traces(self, mock_request_get, mock_stored_flows):
452
        """Test traces rest call for two traces with different switches."""
453
        api = get_test_client(get_controller_mock(), self.napp)
454
        url = f"{self.server_name_url}/traces/"
455
456
        payload = [
457
            {
458
                "trace": {
459
                    "switch": {
460
                        "dpid": "00:00:00:00:00:00:00:01",
461
                        "in_port": 1
462
                        },
463
                    "eth": {"dl_vlan": 100},
464
                }
465
            },
466
            {
467
                "trace": {
468
                    "switch": {
469
                        "dpid": "00:00:00:00:00:00:00:02",
470
                        "in_port": 1},
471
                    "eth": {"dl_vlan": 100},
472
                }
473
            }
474
        ]
475
476
        stored_flow = {
477
                "id": 1,
478
                "table_id": 0,
479
                "cookie": 84114964,
480
                "hard_timeout": 0,
481
                "idle_timeout": 0,
482
                "priority": 10,
483
        }
484
485
        mock_stored_flows.return_value = {
486
            "00:00:00:00:00:00:00:01": [stored_flow]
487
        }
488
        mock_json = MagicMock()
489
        mock_json.json.return_value = {
490
            "00:00:00:00:00:00:00:01": [stored_flow]
491
        }
492
        mock_request_get.get.return_value = mock_json
493
494
        response = api.put(
495
            url, data=json.dumps(payload), content_type="application/json"
496
        )
497
        current_data = json.loads(response.data)
498
        result1 = current_data["00:00:00:00:00:00:00:01"]
499
        result2 = current_data["00:00:00:00:00:00:00:02"]
500
501
        assert result1[0][0]["dpid"] == "00:00:00:00:00:00:00:01"
502
        assert result1[0][0]["port"] == 1
503
        assert result1[0][0]["type"] == "starting"
504
        assert result1[0][0]["vlan"] == 100
505
506
        assert result2[0][0]["dpid"] == "00:00:00:00:00:00:00:02"
507
        assert result2[0][0]["port"] == 1
508
        assert result2[0][0]["type"] == "starting"
509
        assert result2[0][0]["vlan"] == 100
510
511
    @patch("napps.amlight.sdntrace_cp.utils.get_stored_flows")
512
    @patch("napps.amlight.sdntrace_cp.utils.requests")