Code Duplication    Length = 41-42 lines in 2 locations

tests/unit/test_main.py 2 locations

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