Code Duplication    Length = 25-27 lines in 3 locations

tests/unit/test_main.py 3 locations

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