Code Duplication    Length = 45-49 lines in 3 locations

tests/unit/test_automate.py 3 locations

@@ 265-313 (lines=49) @@
262
        mock_get_circuit.assert_called_once()
263
        self.assertFalse(result)
264
265
    @patch("napps.amlight.sdntrace_cp.automate.Automate.get_circuit")
266
    @patch("napps.amlight.sdntrace_cp.automate.Automate.find_circuits")
267
    def test_check_trace__wrong_steps(
268
        self, mock_find_circuits, mock_get_circuit
269
    ):
270
        """Verify _check_trace with circuit steps different
271
        from trace steps"""
272
        circuit_steps = [
273
            {
274
                "dpid": "00:00:00:00:00:00:00:01",
275
                "in_port": 3,
276
            },
277
            {
278
                "dpid": "00:00:00:00:00:00:00:02",
279
                "in_port": 3,
280
            },
281
        ]
282
        mock_get_circuit.return_value = circuit_steps
283
284
        trace = [
285
            {
286
                "dpid": "00:00:00:00:00:00:00:01",
287
                "port": 3,
288
            },
289
            {
290
                "dpid": "00:00:00:00:00:00:00:05",
291
                "port": 3,
292
            },
293
            {
294
                "dpid": "00:00:00:00:00:00:00:03",
295
                "port": 3,
296
            },
297
        ]
298
299
        circuit = {
300
            "dpid_a": "00:00:00:00:00:00:00:01",
301
            "port_a": 1,
302
            "dpid_z": "00:00:00:00:00:00:00:03",
303
            "port_z": 2,
304
        }
305
306
        tracer = MagicMock()
307
        automate = Automate(tracer)
308
        automate._circuits = []
309
        result = automate._check_trace(circuit, trace)
310
311
        mock_find_circuits.assert_called_once()
312
        mock_get_circuit.assert_called_once()
313
        self.assertFalse(result)
314
315
    @patch("napps.amlight.sdntrace_cp.automate.Automate.get_circuit")
316
    @patch("napps.amlight.sdntrace_cp.automate.Automate.find_circuits")
@@ 171-216 (lines=46) @@
168
169
        self.assertFalse(result)
170
171
    @patch("napps.amlight.sdntrace_cp.automate.Automate.get_circuit")
172
    @patch("napps.amlight.sdntrace_cp.automate.Automate.find_circuits")
173
    def test_check_trace(self, mock_find_circuits, mock_get_circuit):
174
        """Verify _check_trace with trace finding a valid circuit."""
175
        circuit_steps = [
176
            {
177
                "dpid": "00:00:00:00:00:00:00:01",
178
                "in_port": 3,
179
            },
180
            {
181
                "dpid": "00:00:00:00:00:00:00:02",
182
                "in_port": 3,
183
            },
184
        ]
185
        mock_get_circuit.return_value = circuit_steps
186
187
        trace = [
188
            {
189
                "dpid": "00:00:00:00:00:00:00:01",
190
                "port": 3,
191
            },
192
            {
193
                "dpid": "00:00:00:00:00:00:00:02",
194
                "port": 3,
195
            },
196
            {
197
                "dpid": "00:00:00:00:00:00:00:03",
198
                "port": 3,
199
            },
200
        ]
201
202
        circuit = {
203
            "dpid_a": "00:00:00:00:00:00:00:01",
204
            "port_a": 1,
205
            "dpid_z": "00:00:00:00:00:00:00:03",
206
            "port_z": 2,
207
        }
208
209
        tracer = MagicMock()
210
        automate = Automate(tracer)
211
        automate._circuits = []
212
        result = automate._check_trace(circuit, trace)
213
214
        mock_find_circuits.assert_called_once()
215
        mock_get_circuit.assert_called_once()
216
        self.assertTrue(result)
217
218
    # pylint: disable=duplicate-code
219
    @patch("napps.amlight.sdntrace_cp.automate.Automate.get_circuit")
@@ 219-263 (lines=45) @@
216
        self.assertTrue(result)
217
218
    # pylint: disable=duplicate-code
219
    @patch("napps.amlight.sdntrace_cp.automate.Automate.get_circuit")
220
    @patch("napps.amlight.sdntrace_cp.automate.Automate.find_circuits")
221
    def test_check_trace__short_trace(
222
        self, mock_find_circuits, mock_get_circuit
223
    ):
224
        """Verify _check_trace if lenght of circuit steps is different from
225
        lenght of trace steps"""
226
        circuit_steps = [
227
            {
228
                "dpid": "00:00:00:00:00:00:00:01",
229
                "in_port": 3,
230
            },
231
            {
232
                "dpid": "00:00:00:00:00:00:00:02",
233
                "in_port": 3,
234
            },
235
        ]
236
        mock_get_circuit.return_value = circuit_steps
237
238
        trace = [
239
            {
240
                "dpid": "00:00:00:00:00:00:00:01",
241
                "port": 3,
242
            },
243
            {
244
                "dpid": "00:00:00:00:00:00:00:03",
245
                "port": 3,
246
            },
247
        ]
248
249
        circuit = {
250
            "dpid_a": "00:00:00:00:00:00:00:01",
251
            "port_a": 1,
252
            "dpid_z": "00:00:00:00:00:00:00:03",
253
            "port_z": 2,
254
        }
255
256
        tracer = MagicMock()
257
        automate = Automate(tracer)
258
        automate._circuits = []
259
        result = automate._check_trace(circuit, trace)
260
261
        mock_find_circuits.assert_called_once()
262
        mock_get_circuit.assert_called_once()
263
        self.assertFalse(result)
264
265
    @patch("napps.amlight.sdntrace_cp.automate.Automate.get_circuit")
266
    @patch("napps.amlight.sdntrace_cp.automate.Automate.find_circuits")