Code Duplication    Length = 25-27 lines in 3 locations

tests/unit/test_main.py 3 locations

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