Code Duplication    Length = 25-27 lines in 3 locations

tests/unit/test_main.py 3 locations

@@ 285-311 (lines=27) @@
282
        self.napp.check_switch_consistency(switch)
283
        mock_install_flows.assert_called()
284
285
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
286
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
287
    def test_check_switch_consistency_delete(self, *args):
288
        """Test check_switch_consistency method.
289
290
        This test checks the case when a flow is missing in switch and have the
291
        DELETE command.
292
        """
293
        (mock_flow_factory, mock_install_flows) = args
294
        dpid = "00:00:00:00:00:00:00:01"
295
        switch = get_switch_mock(dpid, 0x04)
296
297
        flow_1 = MagicMock()
298
        flow_1.as_dict.return_value = {'flow_1': 'data'}
299
300
        flow_list = [{"command": "delete",
301
                      "flow": {'flow_1': 'data'}
302
                      }]
303
        serializer = MagicMock()
304
        serializer.from_dict.return_value = flow_1
305
306
        switch.flows = [flow_1]
307
308
        mock_flow_factory.return_value = serializer
309
        self.napp.stored_flows = {dpid: {"flow_list": flow_list}}
310
        self.napp.check_switch_consistency(switch)
311
        mock_install_flows.assert_called()
312
313
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
314
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
@@ 313-337 (lines=25) @@
310
        self.napp.check_switch_consistency(switch)
311
        mock_install_flows.assert_called()
312
313
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
314
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
315
    def test_check_storehouse_consistency(self, *args):
316
        """Test check_storehouse_consistency method.
317
318
        This test checks the case when a flow is missing in storehouse.
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
        switch.flows = [flow_1]
328
329
        flow_list = [{"command": "add",
330
                      "flow": {'flow_2': 'data'}
331
                      }]
332
        serializer = MagicMock()
333
334
        mock_flow_factory.return_value = serializer
335
        self.napp.stored_flows = {dpid: {"flow_list": flow_list}}
336
        self.napp.check_storehouse_consistency(switch)
337
        mock_install_flows.assert_called()
338
339
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
340
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
@@ 259-283 (lines=25) @@
256
        self.napp._store_changed_flows(command, flows, switch)
257
        mock_save_flow.assert_called()
258
259
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
260
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
261
    def test_check_switch_consistency_add(self, *args):
262
        """Test check_switch_consistency method.
263
264
        This test checks the case when a flow is missing in switch and have the
265
        ADD command.
266
        """
267
        (mock_flow_factory, mock_install_flows) = args
268
        dpid = "00:00:00:00:00:00:00:01"
269
        switch = get_switch_mock(dpid, 0x04)
270
        switch.flows = []
271
272
        flow_1 = MagicMock()
273
        flow_1.as_dict.return_value = {'flow_1': 'data'}
274
275
        flow_list = [{"command": "add",
276
                      "flow": {'flow_1': 'data'}
277
                      }]
278
        serializer = MagicMock()
279
280
        mock_flow_factory.return_value = serializer
281
        self.napp.stored_flows = {dpid: {"flow_list": flow_list}}
282
        self.napp.check_switch_consistency(switch)
283
        mock_install_flows.assert_called()
284
285
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
286
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')