Code Duplication    Length = 61-63 lines in 2 locations

tests/unit/test_main.py 2 locations

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