Code Duplication    Length = 27-27 lines in 3 locations

tests/unit/test_main.py 3 locations

@@ 286-312 (lines=27) @@
283
        self.napp.consistency_of_flows_in_switch(switch)
284
        mock_install_flows.assert_called()
285
286
    @patch('napps.kytos.flow_manager.main.Main')
287
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
288
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
289
    def test_consistency_flow_is_missing_in_storehouse(self, *args):
290
        """Test consistency_of_flows_in_switch method.
291
292
        This test checks the case when a flow is missing in storehouse.
293
        """
294
        (mock_flow_factory, mock_install_flows, mock_main) = 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
        switch.flows = [flow_1]
302
303
        flow_list = [{"command": "add",
304
                      "flow": {'flow_2': 'data'}
305
                      }]
306
        serializer = MagicMock()
307
308
        mock_flow_factory.return_value = serializer
309
        self.napp.stored_flows = {dpid: {"flow_list": flow_list}}
310
        mock_main._is_flow_in_list.return_value = False
311
        self.napp.consistency_of_flows_in_storehouse(switch)
312
        mock_install_flows.assert_called()
313
@@ 258-284 (lines=27) @@
255
        self.napp.consistency_of_flows_in_switch(switch)
256
        mock_install_flows.assert_called()
257
258
    @patch('napps.kytos.flow_manager.main.Main._is_flow_in_list')
259
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
260
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
261
    def test_consistency_flow_is_missing_in_switch_delete(self, *args):
262
        """Test consistency_of_flows_in_switch method.
263
264
        This test checks the case when a flow is missing in switch and have the
265
        DELETE command.
266
        """
267
        (mock_flow_factory, mock_install_flows, mock_is_flow_in_list) = 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": "delete",
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
        mock_is_flow_in_list.return_value = True
283
        self.napp.consistency_of_flows_in_switch(switch)
284
        mock_install_flows.assert_called()
285
286
    @patch('napps.kytos.flow_manager.main.Main')
287
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
@@ 230-256 (lines=27) @@
227
        self.napp._store_changed_flows(command, flows, switch)
228
        mock_save_flow.assert_called()
229
230
    @patch('napps.kytos.flow_manager.main.Main._is_flow_in_list')
231
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
232
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
233
    def test_consistency_flow_is_missing_in_switch_add(self, *args):
234
        """Test consistency_of_flows_in_switch method.
235
236
        This test checks the case when a flow is missing in switch and have the
237
        ADD command.
238
        """
239
        (mock_flow_factory, mock_install_flows, mock_is_flow_in_list) = args
240
        dpid = "00:00:00:00:00:00:00:01"
241
        switch = get_switch_mock(dpid, 0x04)
242
        switch.flows = []
243
244
        flow_1 = MagicMock()
245
        flow_1.as_dict.return_value = {'flow_1': 'data'}
246
247
        flow_list = [{"command": "add",
248
                      "flow": {'flow_1': 'data'}
249
                      }]
250
        serializer = MagicMock()
251
252
        mock_flow_factory.return_value = serializer
253
        self.napp.stored_flows = {dpid: {"flow_list": flow_list}}
254
        mock_is_flow_in_list.return_value = False
255
        self.napp.consistency_of_flows_in_switch(switch)
256
        mock_install_flows.assert_called()
257
258
    @patch('napps.kytos.flow_manager.main.Main._is_flow_in_list')
259
    @patch('napps.kytos.flow_manager.main.Main._install_flows')