|
@@ 1442-1509 (lines=68) @@
|
| 1439 |
|
evc_deploy.assert_not_called() |
| 1440 |
|
self.assertEqual(405, response.status_code) |
| 1441 |
|
|
| 1442 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC.deploy") |
| 1443 |
|
@patch("napps.kytos.mef_eline.scheduler.Scheduler.add") |
| 1444 |
|
@patch("napps.kytos.mef_eline.main.Main._uni_from_dict") |
| 1445 |
|
@patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc") |
| 1446 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC._validate") |
| 1447 |
|
@patch("napps.kytos.mef_eline.main.EVC.as_dict") |
| 1448 |
|
def test_update_circuit_invalid_json(self, *args): |
| 1449 |
|
"""Test update a circuit circuit.""" |
| 1450 |
|
# pylint: disable=too-many-locals |
| 1451 |
|
( |
| 1452 |
|
evc_as_dict_mock, |
| 1453 |
|
validate_mock, |
| 1454 |
|
mongo_controller_upsert_mock, |
| 1455 |
|
uni_from_dict_mock, |
| 1456 |
|
sched_add_mock, |
| 1457 |
|
evc_deploy_mock, |
| 1458 |
|
) = args |
| 1459 |
|
|
| 1460 |
|
validate_mock.return_value = True |
| 1461 |
|
mongo_controller_upsert_mock.return_value = True |
| 1462 |
|
sched_add_mock.return_value = True |
| 1463 |
|
evc_deploy_mock.return_value = True |
| 1464 |
|
uni1 = create_autospec(UNI) |
| 1465 |
|
uni2 = create_autospec(UNI) |
| 1466 |
|
uni1.interface = create_autospec(Interface) |
| 1467 |
|
uni2.interface = create_autospec(Interface) |
| 1468 |
|
uni1.interface.switch = "00:00:00:00:00:00:00:01" |
| 1469 |
|
uni2.interface.switch = "00:00:00:00:00:00:00:02" |
| 1470 |
|
uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2] |
| 1471 |
|
|
| 1472 |
|
api = self.get_app_test_client(self.napp) |
| 1473 |
|
payload1 = { |
| 1474 |
|
"name": "my evc1", |
| 1475 |
|
"uni_a": { |
| 1476 |
|
"interface_id": "00:00:00:00:00:00:00:01:1", |
| 1477 |
|
"tag": {"tag_type": 1, "value": 80}, |
| 1478 |
|
}, |
| 1479 |
|
"uni_z": { |
| 1480 |
|
"interface_id": "00:00:00:00:00:00:00:02:2", |
| 1481 |
|
"tag": {"tag_type": 1, "value": 1}, |
| 1482 |
|
}, |
| 1483 |
|
"dynamic_backup_path": True, |
| 1484 |
|
} |
| 1485 |
|
|
| 1486 |
|
payload2 = { |
| 1487 |
|
"dynamic_backup_path": False, |
| 1488 |
|
} |
| 1489 |
|
|
| 1490 |
|
evc_as_dict_mock.return_value = payload1 |
| 1491 |
|
response = api.post( |
| 1492 |
|
f"{self.server_name_url}/v2/evc/", |
| 1493 |
|
data=json.dumps(payload1), |
| 1494 |
|
content_type="application/json", |
| 1495 |
|
) |
| 1496 |
|
self.assertEqual(201, response.status_code) |
| 1497 |
|
|
| 1498 |
|
evc_as_dict_mock.return_value = payload2 |
| 1499 |
|
current_data = json.loads(response.data) |
| 1500 |
|
circuit_id = current_data["circuit_id"] |
| 1501 |
|
response = api.patch( |
| 1502 |
|
f"{self.server_name_url}/v2/evc/{circuit_id}", |
| 1503 |
|
data=payload2, |
| 1504 |
|
content_type="application/json", |
| 1505 |
|
) |
| 1506 |
|
current_data = json.loads(response.data) |
| 1507 |
|
expected_data = "The request body is not a well-formed JSON." |
| 1508 |
|
self.assertEqual(current_data["description"], expected_data) |
| 1509 |
|
self.assertEqual(400, response.status_code) |
| 1510 |
|
|
| 1511 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC.deploy") |
| 1512 |
|
@patch("napps.kytos.mef_eline.scheduler.Scheduler.add") |
|
@@ 1591-1650 (lines=60) @@
|
| 1588 |
|
self.assertEqual(400, response.status_code) |
| 1589 |
|
self.assertEqual(current_data["description"], expected_data) |
| 1590 |
|
|
| 1591 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC.deploy") |
| 1592 |
|
@patch("napps.kytos.mef_eline.scheduler.Scheduler.add") |
| 1593 |
|
@patch("napps.kytos.mef_eline.main.Main._uni_from_dict") |
| 1594 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC._validate") |
| 1595 |
|
@patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc") |
| 1596 |
|
def test_update_evc_no_json_mime(self, *args): |
| 1597 |
|
"""Test update a circuit with wrong mimetype.""" |
| 1598 |
|
# pylint: disable=too-many-locals |
| 1599 |
|
( |
| 1600 |
|
mongo_controller_upsert_mock, |
| 1601 |
|
validate_mock, |
| 1602 |
|
uni_from_dict_mock, |
| 1603 |
|
sched_add_mock, |
| 1604 |
|
evc_deploy_mock, |
| 1605 |
|
) = args |
| 1606 |
|
|
| 1607 |
|
validate_mock.return_value = True |
| 1608 |
|
sched_add_mock.return_value = True |
| 1609 |
|
evc_deploy_mock.return_value = True |
| 1610 |
|
uni1 = create_autospec(UNI) |
| 1611 |
|
uni2 = create_autospec(UNI) |
| 1612 |
|
uni1.interface = create_autospec(Interface) |
| 1613 |
|
uni2.interface = create_autospec(Interface) |
| 1614 |
|
uni1.interface.switch = "00:00:00:00:00:00:00:01" |
| 1615 |
|
uni2.interface.switch = "00:00:00:00:00:00:00:02" |
| 1616 |
|
uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2] |
| 1617 |
|
mongo_controller_upsert_mock.return_value = True |
| 1618 |
|
|
| 1619 |
|
api = self.get_app_test_client(self.napp) |
| 1620 |
|
payload1 = { |
| 1621 |
|
"name": "my evc1", |
| 1622 |
|
"uni_a": { |
| 1623 |
|
"interface_id": "00:00:00:00:00:00:00:01:1", |
| 1624 |
|
"tag": {"tag_type": 1, "value": 80}, |
| 1625 |
|
}, |
| 1626 |
|
"uni_z": { |
| 1627 |
|
"interface_id": "00:00:00:00:00:00:00:02:2", |
| 1628 |
|
"tag": {"tag_type": 1, "value": 1}, |
| 1629 |
|
}, |
| 1630 |
|
"dynamic_backup_path": True, |
| 1631 |
|
} |
| 1632 |
|
|
| 1633 |
|
payload2 = {"dynamic_backup_path": False} |
| 1634 |
|
|
| 1635 |
|
response = api.post( |
| 1636 |
|
f"{self.server_name_url}/v2/evc/", |
| 1637 |
|
data=json.dumps(payload1), |
| 1638 |
|
content_type="application/json", |
| 1639 |
|
) |
| 1640 |
|
self.assertEqual(201, response.status_code) |
| 1641 |
|
|
| 1642 |
|
current_data = json.loads(response.data) |
| 1643 |
|
circuit_id = current_data["circuit_id"] |
| 1644 |
|
response = api.patch( |
| 1645 |
|
f"{self.server_name_url}/v2/evc/{circuit_id}", data=payload2 |
| 1646 |
|
) |
| 1647 |
|
current_data = json.loads(response.data) |
| 1648 |
|
expected_data = "The request body mimetype is not application/json." |
| 1649 |
|
self.assertEqual(current_data["description"], expected_data) |
| 1650 |
|
self.assertEqual(415, response.status_code) |
| 1651 |
|
|
| 1652 |
|
def test_delete_no_evc(self): |
| 1653 |
|
"""Test delete when EVC does not exist.""" |