Code Duplication    Length = 26-27 lines in 3 locations

tests/unit/test_main.py 3 locations

@@ 413-439 (lines=27) @@
410
        self.napp.check_switch_consistency(switch)
411
        mock_install_flows.assert_called()
412
413
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
414
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
415
    def test_check_storehouse_consistency(self, *args):
416
        """Test check_storehouse_consistency method.
417
418
        This test checks the case when a flow is missing in storehouse.
419
        """
420
        (mock_flow_factory, mock_install_flows) = args
421
        cookie_exception_interval = [(0x2b00000000000011, 0x2b000000000000ff)]
422
        self.napp.cookie_exception_range = cookie_exception_interval
423
        dpid = "00:00:00:00:00:00:00:01"
424
        switch = get_switch_mock(dpid, 0x04)
425
        flow_1 = MagicMock()
426
        flow_1.cookie = 0x2b00000000000010
427
        flow_1.as_dict.return_value = {'flow_1': 'data', 'cookie': 1}
428
429
        switch.flows = [flow_1]
430
431
        flow_list = [{"command": "add",
432
                      "flow": {'flow_2': 'data', 'cookie': 1}
433
                      }]
434
        serializer = flow_1
435
436
        mock_flow_factory.return_value = serializer
437
        self.napp.stored_flows = {dpid: {"flow_list": flow_list}}
438
        self.napp.check_storehouse_consistency(switch)
439
        mock_install_flows.assert_called()
440
441
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
442
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
@@ 385-411 (lines=27) @@
382
        self.napp.check_switch_consistency(switch)
383
        mock_install_flows.assert_called()
384
385
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
386
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
387
    def test_check_switch_consistency_delete(self, *args):
388
        """Test check_switch_consistency method.
389
390
        This test checks the case when a flow is missing in switch and have the
391
        DELETE command.
392
        """
393
        (mock_flow_factory, mock_install_flows) = args
394
        dpid = "00:00:00:00:00:00:00:01"
395
        switch = get_switch_mock(dpid, 0x04)
396
397
        flow_1 = MagicMock()
398
        flow_1.as_dict.return_value = {'flow_1': 'data'}
399
400
        flow_list = [{"command": "delete",
401
                      "flow": {'flow_1': 'data'}
402
                      }]
403
        serializer = MagicMock()
404
        serializer.from_dict.return_value = flow_1
405
406
        switch.flows = [flow_1]
407
408
        mock_flow_factory.return_value = serializer
409
        self.napp.stored_flows = {dpid: {"flow_list": flow_list}}
410
        self.napp.check_switch_consistency(switch)
411
        mock_install_flows.assert_called()
412
413
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
414
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
@@ 358-383 (lines=26) @@
355
        self.napp._store_changed_flows(command, flows, switch)
356
        mock_save_flow.assert_called()
357
358
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
359
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
360
    def test_check_switch_consistency_add(self, *args):
361
        """Test check_switch_consistency method.
362
363
        This test checks the case when a flow is missing in switch and have the
364
        ADD command.
365
        """
366
        (mock_flow_factory, mock_install_flows) = args
367
        dpid = "00:00:00:00:00:00:00:01"
368
        switch = get_switch_mock(dpid, 0x04)
369
        switch.flows = []
370
371
        flow_1 = MagicMock()
372
        flow_1.as_dict.return_value = {'flow_1': 'data'}
373
374
        flow_list = [{"command": "add",
375
                      "flow": {'flow_1': 'data'}
376
                      }]
377
        serializer = MagicMock()
378
        serializer.flow.cookie.return_value = 0
379
380
        mock_flow_factory.return_value = serializer
381
        self.napp.stored_flows = {dpid: {"flow_list": flow_list}}
382
        self.napp.check_switch_consistency(switch)
383
        mock_install_flows.assert_called()
384
385
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
386
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')