Code Duplication    Length = 25-27 lines in 3 locations

tests/unit/test_main.py 3 locations

@@ 369-395 (lines=27) @@
366
        self.napp.check_switch_consistency(switch)
367
        mock_install_flows.assert_called()
368
369
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
370
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
371
    def test_check_switch_consistency_delete(self, *args):
372
        """Test check_switch_consistency method.
373
374
        This test checks the case when a flow is missing in switch and have the
375
        DELETE command.
376
        """
377
        (mock_flow_factory, mock_install_flows) = args
378
        dpid = "00:00:00:00:00:00:00:01"
379
        switch = get_switch_mock(dpid, 0x04)
380
381
        flow_1 = MagicMock()
382
        flow_1.as_dict.return_value = {'flow_1': 'data'}
383
384
        flow_list = [{"command": "delete",
385
                      "flow": {'flow_1': 'data'}
386
                      }]
387
        serializer = MagicMock()
388
        serializer.from_dict.return_value = flow_1
389
390
        switch.flows = [flow_1]
391
392
        mock_flow_factory.return_value = serializer
393
        self.napp.stored_flows = {dpid: {"flow_list": flow_list}}
394
        self.napp.check_switch_consistency(switch)
395
        mock_install_flows.assert_called()
396
397
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
398
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
@@ 397-421 (lines=25) @@
394
        self.napp.check_switch_consistency(switch)
395
        mock_install_flows.assert_called()
396
397
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
398
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
399
    def test_check_storehouse_consistency(self, *args):
400
        """Test check_storehouse_consistency method.
401
402
        This test checks the case when a flow is missing in storehouse.
403
        """
404
        (mock_flow_factory, mock_install_flows) = args
405
        dpid = "00:00:00:00:00:00:00:01"
406
        switch = get_switch_mock(dpid, 0x04)
407
408
        flow_1 = MagicMock()
409
        flow_1.as_dict.return_value = {'flow_1': 'data'}
410
411
        switch.flows = [flow_1]
412
413
        flow_list = [{"command": "add",
414
                      "flow": {'flow_2': 'data'}
415
                      }]
416
        serializer = MagicMock()
417
418
        mock_flow_factory.return_value = serializer
419
        self.napp.stored_flows = {dpid: {"flow_list": flow_list}}
420
        self.napp.check_storehouse_consistency(switch)
421
        mock_install_flows.assert_called()
422
423
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
424
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
@@ 343-367 (lines=25) @@
340
        self.napp._store_changed_flows(command, flows, switch)
341
        mock_save_flow.assert_called()
342
343
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
344
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
345
    def test_check_switch_consistency_add(self, *args):
346
        """Test check_switch_consistency method.
347
348
        This test checks the case when a flow is missing in switch and have the
349
        ADD command.
350
        """
351
        (mock_flow_factory, mock_install_flows) = args
352
        dpid = "00:00:00:00:00:00:00:01"
353
        switch = get_switch_mock(dpid, 0x04)
354
        switch.flows = []
355
356
        flow_1 = MagicMock()
357
        flow_1.as_dict.return_value = {'flow_1': 'data'}
358
359
        flow_list = [{"command": "add",
360
                      "flow": {'flow_1': 'data'}
361
                      }]
362
        serializer = MagicMock()
363
364
        mock_flow_factory.return_value = serializer
365
        self.napp.stored_flows = {dpid: {"flow_list": flow_list}}
366
        self.napp.check_switch_consistency(switch)
367
        mock_install_flows.assert_called()
368
369
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
370
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')