Code Duplication    Length = 25-27 lines in 3 locations

tests/unit/test_main.py 3 locations

@@ 312-338 (lines=27) @@
309
        self.napp.check_switch_consistency(switch)
310
        mock_install_flows.assert_called()
311
312
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
313
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
314
    def test_check_switch_consistency_delete(self, *args):
315
        """Test check_switch_consistency method.
316
317
        This test checks the case when a flow is missing in switch and have the
318
        DELETE command.
319
        """
320
        (mock_flow_factory, mock_install_flows) = args
321
        dpid = "00:00:00:00:00:00:00:01"
322
        switch = get_switch_mock(dpid, 0x04)
323
324
        flow_1 = MagicMock()
325
        flow_1.as_dict.return_value = {'flow_1': 'data'}
326
327
        flow_list = [{"command": "delete",
328
                      "flow": {'flow_1': 'data'}
329
                      }]
330
        serializer = MagicMock()
331
        serializer.from_dict.return_value = flow_1
332
333
        switch.flows = [flow_1]
334
335
        mock_flow_factory.return_value = serializer
336
        self.napp.stored_flows = {dpid: {"flow_list": flow_list}}
337
        self.napp.check_switch_consistency(switch)
338
        mock_install_flows.assert_called()
339
340
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
341
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
@@ 340-364 (lines=25) @@
337
        self.napp.check_switch_consistency(switch)
338
        mock_install_flows.assert_called()
339
340
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
341
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
342
    def test_check_storehouse_consistency(self, *args):
343
        """Test check_storehouse_consistency method.
344
345
        This test checks the case when a flow is missing in storehouse.
346
        """
347
        (mock_flow_factory, mock_install_flows) = args
348
        dpid = "00:00:00:00:00:00:00:01"
349
        switch = get_switch_mock(dpid, 0x04)
350
351
        flow_1 = MagicMock()
352
        flow_1.as_dict.return_value = {'flow_1': 'data'}
353
354
        switch.flows = [flow_1]
355
356
        flow_list = [{"command": "add",
357
                      "flow": {'flow_2': 'data'}
358
                      }]
359
        serializer = MagicMock()
360
361
        mock_flow_factory.return_value = serializer
362
        self.napp.stored_flows = {dpid: {"flow_list": flow_list}}
363
        self.napp.check_storehouse_consistency(switch)
364
        mock_install_flows.assert_called()
365
366
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
367
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
@@ 286-310 (lines=25) @@
283
        self.napp._store_changed_flows(command, flows, switch)
284
        mock_save_flow.assert_called()
285
286
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
287
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
288
    def test_check_switch_consistency_add(self, *args):
289
        """Test check_switch_consistency method.
290
291
        This test checks the case when a flow is missing in switch and have the
292
        ADD command.
293
        """
294
        (mock_flow_factory, mock_install_flows) = args
295
        dpid = "00:00:00:00:00:00:00:01"
296
        switch = get_switch_mock(dpid, 0x04)
297
        switch.flows = []
298
299
        flow_1 = MagicMock()
300
        flow_1.as_dict.return_value = {'flow_1': 'data'}
301
302
        flow_list = [{"command": "add",
303
                      "flow": {'flow_1': 'data'}
304
                      }]
305
        serializer = MagicMock()
306
307
        mock_flow_factory.return_value = serializer
308
        self.napp.stored_flows = {dpid: {"flow_list": flow_list}}
309
        self.napp.check_switch_consistency(switch)
310
        mock_install_flows.assert_called()
311
312
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
313
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')