Code Duplication    Length = 25-27 lines in 3 locations

tests/unit/test_main.py 3 locations

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