Code Duplication    Length = 25-27 lines in 3 locations

tests/unit/test_main.py 3 locations

@@ 331-357 (lines=27) @@
328
        self.napp.check_switch_consistency(switch)
329
        mock_install_flows.assert_called()
330
331
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
332
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
333
    def test_check_switch_consistency_delete(self, *args):
334
        """Test check_switch_consistency method.
335
336
        This test checks the case when a flow is missing in switch and have the
337
        DELETE command.
338
        """
339
        (mock_flow_factory, mock_install_flows) = args
340
        dpid = "00:00:00:00:00:00:00:01"
341
        switch = get_switch_mock(dpid, 0x04)
342
343
        flow_1 = MagicMock()
344
        flow_1.as_dict.return_value = {'flow_1': 'data'}
345
346
        flow_list = [{"command": "delete",
347
                      "flow": {'flow_1': 'data'}
348
                      }]
349
        serializer = MagicMock()
350
        serializer.from_dict.return_value = flow_1
351
352
        switch.flows = [flow_1]
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')
@@ 359-383 (lines=25) @@
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_storehouse_consistency(self, *args):
362
        """Test check_storehouse_consistency method.
363
364
        This test checks the case when a flow is missing in storehouse.
365
        """
366
        (mock_flow_factory, mock_install_flows) = args
367
        dpid = "00:00:00:00:00:00:00:01"
368
        switch = get_switch_mock(dpid, 0x04)
369
370
        flow_1 = MagicMock()
371
        flow_1.as_dict.return_value = {'flow_1': 'data'}
372
373
        switch.flows = [flow_1]
374
375
        flow_list = [{"command": "add",
376
                      "flow": {'flow_2': 'data'}
377
                      }]
378
        serializer = MagicMock()
379
380
        mock_flow_factory.return_value = serializer
381
        self.napp.stored_flows = {dpid: {"flow_list": flow_list}}
382
        self.napp.check_storehouse_consistency(switch)
383
        mock_install_flows.assert_called()
384
385
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
386
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
@@ 305-329 (lines=25) @@
302
        self.napp._store_changed_flows(command, flows, switch)
303
        mock_save_flow.assert_called()
304
305
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
306
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
307
    def test_check_switch_consistency_add(self, *args):
308
        """Test check_switch_consistency method.
309
310
        This test checks the case when a flow is missing in switch and have the
311
        ADD command.
312
        """
313
        (mock_flow_factory, mock_install_flows) = args
314
        dpid = "00:00:00:00:00:00:00:01"
315
        switch = get_switch_mock(dpid, 0x04)
316
        switch.flows = []
317
318
        flow_1 = MagicMock()
319
        flow_1.as_dict.return_value = {'flow_1': 'data'}
320
321
        flow_list = [{"command": "add",
322
                      "flow": {'flow_1': 'data'}
323
                      }]
324
        serializer = MagicMock()
325
326
        mock_flow_factory.return_value = serializer
327
        self.napp.stored_flows = {dpid: {"flow_list": flow_list}}
328
        self.napp.check_switch_consistency(switch)
329
        mock_install_flows.assert_called()
330
331
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
332
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')