Test Failed
Pull Request — master (#140)
by Rogerio
04:09
created

TestMain.test_create_schedule()   B

Complexity

Conditions 1

Size

Total Lines 49
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

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