Passed
Pull Request — master (#140)
by Rogerio
03:51
created

TestMain.test_evc_from_dict()   A

Complexity

Conditions 1

Size

Total Lines 33
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 22
nop 3
dl 0
loc 33
rs 9.352
c 0
b 0
f 0
1
"""Module to test the main napp file."""
2
import json
3
from unittest import TestCase
4
from unittest.mock import patch
5
6
from napps.kytos.mef_eline.main import Main
7
from tests.helpers import get_controller_mock
8
9
10
class TestMain(TestCase):  # pylint: disable=too-many-public-methods
11
    """Test the Main class."""
12
13
    def setUp(self):
14
        """Execute steps before each tests.
15
16
        Set the server_name_url_url from kytos/mef_eline
17
        """
18
        self.server_name_url = 'http://localhost:8181/api/kytos/mef_eline'
19
        self.napp = Main(get_controller_mock())
20
21
    def test_get_event_listeners(self):
22
        """Verify all event listeners registered."""
23
        expected_events = ['kytos/core.shutdown',
24
                           'kytos/core.shutdown.kytos/mef_eline',
25
                           'kytos/topology.link_up',
26
                           'kytos/topology.link_down']
27
        actual_events = self.napp.listeners()
28
29
        for _event in expected_events:
30
            self.assertIn(_event, actual_events, '%s' % _event)
31
32
    def test_verify_api_urls(self):
33
        """Verify all APIs registered."""
34
        expected_urls = [
35
            ({}, {'POST', 'OPTIONS'},
36
             '/api/kytos/mef_eline/v2/evc/'),
37
38
            ({}, {'OPTIONS', 'HEAD', 'GET'},
39
             '/api/kytos/mef_eline/v2/evc/'),
40
41
            ({'circuit_id': '[circuit_id]'}, {'OPTIONS', 'DELETE'},
42
             '/api/kytos/mef_eline/v2/evc/<circuit_id>'),
43
44
            ({'circuit_id': '[circuit_id]'}, {'OPTIONS', 'HEAD', 'GET'},
45
             '/api/kytos/mef_eline/v2/evc/<circuit_id>'),
46
47
            ({'circuit_id': '[circuit_id]'}, {'OPTIONS', 'PATCH'},
48
             '/api/kytos/mef_eline/v2/evc/<circuit_id>'),
49
50
            ({}, {'OPTIONS', 'GET', 'HEAD'},
51
             '/api/kytos/mef_eline/v2/evc/schedule'),
52
53
            ({}, {'POST', 'OPTIONS'},
54
             '/api/kytos/mef_eline/v2/evc/schedule/'),
55
56
            ({'schedule_id': '[schedule_id]'},
57
             {'OPTIONS', 'DELETE'},
58
             '/api/kytos/mef_eline/v2/evc/schedule/<schedule_id>'),
59
60
            ({'schedule_id': '[schedule_id]'},
61
             {'OPTIONS', 'PATCH'},
62
             '/api/kytos/mef_eline/v2/evc/schedule/<schedule_id>')
63
            ]
64
65
        urls = self.get_napp_urls(self.napp)
66
        self.assertCountEqual(expected_urls, urls)
67
68
    @patch('napps.kytos.mef_eline.main.Main.uni_from_dict')
69
    @patch('napps.kytos.mef_eline.models.EVCBase._validate')
70
    def test_evc_from_dict(self, _validate_mock, uni_from_dict_mock):
71
        """
72
        Test the helper method that create an EVN from dict.
73
74
        Verify object creation with circuit data and schedule data.
75
        """
76
        _validate_mock.return_value = True
77
        uni_from_dict_mock.side_effect = ['uni_a', 'uni_z']
78
        payload = {
79
            "name": "my evc1",
80
            "uni_a": {
81
                "interface_id": "00:00:00:00:00:00:00:01:1",
82
                "tag": {
83
                    "tag_type": 1,
84
                    "value": 80
85
                }
86
            },
87
            "uni_z": {
88
                "interface_id": "00:00:00:00:00:00:00:02:2",
89
                "tag": {
90
                    "tag_type": 1,
91
                    "value": 1
92
                }
93
            },
94
            "circuit_scheduler": [{
95
                "frequency": "* * * * *",
96
                "action": "create"
97
            }]
98
        }
99
        evc_response = self.napp.evc_from_dict(payload)
100
        self.assertIsNotNone(evc_response)
101
102
    def test_list_without_circuits(self):
103
        """Test if list circuits return 'no circuit stored.'."""
104
        api = self.get_app_test_client(self.napp)
105
        url = f'{self.server_name_url}/v2/evc/'
106
        response = api.get(url)
107
        self.assertEqual(response.status_code, 200, response.data)
108
        self.assertEqual(json.loads(response.data.decode()), {})
109
110
    @patch('napps.kytos.mef_eline.storehouse.StoreHouse.get_data')
111
    def test_list_no_circuits_stored(self, storehouse_data_mock):
112
        """Test if list circuits return all circuits stored."""
113
        circuits = {}
114
        storehouse_data_mock.return_value = circuits
115
116
        api = self.get_app_test_client(self.napp)
117
        url = f'{self.server_name_url}/v2/evc/'
118
119
        response = api.get(url)
120
        expected_result = circuits
121
        self.assertEqual(json.loads(response.data), expected_result)
122
123
    @patch('napps.kytos.mef_eline.storehouse.StoreHouse.get_data')
124
    def test_list_with_circuits_stored(self, storehouse_data_mock):
125
        """Test if list circuits return all circuits stored."""
126
        circuits = {'1': {'name': 'circuit_1'},
127
                    '2': {'name': 'circuit_2'}}
128
        storehouse_data_mock.return_value = circuits
129
130
        api = self.get_app_test_client(self.napp)
131
        url = f'{self.server_name_url}/v2/evc/'
132
133
        response = api.get(url)
134
        expected_result = circuits
135
        self.assertEqual(json.loads(response.data), expected_result)
136
137 View Code Duplication
    @patch('napps.kytos.mef_eline.storehouse.StoreHouse.get_data')
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
138
    def test_circuit_with_valid_id(self, storehouse_data_mock):
139
        """Test if get_circuit return the circuit attributes."""
140
        circuits = {'1': {'name': 'circuit_1'},
141
                    '2': {'name': 'circuit_2'}}
142
        storehouse_data_mock.return_value = circuits
143
144
        api = self.get_app_test_client(self.napp)
145
        url = f'{self.server_name_url}/v2/evc/1'
146
        response = api.get(url)
147
        expected_result = circuits['1']
148
        self.assertEqual(json.loads(response.data), expected_result)
149
150 View Code Duplication
    @patch('napps.kytos.mef_eline.storehouse.StoreHouse.get_data')
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
151
    def test_circuit_with_invalid_id(self, storehouse_data_mock):
152
        """Test if get_circuit return invalid circuit_id."""
153
        circuits = {'1': {'name': 'circuit_1'},
154
                    '2': {'name': 'circuit_2'}}
155
        storehouse_data_mock.return_value = circuits
156
157
        api = self.get_app_test_client(self.napp)
158
        url = f'{self.server_name_url}/v2/evc/3'
159
        response = api.get(url)
160
        expected_result = {'response': 'circuit_id 3 not found'}
161
        self.assertEqual(json.loads(response.data), expected_result)
162
163
    @patch('napps.kytos.mef_eline.storehouse.StoreHouse.get_data')
164
    @patch('napps.kytos.mef_eline.scheduler.Scheduler.add')
165
    @patch('napps.kytos.mef_eline.main.Main.uni_from_dict')
166
    @patch('napps.kytos.mef_eline.storehouse.StoreHouse.save_evc')
167
    @patch('napps.kytos.mef_eline.main.EVC.as_dict')
168
    @patch('napps.kytos.mef_eline.models.EVC._validate')
169
    def test_create_a_circuit_case_1(self, *args):
170
        """Test create a new circuit."""
171
        (validate_mock, evc_as_dict_mock, save_evc_mock,
172
         uni_from_dict_mock, sched_add_mock, storehouse_data_mock) = args
173
174
        validate_mock.return_value = True
175
        save_evc_mock.return_value = True
176
        uni_from_dict_mock.side_effect = ['uni_a', 'uni_z']
177
        evc_as_dict_mock.return_value = {}
178
        sched_add_mock.return_value = True
179
        storehouse_data_mock.return_value = {}
180
181
        api = self.get_app_test_client(self.napp)
182
        url = f'{self.server_name_url}/v2/evc/'
183
        payload = {
184
                   "name": "my evc1",
185
                   "frequency": "* * * * *",
186
                   "uni_a": {
187
                     "interface_id": "00:00:00:00:00:00:00:01:1",
188
                     "tag": {
189
                       "tag_type": 1,
190
                       "value": 80
191
                     }
192
                   },
193
                   "uni_z": {
194
                     "interface_id": "00:00:00:00:00:00:00:02:2",
195
                     "tag": {
196
                       "tag_type": 1,
197
                       "value": 1
198
                     }
199
                   }
200
                 }
201
202
        response = api.post(url, data=json.dumps(payload),
203
                            content_type='application/json')
204
        current_data = json.loads(response.data)
205
206
        # verify expected result from request
207
        self.assertEqual(201, response.status_code, response.data)
208
        self.assertIn('circuit_id', current_data)
209
210
        # verify uni called
211
        uni_from_dict_mock.called_twice()
212
        uni_from_dict_mock.assert_any_call(payload['uni_z'])
213
        uni_from_dict_mock.assert_any_call(payload['uni_a'])
214
215
        # verify validation called
216
        validate_mock.assert_called_once()
217
        validate_mock.assert_called_with(frequency='* * * * *',
218
                                         name='my evc1',
219
                                         uni_a='uni_a',
220
                                         uni_z='uni_z')
221
        # verify save method is called
222
        save_evc_mock.assert_called_once()
223
224
        # verify evc as dict is called to save in the box
225
        evc_as_dict_mock.assert_called_once()
226
        # verify add circuit in sched
227
        sched_add_mock.assert_called_once()
228
229
    @staticmethod
230
    def get_napp_urls(napp):
231
        """Return the kytos/mef_eline urls.
232
233
        The urls will be like:
234
235
        urls = [
236
            (options, methods, url)
237
        ]
238
239
        """
240
        controller = napp.controller
241
        controller.api_server.register_napp_endpoints(napp)
242
243
        urls = []
244
        for rule in controller.api_server.app.url_map.iter_rules():
245
            options = {}
246
            for arg in rule.arguments:
247
                options[arg] = "[{0}]".format(arg)
248
249
            if f'{napp.username}/{napp.name}' in str(rule):
250
                urls.append((options, rule.methods, f'{str(rule)}'))
251
252
        return urls
253
254
    @staticmethod
255
    def get_app_test_client(napp):
256
        """Return a flask api test client."""
257
        napp.controller.api_server.register_napp_endpoints(napp)
258
        return napp.controller.api_server.app.test_client()
259
260
    def test_create_a_circuit_case_2(self):
261
        """Test create a new circuit trying to send request without a json."""
262
        api = self.get_app_test_client(self.napp)
263
        url = f'{self.server_name_url}/v2/evc/'
264
265
        response = api.post(url)
266
        current_data = json.loads(response.data)
267
        expected_data = 'Bad request: The request do not have a json.'
268
269
        self.assertEqual(400, response.status_code, response.data)
270
        self.assertEqual(current_data, expected_data)
271
272
    @patch('napps.kytos.mef_eline.scheduler.Scheduler.add')
273
    @patch('napps.kytos.mef_eline.main.Main.uni_from_dict')
274
    @patch('napps.kytos.mef_eline.storehouse.StoreHouse.save_evc')
275
    @patch('napps.kytos.mef_eline.models.EVC._validate')
276
    @patch('napps.kytos.mef_eline.main.EVC.as_dict')
277
    def test_create_circuit_already_enabled(self, *args):
278
        """Test create an already created circuit."""
279
        (evc_as_dict_mock, validate_mock, save_evc_mock,
280
         uni_from_dict_mock, sched_add_mock) = args
281
282
        validate_mock.return_value = True
283
        save_evc_mock.return_value = True
284
        sched_add_mock.return_value = True
285
        uni_from_dict_mock.side_effect = ['uni_a', 'uni_z', 'uni_a', 'uni_z']
286
        payload1 = {'name': 'circuit_1'}
287
288
        api = self.get_app_test_client(self.napp)
289
        payload2 = {
290
            "name": "my evc1",
291
            "uni_a": {
292
                "interface_id": "00:00:00:00:00:00:00:01:1",
293
                "tag": {
294
                    "tag_type": 1,
295
                    "value": 80
296
                }
297
            },
298
            "uni_z": {
299
                "interface_id": "00:00:00:00:00:00:00:02:2",
300
                "tag": {
301
                    "tag_type": 1,
302
                    "value": 1
303
                }
304
            }
305
        }
306
307
        evc_as_dict_mock.return_value = payload1
308
        response = api.post(f'{self.server_name_url}/v2/evc/',
309
                            data=json.dumps(payload1),
310
                            content_type='application/json')
311
        self.assertEqual(201, response.status_code)
312
313
        evc_as_dict_mock.return_value = payload2
314
        response = api.post(f'{self.server_name_url}/v2/evc/',
315
                            data=json.dumps(payload2),
316
                            content_type='application/json')
317
        self.assertEqual(201, response.status_code)
318
319
        response = api.post(f'{self.server_name_url}/v2/evc/',
320
                            data=json.dumps(payload2),
321
                            content_type='application/json')
322
        current_data = json.loads(response.data)
323
        expected_data = 'Not Acceptable: This evc already exists.'
324
        self.assertEqual(current_data, expected_data)
325
        self.assertEqual(409, response.status_code)
326
327
    def test_list_schedules__no_data(self):
328
        """Test list of schedules."""
329
        api = self.get_app_test_client(self.napp)
330
        url = f'{self.server_name_url}/v2/evc/schedule'
331
        response = api.get(url)
332
        self.assertEqual(response.status_code, 200, response.data)
333
        self.assertEqual(json.loads(response.data.decode()), {})
334
335
    @patch('napps.kytos.mef_eline.storehouse.StoreHouse.get_data')
336
    def test_list_schedules__no_data_stored(self, storehouse_data_mock):
337
        """Test if list circuits return all circuits stored."""
338
        circuits = {}
339
        storehouse_data_mock.return_value = circuits
340
341
        api = self.get_app_test_client(self.napp)
342
        url = f'{self.server_name_url}/v2/evc/schedule'
343
344
        response = api.get(url)
345
        expected_result = circuits
346
347
        self.assertEqual(response.status_code, 200, response.data)
348
        self.assertEqual(json.loads(response.data), expected_result)
349
350
    # pylint: disable=no-self-use
351
    def _add_storehouse_schedule_data(self, storehouse_data_mock):
352
        """Add schedule data to storehouse mock object."""
353
        circuits = {}
354
        payload_1 = {
355
            "id": "aa:aa:aa",
356
            "name": "my evc1",
357
            "uni_a": {
358
                "interface_id": "00:00:00:00:00:00:00:01:1",
359
                "tag": {
360
                    "tag_type": 1,
361
                    "value": 80
362
                }
363
            },
364
            "uni_z": {
365
                "interface_id": "00:00:00:00:00:00:00:02:2",
366
                "tag": {
367
                    "tag_type": 1,
368
                    "value": 1
369
                }
370
            },
371
            "circuit_scheduler": [
372
                {
373
                    "id": "1",
374
                    "frequency": "* * * * *",
375
                    "action": "create"
376
                },
377
                {
378
                    "id": "2",
379
                    "frequency": "1 * * * *",
380
                    "action": "remove"
381
                }
382
            ]
383
        }
384
        circuits.update({'1': payload_1})
385
        payload_2 = {
386
            "id": "bb:bb:bb",
387
            "name": "my second evc1",
388
            "uni_a": {
389
                "interface_id": "00:00:00:00:00:00:00:01:2",
390
                "tag": {
391
                    "tag_type": 1,
392
                    "value": 90
393
                }
394
            },
395
            "uni_z": {
396
                "interface_id": "00:00:00:00:00:00:00:03:2",
397
                "tag": {
398
                    "tag_type": 1,
399
                    "value": 100
400
                }
401
            },
402
            "circuit_scheduler": [
403
                {
404
                    "id": "3",
405
                    "frequency": "1 * * * *",
406
                    "action": "create"
407
                },
408
                {
409
                    "id": "4",
410
                    "frequency": "2 * * * *",
411
                    "action": "remove"
412
                }
413
            ]
414
        }
415
        circuits.update({'2': payload_2})
416
        # Add one circuit to the storehouse.
417
        storehouse_data_mock.return_value = circuits
418
419
    @patch('napps.kytos.mef_eline.storehouse.StoreHouse.get_data')
420
    def test_list_schedules_from_storehouse(self, storehouse_data_mock):
421
        """Test if list circuits return specific circuits stored."""
422
        self._add_storehouse_schedule_data(storehouse_data_mock)
423
424
        api = self.get_app_test_client(self.napp)
425
        url = f'{self.server_name_url}/v2/evc/schedule'
426
427
        # Call URL
428
        response = api.get(url)
429
        # Expected JSON data from response
430
        expected = [{"aa:aa:aa":
431
                    [{"action": "create",
432
                      "frequency": "* * * * *",
433
                      "id": "1"},
434
                     {"action": "remove",
435
                      "frequency": "1 * * * *",
436
                      "id": "2"}]},
437
                    {"bb:bb:bb":
438
                        [{"action": "create",
439
                          "frequency": "1 * * * *",
440
                          "id": "3"},
441
                         {"action": "remove",
442
                          "frequency": "2 * * * *",
443
                          "id": "4"}]}
444
445
                    ]
446
447
        self.assertEqual(response.status_code, 200, response.data)
448
        self.assertEqual(expected, json.loads(response.data))
449
450
    @patch('napps.kytos.mef_eline.storehouse.StoreHouse.get_data')
451
    def test_get_specific_schedule_from_storehouse(self, storehouse_data_mock):
452
        """Test get schedules from a circuit."""
453
        self._add_storehouse_schedule_data(storehouse_data_mock)
454
455
        requested_id = "2"
456
        api = self.get_app_test_client(self.napp)
457
        url = f'{self.server_name_url}/v2/evc/{requested_id}'
458
459
        # Call URL
460
        response = api.get(url)
461
462
        # Expected JSON data from response
463
        expected = [{'action': 'create', 'frequency': '1 * * * *', 'id': '3'},
464
                    {'action': 'remove', 'frequency': '2 * * * *', 'id': '4'}]
465
466
        self.assertEqual(response.status_code, 200)
467
        self.assertEqual(expected,
468
                         json.loads(response.data)["circuit_scheduler"])
469
470
    def test_get_specific_schedules_from_storehouse_not_found(self):
471
        """Test get specific schedule ID that does not exist."""
472
        requested_id = "blah"
473
        api = self.get_app_test_client(self.napp)
474
        url = f'{self.server_name_url}/v2/evc/{requested_id}'
475
476
        # Call URL
477
        response = api.get(url)
478
479
        expected = {'response': 'circuit_id blah not found'}
480
        # Assert response not found
481
        self.assertEqual(response.status_code, 404, response.data)
482
        self.assertEqual(expected, json.loads(response.data))
483
484
    @patch('apscheduler.schedulers.background.BackgroundScheduler.add_job')
485
    @patch('napps.kytos.mef_eline.storehouse.StoreHouse.get_data')
486
    @patch('napps.kytos.mef_eline.scheduler.Scheduler.add')
487
    @patch('napps.kytos.mef_eline.main.Main.uni_from_dict')
488
    @patch('napps.kytos.mef_eline.storehouse.StoreHouse.save_evc')
489
    @patch('napps.kytos.mef_eline.main.EVC.as_dict')
490
    @patch('napps.kytos.mef_eline.models.EVC._validate')
491
    def test_create_schedule(self, *args):  # pylint: disable=too-many-locals
492
        """Test create a circuit schedule."""
493
        (validate_mock, evc_as_dict_mock, save_evc_mock,
494
         uni_from_dict_mock, sched_add_mock, storehouse_data_mock,
495
         scheduler_add_job_mock) = args
496
497
        validate_mock.return_value = True
498
        save_evc_mock.return_value = True
499
        uni_from_dict_mock.side_effect = ['uni_a', 'uni_z']
500
        evc_as_dict_mock.return_value = {}
501
        sched_add_mock.return_value = True
502
        storehouse_data_mock.return_value = {}
503
504
        self._add_storehouse_schedule_data(storehouse_data_mock)
505
506
        requested_id = "2"
507
        api = self.get_app_test_client(self.napp)
508
        url = f'{self.server_name_url}/v2/evc/schedule/'
509
510
        payload = {
511
              "circuit_id": requested_id,
512
              "schedule": {
513
                "frequency": "1 * * * *",
514
                "action": "create"
515
              }
516
            }
517
518
        # Call URL
519
        response = api.post(url, data=json.dumps(payload),
520
                            content_type='application/json')
521
522
        response_json = json.loads(response.data)
523
524
        self.assertEqual(response.status_code, 201, response.data)
525
        scheduler_add_job_mock.assert_called_once()
526
        save_evc_mock.assert_called_once()
527
        self.assertEqual(payload["schedule"]["frequency"],
528
                         response_json["frequency"])
529
        self.assertEqual(payload["schedule"]["action"],
530
                         response_json["action"])
531
        self.assertIsNotNone(response_json["id"])
532
533
    @patch('apscheduler.schedulers.background.BackgroundScheduler.remove_job')
534
    @patch('napps.kytos.mef_eline.storehouse.StoreHouse.get_data')
535
    @patch('napps.kytos.mef_eline.scheduler.Scheduler.add')
536
    @patch('napps.kytos.mef_eline.main.Main.uni_from_dict')
537
    @patch('napps.kytos.mef_eline.storehouse.StoreHouse.save_evc')
538
    @patch('napps.kytos.mef_eline.main.EVC.as_dict')
539
    @patch('napps.kytos.mef_eline.models.EVC._validate')
540
    def test_update_schedule(self, *args):  # pylint: disable=too-many-locals
541
        """Test create a circuit schedule."""
542
        (validate_mock, evc_as_dict_mock, save_evc_mock,
543
         uni_from_dict_mock, sched_add_mock, storehouse_data_mock,
544
         scheduler_remove_job_mock) = args
545
546
        storehouse_payload_1 = {
547
            "2": {
548
                "id": "2",
549
                "name": "my evc1",
550
                "uni_a": {
551
                    "interface_id": "00:00:00:00:00:00:00:01:1",
552
                    "tag": {
553
                        "tag_type": 1,
554
                        "value": 80
555
                    }
556
                },
557
                "uni_z": {
558
                    "interface_id": "00:00:00:00:00:00:00:02:2",
559
                    "tag": {
560
                        "tag_type": 1,
561
                        "value": 1
562
                    }
563
                },
564
                "circuit_scheduler": [{
565
                    "id": "1",
566
                    "frequency": "* * * * *",
567
                    "action": "create"
568
                }
569
                ]
570
            }
571
        }
572
573
        validate_mock.return_value = True
574
        save_evc_mock.return_value = True
575
        sched_add_mock.return_value = True
576
        uni_from_dict_mock.side_effect = ['uni_a', 'uni_z']
577
        evc_as_dict_mock.return_value = {}
578
        storehouse_data_mock.return_value = storehouse_payload_1
579
        scheduler_remove_job_mock.return_value = True
580
581
        requested_schedule_id = "1"
582
        api = self.get_app_test_client(self.napp)
583
        url = f'{self.server_name_url}/v2/evc/schedule/{requested_schedule_id}'
584
585
        payload = {
586
            "frequency": "1 * * * *",
587
            "action": "create"
588
        }
589
590
        # Call URL
591
        response = api.patch(url, data=json.dumps(payload),
592
                             content_type='application/json')
593
594
        response_json = json.loads(response.data)
595
596
        self.assertEqual(response.status_code, 200, response.data)
597
        scheduler_remove_job_mock.assert_called_once()
598
        save_evc_mock.assert_called_once()
599
        self.assertEqual(payload["frequency"], response_json["frequency"])
600
        self.assertEqual(payload["action"], response_json["action"])
601
        self.assertIsNotNone(response_json["id"])
602
603
    @patch('apscheduler.schedulers.background.BackgroundScheduler.remove_job')
604
    @patch('napps.kytos.mef_eline.storehouse.StoreHouse.get_data')
605
    @patch('napps.kytos.mef_eline.main.Main.uni_from_dict')
606
    @patch('napps.kytos.mef_eline.storehouse.StoreHouse.save_evc')
607
    @patch('napps.kytos.mef_eline.main.EVC.as_dict')
608
    @patch('napps.kytos.mef_eline.models.EVC._validate')
609
    def test_delete_schedule(self, *args):
610
        """Test create a circuit schedule."""
611
        (validate_mock, evc_as_dict_mock, save_evc_mock,
612
         uni_from_dict_mock, storehouse_data_mock,
613
         scheduler_remove_job_mock) = args
614
615
        storehouse_payload_1 = {
616
            "2": {
617
                "id": "2",
618
                "name": "my evc1",
619
                "uni_a": {
620
                    "interface_id": "00:00:00:00:00:00:00:01:1",
621
                    "tag": {
622
                        "tag_type": 1,
623
                        "value": 80
624
                    }
625
                },
626
                "uni_z": {
627
                    "interface_id": "00:00:00:00:00:00:00:02:2",
628
                    "tag": {
629
                        "tag_type": 1,
630
                        "value": 1
631
                    }
632
                },
633
                "circuit_scheduler": [{
634
                    "id": "1",
635
                    "frequency": "* * * * *",
636
                    "action": "create"
637
                }]
638
            }
639
        }
640
641
        validate_mock.return_value = True
642
        save_evc_mock.return_value = True
643
        uni_from_dict_mock.side_effect = ['uni_a', 'uni_z']
644
        evc_as_dict_mock.return_value = {}
645
        storehouse_data_mock.return_value = storehouse_payload_1
646
        scheduler_remove_job_mock.return_value = True
647
648
        requested_schedule_id = "1"
649
        api = self.get_app_test_client(self.napp)
650
        url = f'{self.server_name_url}/v2/evc/schedule/{requested_schedule_id}'
651
652
        # Call URL
653
        response = api.delete(url)
654
655
        self.assertEqual(response.status_code, 200, response.data)
656
        scheduler_remove_job_mock.assert_called_once()
657
        save_evc_mock.assert_called_once()
658
        self.assertIn("Schedule removed", f"{response.data}")
659