Code Duplication    Length = 25-27 lines in 3 locations

tests/unit/test_main.py 3 locations

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