Code Duplication    Length = 26-28 lines in 2 locations

tests/unit/test_main.py 2 locations

@@ 630-657 (lines=28) @@
627
        mock_save_flow.assert_called()
628
        self.assertEqual(len(self.napp.stored_flows[dpid]['flow_list']), 1)
629
630
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
631
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
632
    def test_consistency_cookie_ignored_range(self, *args):
633
        """Test the consistency `cookie` ignored range."""
634
        (mock_flow_factory, mock_install_flows) = args
635
        dpid = "00:00:00:00:00:00:00:01"
636
        switch = get_switch_mock(dpid, 0x04)
637
        cookie_ignored_interval = [(0x2b00000000000011,
638
                                    0x2b000000000000ff), 0x2b00000000000100]
639
        self.napp.cookie_ignored_range = cookie_ignored_interval
640
        flow = MagicMock()
641
        expected = [
642
                    {'cookie': 0x2b00000000000010, 'called': 1},
643
                    {'cookie': 0x2b00000000000013, 'called': 0},
644
                    {'cookie': 0x2b00000000000100, 'called': 0},
645
                    {'cookie': 0x2b00000000000101, 'called': 1}]
646
        # ignored flow
647
        for i in expected:
648
            mock_install_flows.call_count = 0
649
            cookie = i['cookie']
650
            called = i['called']
651
            flow.cookie = cookie
652
            flow.as_dict.return_value = {'flow_1': 'data', 'cookie': cookie}
653
            switch.flows = [flow]
654
            mock_flow_factory.return_value = flow
655
            self.napp.stored_flows = {dpid: {"flow_list": flow}}
656
            self.napp.check_storehouse_consistency(switch)
657
            self.assertEqual(mock_install_flows.call_count, called)
658
659
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
660
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
@@ 659-684 (lines=26) @@
656
            self.napp.check_storehouse_consistency(switch)
657
            self.assertEqual(mock_install_flows.call_count, called)
658
659
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
660
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
661
    def test_consistency_table_id_ignored_range(self, *args):
662
        """Test the consistency `table_id` ignored range."""
663
        (mock_flow_factory, mock_install_flows) = args
664
        dpid = "00:00:00:00:00:00:00:01"
665
        switch = get_switch_mock(dpid, 0x04)
666
        table_id_ignored_interval = [(1, 2), 3]
667
        self.napp.tab_id_ignored_range = table_id_ignored_interval
668
        flow = MagicMock()
669
        expected = [
670
                    {'table_id': 0, 'called': 1},
671
                    {'table_id': 3, 'called': 0},
672
                    {'table_id': 4, 'called': 1}]
673
        # ignored flow
674
        for i in expected:
675
            table_id = i['table_id']
676
            called = i['called']
677
            mock_install_flows.call_count = 0
678
            flow.table_id = table_id
679
            flow.as_dict.return_value = {'flow_1': 'data', 'cookie': table_id}
680
            switch.flows = [flow]
681
            mock_flow_factory.return_value = flow
682
            self.napp.stored_flows = {dpid: {"flow_list": flow}}
683
            self.napp.check_storehouse_consistency(switch)
684
            self.assertEqual(mock_install_flows.call_count, called)
685