Code Duplication    Length = 26-27 lines in 3 locations

tests/unit/test_main.py 3 locations

@@ 314-340 (lines=27) @@
311
        self.napp.check_switch_consistency(switch)
312
        mock_install_flows.assert_called()
313
314
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
315
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
316
    def test_check_storehouse_consistency(self, *args):
317
        """Test check_storehouse_consistency method.
318
319
        This test checks the case when a flow is missing in storehouse.
320
        """
321
        (mock_flow_factory, mock_install_flows) = args
322
        cookie_exception_interval = [(0x2b00000000000011, 0x2b000000000000ff)]
323
        self.napp.cookie_exception_range = cookie_exception_interval
324
        dpid = "00:00:00:00:00:00:00:01"
325
        switch = get_switch_mock(dpid, 0x04)
326
        flow_1 = MagicMock()
327
        flow_1.cookie = 0x2b00000000000010
328
        flow_1.as_dict.return_value = {'flow_1': 'data', 'cookie': 1}
329
330
        switch.flows = [flow_1]
331
332
        flow_list = [{"command": "add",
333
                      "flow": {'flow_2': 'data', 'cookie': 1}
334
                      }]
335
        serializer = flow_1
336
337
        mock_flow_factory.return_value = serializer
338
        self.napp.stored_flows = {dpid: {"flow_list": flow_list}}
339
        self.napp.check_storehouse_consistency(switch)
340
        mock_install_flows.assert_called()
341
342
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
343
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
@@ 286-312 (lines=27) @@
283
        self.napp.check_switch_consistency(switch)
284
        mock_install_flows.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_delete(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
        DELETE 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
298
        flow_1 = MagicMock()
299
        flow_1.as_dict.return_value = {'flow_1': 'data'}
300
301
        flow_list = [{"command": "delete",
302
                      "flow": {'flow_1': 'data'}
303
                      }]
304
        serializer = MagicMock()
305
        serializer.from_dict.return_value = flow_1
306
307
        switch.flows = [flow_1]
308
309
        mock_flow_factory.return_value = serializer
310
        self.napp.stored_flows = {dpid: {"flow_list": flow_list}}
311
        self.napp.check_switch_consistency(switch)
312
        mock_install_flows.assert_called()
313
314
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
315
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
@@ 259-284 (lines=26) @@
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
        serializer.flow.cookie.return_value = 0
280
281
        mock_flow_factory.return_value = serializer
282
        self.napp.stored_flows = {dpid: {"flow_list": flow_list}}
283
        self.napp.check_switch_consistency(switch)
284
        mock_install_flows.assert_called()
285
286
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
287
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')