Code Duplication    Length = 41-42 lines in 2 locations

tests/unit/test_main.py 2 locations

@@ 1988-2029 (lines=42) @@
1985
            content={"1": "FailoverEvent1"}
1986
        )
1987
1988
    @patch("napps.kytos.mef_eline.main.emit_event")
1989
    @patch("napps.kytos.mef_eline.main.send_flow_mods_http")
1990
    def test_execute_swap_to_failover_exception(
1991
        self,
1992
        send_flow_mods_mock: MagicMock,
1993
        emit_main_mock: MagicMock,
1994
    ):
1995
        """Test handle_link_down method when an exception occurs."""
1996
        evc1 = MagicMock(id="1")
1997
        good_path = MagicMock(id="GoodPath")
1998
        bad_path = MagicMock(id="BadPath")
1999
        evc1.current_path = bad_path
2000
        evc1.failover_path = good_path
2001
        evc2 = MagicMock(id="2")
2002
2003
        self.napp.prepare_swap_to_failover_flow = {
2004
            evc1: {"1": ["Flow1"]},
2005
            evc2: None
2006
        }.get
2007
2008
        self.napp.prepare_swap_to_failover_event = {
2009
            evc1: "FailoverEvent1",
2010
        }.get
2011
2012
        send_flow_mods_mock.side_effect = FlowModException(
2013
            "Flowmod failed to send"
2014
        )
2015
2016
        success, failure = self.napp.execute_swap_to_failover([evc1, evc2])
2017
2018
        assert success == []
2019
        assert failure == [evc1, evc2]
2020
2021
        send_flow_mods_mock.assert_called_with(
2022
            {"1": ["Flow1"]},
2023
            "install"
2024
        )
2025
2026
        assert evc1.current_path == bad_path
2027
        assert evc1.failover_path == good_path
2028
2029
        emit_main_mock.assert_not_called()
2030
2031
    @patch("napps.kytos.mef_eline.main.emit_event")
2032
    @patch("napps.kytos.mef_eline.main.send_flow_mods_http")
@@ 1945-1985 (lines=41) @@
1942
            evc6.as_dict(),
1943
        ])
1944
1945
    @patch("napps.kytos.mef_eline.main.emit_event")
1946
    @patch("napps.kytos.mef_eline.main.send_flow_mods_http")
1947
    def test_execute_swap_to_failover(
1948
        self,
1949
        send_flow_mods_mock: MagicMock,
1950
        emit_main_mock: MagicMock,
1951
    ):
1952
        """Test execute_swap_to_failover method."""
1953
        evc1 = MagicMock(id="1")
1954
        good_path = MagicMock(id="GoodPath")
1955
        bad_path = MagicMock(id="BadPath")
1956
        evc1.current_path = bad_path
1957
        evc1.failover_path = good_path
1958
        evc2 = MagicMock(id="2")
1959
1960
        self.napp.prepare_swap_to_failover_flow = {
1961
            evc1: {"1": ["Flow1"]},
1962
            evc2: None
1963
        }.get
1964
1965
        self.napp.prepare_swap_to_failover_event = {
1966
            evc1: "FailoverEvent1",
1967
        }.get
1968
1969
        success, failure = self.napp.execute_swap_to_failover([evc1, evc2])
1970
1971
        assert success == [evc1]
1972
        assert failure == [evc2]
1973
1974
        send_flow_mods_mock.assert_called_with(
1975
            {"1": ["Flow1"]},
1976
            "install"
1977
        )
1978
1979
        assert evc1.current_path == good_path
1980
        assert evc1.failover_path == bad_path
1981
1982
        emit_main_mock.assert_called_with(
1983
            self.napp.controller,
1984
            "failover_link_down",
1985
            content={"1": "FailoverEvent1"}
1986
        )
1987
1988
    @patch("napps.kytos.mef_eline.main.emit_event")