Code Duplication    Length = 41-42 lines in 2 locations

tests/unit/test_main.py 2 locations

@@ 2094-2135 (lines=42) @@
2091
            content={"1": "FailoverEvent1"}
2092
        )
2093
2094
    @patch("napps.kytos.mef_eline.main.emit_event")
2095
    @patch("napps.kytos.mef_eline.main.send_flow_mods_http")
2096
    def test_execute_swap_to_failover_exception(
2097
        self,
2098
        send_flow_mods_mock: MagicMock,
2099
        emit_main_mock: MagicMock,
2100
    ):
2101
        """Test handle_link_down method when an exception occurs."""
2102
        evc1 = MagicMock(id="1")
2103
        good_path = MagicMock(id="GoodPath")
2104
        bad_path = MagicMock(id="BadPath")
2105
        evc1.current_path = bad_path
2106
        evc1.failover_path = good_path
2107
        evc2 = MagicMock(id="2")
2108
2109
        self.napp.prepare_swap_to_failover_flow = {
2110
            evc1: {"1": ["Flow1"]},
2111
            evc2: None
2112
        }.get
2113
2114
        self.napp.prepare_swap_to_failover_event = {
2115
            evc1: "FailoverEvent1",
2116
        }.get
2117
2118
        send_flow_mods_mock.side_effect = FlowModException(
2119
            "Flowmod failed to send"
2120
        )
2121
2122
        success, failure = self.napp.execute_swap_to_failover([evc1, evc2])
2123
2124
        assert success == []
2125
        assert failure == [evc1, evc2]
2126
2127
        send_flow_mods_mock.assert_called_with(
2128
            {"1": ["Flow1"]},
2129
            "install"
2130
        )
2131
2132
        assert evc1.current_path == bad_path
2133
        assert evc1.failover_path == good_path
2134
2135
        emit_main_mock.assert_not_called()
2136
2137
    @patch("napps.kytos.mef_eline.main.emit_event")
2138
    @patch("napps.kytos.mef_eline.main.send_flow_mods_http")
@@ 2051-2091 (lines=41) @@
2048
            evc6.as_dict(),
2049
        ])
2050
2051
    @patch("napps.kytos.mef_eline.main.emit_event")
2052
    @patch("napps.kytos.mef_eline.main.send_flow_mods_http")
2053
    def test_execute_swap_to_failover(
2054
        self,
2055
        send_flow_mods_mock: MagicMock,
2056
        emit_main_mock: MagicMock,
2057
    ):
2058
        """Test execute_swap_to_failover method."""
2059
        evc1 = MagicMock(id="1")
2060
        good_path = MagicMock(id="GoodPath")
2061
        bad_path = MagicMock(id="BadPath")
2062
        evc1.current_path = bad_path
2063
        evc1.failover_path = good_path
2064
        evc2 = MagicMock(id="2")
2065
2066
        self.napp.prepare_swap_to_failover_flow = {
2067
            evc1: {"1": ["Flow1"]},
2068
            evc2: None
2069
        }.get
2070
2071
        self.napp.prepare_swap_to_failover_event = {
2072
            evc1: "FailoverEvent1",
2073
        }.get
2074
2075
        success, failure = self.napp.execute_swap_to_failover([evc1, evc2])
2076
2077
        assert success == [evc1]
2078
        assert failure == [evc2]
2079
2080
        send_flow_mods_mock.assert_called_with(
2081
            {"1": ["Flow1"]},
2082
            "install"
2083
        )
2084
2085
        assert evc1.current_path == good_path
2086
        assert evc1.failover_path == bad_path
2087
2088
        emit_main_mock.assert_called_with(
2089
            self.napp.controller,
2090
            "failover_link_down",
2091
            content={"1": "FailoverEvent1"}
2092
        )
2093
2094
    @patch("napps.kytos.mef_eline.main.emit_event")