Code Duplication    Length = 25-27 lines in 3 locations

tests/unit/test_main.py 3 locations

@@ 343-369 (lines=27) @@
340
        self.napp.check_switch_consistency(switch)
341
        mock_install_flows.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_delete(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
        DELETE 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
355
        flow_1 = MagicMock()
356
        flow_1.as_dict.return_value = {'flow_1': 'data'}
357
358
        flow_list = [{"command": "delete",
359
                      "flow": {'flow_1': 'data'}
360
                      }]
361
        serializer = MagicMock()
362
        serializer.from_dict.return_value = flow_1
363
364
        switch.flows = [flow_1]
365
366
        mock_flow_factory.return_value = serializer
367
        self.napp.stored_flows = {dpid: {"flow_list": flow_list}}
368
        self.napp.check_switch_consistency(switch)
369
        mock_install_flows.assert_called()
370
371
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
372
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
@@ 371-395 (lines=25) @@
368
        self.napp.check_switch_consistency(switch)
369
        mock_install_flows.assert_called()
370
371
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
372
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
373
    def test_check_storehouse_consistency(self, *args):
374
        """Test check_storehouse_consistency method.
375
376
        This test checks the case when a flow is missing in storehouse.
377
        """
378
        (mock_flow_factory, mock_install_flows) = args
379
        dpid = "00:00:00:00:00:00:00:01"
380
        switch = get_switch_mock(dpid, 0x04)
381
382
        flow_1 = MagicMock()
383
        flow_1.as_dict.return_value = {'flow_1': 'data'}
384
385
        switch.flows = [flow_1]
386
387
        flow_list = [{"command": "add",
388
                      "flow": {'flow_2': 'data'}
389
                      }]
390
        serializer = MagicMock()
391
392
        mock_flow_factory.return_value = serializer
393
        self.napp.stored_flows = {dpid: {"flow_list": flow_list}}
394
        self.napp.check_storehouse_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')
@@ 317-341 (lines=25) @@
314
        self.napp._store_changed_flows(command, flows, switch)
315
        mock_save_flow.assert_called()
316
317
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
318
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
319
    def test_check_switch_consistency_add(self, *args):
320
        """Test check_switch_consistency method.
321
322
        This test checks the case when a flow is missing in switch and have the
323
        ADD command.
324
        """
325
        (mock_flow_factory, mock_install_flows) = args
326
        dpid = "00:00:00:00:00:00:00:01"
327
        switch = get_switch_mock(dpid, 0x04)
328
        switch.flows = []
329
330
        flow_1 = MagicMock()
331
        flow_1.as_dict.return_value = {'flow_1': 'data'}
332
333
        flow_list = [{"command": "add",
334
                      "flow": {'flow_1': 'data'}
335
                      }]
336
        serializer = MagicMock()
337
338
        mock_flow_factory.return_value = serializer
339
        self.napp.stored_flows = {dpid: {"flow_list": flow_list}}
340
        self.napp.check_switch_consistency(switch)
341
        mock_install_flows.assert_called()
342
343
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
344
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')