Code Duplication    Length = 25-27 lines in 3 locations

tests/unit/test_main.py 3 locations

@@ 271-297 (lines=27) @@
268
        self.napp.check_switch_consistency(switch)
269
        mock_install_flows.assert_called()
270
271
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
272
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
273
    def test_check_switch_consistency_delete(self, *args):
274
        """Test check_switch_consistency method.
275
276
        This test checks the case when a flow is missing in switch and have the
277
        DELETE command.
278
        """
279
        (mock_flow_factory, mock_install_flows) = args
280
        dpid = "00:00:00:00:00:00:00:01"
281
        switch = get_switch_mock(dpid, 0x04)
282
283
        flow_1 = MagicMock()
284
        flow_1.as_dict.return_value = {'flow_1': 'data'}
285
286
        flow_list = [{"command": "delete",
287
                      "flow": {'flow_1': 'data'}
288
                      }]
289
        serializer = MagicMock()
290
        serializer.from_dict.return_value = flow_1
291
292
        switch.flows = [flow_1]
293
294
        mock_flow_factory.return_value = serializer
295
        self.napp.stored_flows = {dpid: {"flow_list": flow_list}}
296
        self.napp.check_switch_consistency(switch)
297
        mock_install_flows.assert_called()
298
299
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
300
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
@@ 299-323 (lines=25) @@
296
        self.napp.check_switch_consistency(switch)
297
        mock_install_flows.assert_called()
298
299
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
300
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
301
    def test_check_storehouse_consistency(self, *args):
302
        """Test check_storehouse_consistency method.
303
304
        This test checks the case when a flow is missing in storehouse.
305
        """
306
        (mock_flow_factory, mock_install_flows) = args
307
        dpid = "00:00:00:00:00:00:00:01"
308
        switch = get_switch_mock(dpid, 0x04)
309
310
        flow_1 = MagicMock()
311
        flow_1.as_dict.return_value = {'flow_1': 'data'}
312
313
        switch.flows = [flow_1]
314
315
        flow_list = [{"command": "add",
316
                      "flow": {'flow_2': 'data'}
317
                      }]
318
        serializer = MagicMock()
319
320
        mock_flow_factory.return_value = serializer
321
        self.napp.stored_flows = {dpid: {"flow_list": flow_list}}
322
        self.napp.check_storehouse_consistency(switch)
323
        mock_install_flows.assert_called()
324
@@ 245-269 (lines=25) @@
242
        self.napp._store_changed_flows(command, flows, switch)
243
        mock_save_flow.assert_called()
244
245
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
246
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
247
    def test_check_switch_consistency_add(self, *args):
248
        """Test check_switch_consistency method.
249
250
        This test checks the case when a flow is missing in switch and have the
251
        ADD command.
252
        """
253
        (mock_flow_factory, mock_install_flows) = args
254
        dpid = "00:00:00:00:00:00:00:01"
255
        switch = get_switch_mock(dpid, 0x04)
256
        switch.flows = []
257
258
        flow_1 = MagicMock()
259
        flow_1.as_dict.return_value = {'flow_1': 'data'}
260
261
        flow_list = [{"command": "add",
262
                      "flow": {'flow_1': 'data'}
263
                      }]
264
        serializer = MagicMock()
265
266
        mock_flow_factory.return_value = serializer
267
        self.napp.stored_flows = {dpid: {"flow_list": flow_list}}
268
        self.napp.check_switch_consistency(switch)
269
        mock_install_flows.assert_called()
270
271
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
272
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')