Code Duplication    Length = 26-28 lines in 2 locations

tests/unit/test_main.py 2 locations

@@ 342-369 (lines=28) @@
339
        self.napp.check_storehouse_consistency(switch)
340
        mock_install_flows.assert_called()
341
342
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
343
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
344
    def test_consistency_cookie_exception_range(self, *args):
345
        """Test the consistency `cookie` exception range."""
346
        (mock_flow_factory, mock_install_flows) = args
347
        dpid = "00:00:00:00:00:00:00:01"
348
        switch = get_switch_mock(dpid, 0x04)
349
        cookie_exception_interval = [(0x2b00000000000011,
350
                                      0x2b000000000000ff), 0x2b00000000000100]
351
        self.napp.cookie_exception_range = cookie_exception_interval
352
        flow = MagicMock()
353
        expected = [
354
                    {'cookie': 0x2b00000000000010, 'called': 1},
355
                    {'cookie': 0x2b00000000000013, 'called': 0},
356
                    {'cookie': 0x2b00000000000100, 'called': 0},
357
                    {'cookie': 0x2b00000000000101, 'called': 1}]
358
        # ignored flow
359
        for i in expected:
360
            mock_install_flows.call_count = 0
361
            cookie = i['cookie']
362
            called = i['called']
363
            flow.cookie = cookie
364
            flow.as_dict.return_value = {'flow_1': 'data', 'cookie': cookie}
365
            switch.flows = [flow]
366
            mock_flow_factory.return_value = flow
367
            self.napp.stored_flows = {dpid: {"flow_list": flow}}
368
            self.napp.check_storehouse_consistency(switch)
369
            self.assertEqual(mock_install_flows.call_count, called)
370
371
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
372
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
@@ 371-396 (lines=26) @@
368
            self.napp.check_storehouse_consistency(switch)
369
            self.assertEqual(mock_install_flows.call_count, called)
370
371
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
372
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
373
    def test_consistency_table_id_exception_range(self, *args):
374
        """Test the consistency `table_id` exception range."""
375
        (mock_flow_factory, mock_install_flows) = args
376
        dpid = "00:00:00:00:00:00:00:01"
377
        switch = get_switch_mock(dpid, 0x04)
378
        table_id_exception_interval = [(1, 2), 3]
379
        self.napp.tab_id_exception_range = table_id_exception_interval
380
        flow = MagicMock()
381
        expected = [
382
                    {'table_id': 0, 'called': 1},
383
                    {'table_id': 3, 'called': 0},
384
                    {'table_id': 4, 'called': 1}]
385
        # ignored flow
386
        for i in expected:
387
            table_id = i['table_id']
388
            called = i['called']
389
            mock_install_flows.call_count = 0
390
            flow.table_id = table_id
391
            flow.as_dict.return_value = {'flow_1': 'data', 'cookie': table_id}
392
            switch.flows = [flow]
393
            mock_flow_factory.return_value = flow
394
            self.napp.stored_flows = {dpid: {"flow_list": flow}}
395
            self.napp.check_storehouse_consistency(switch)
396
            self.assertEqual(mock_install_flows.call_count, called)
397