@@ 1388-1451 (lines=64) @@ | ||
1385 | evc_deploy.assert_not_called() |
|
1386 | self.assertEqual(405, response.status_code) |
|
1387 | ||
1388 | @patch("napps.kytos.mef_eline.models.evc.EVC.deploy") |
|
1389 | @patch("napps.kytos.mef_eline.scheduler.Scheduler.add") |
|
1390 | @patch("napps.kytos.mef_eline.main.Main._uni_from_dict") |
|
1391 | @patch("napps.kytos.mef_eline.storehouse.StoreHouse.save_evc") |
|
1392 | @patch("napps.kytos.mef_eline.models.evc.EVC._validate") |
|
1393 | @patch("napps.kytos.mef_eline.main.EVC.as_dict") |
|
1394 | def test_update_circuit_invalid_json(self, *args): |
|
1395 | """Test update a circuit circuit.""" |
|
1396 | # pylint: disable=too-many-locals |
|
1397 | ( |
|
1398 | evc_as_dict_mock, |
|
1399 | validate_mock, |
|
1400 | save_evc_mock, |
|
1401 | uni_from_dict_mock, |
|
1402 | sched_add_mock, |
|
1403 | evc_deploy_mock, |
|
1404 | ) = args |
|
1405 | ||
1406 | validate_mock.return_value = True |
|
1407 | save_evc_mock.return_value = True |
|
1408 | sched_add_mock.return_value = True |
|
1409 | evc_deploy_mock.return_value = True |
|
1410 | uni1 = create_autospec(UNI) |
|
1411 | uni2 = create_autospec(UNI) |
|
1412 | uni1.interface = create_autospec(Interface) |
|
1413 | uni2.interface = create_autospec(Interface) |
|
1414 | uni1.interface.switch = "00:00:00:00:00:00:00:01" |
|
1415 | uni2.interface.switch = "00:00:00:00:00:00:00:02" |
|
1416 | uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2] |
|
1417 | ||
1418 | api = self.get_app_test_client(self.napp) |
|
1419 | payload1 = { |
|
1420 | "name": "my evc1", |
|
1421 | "uni_a": { |
|
1422 | "interface_id": "00:00:00:00:00:00:00:01:1", |
|
1423 | "tag": {"tag_type": 1, "value": 80}, |
|
1424 | }, |
|
1425 | "uni_z": { |
|
1426 | "interface_id": "00:00:00:00:00:00:00:02:2", |
|
1427 | "tag": {"tag_type": 1, "value": 1}, |
|
1428 | }, |
|
1429 | "dynamic_backup_path": True, |
|
1430 | } |
|
1431 | ||
1432 | payload2 = { |
|
1433 | "dynamic_backup_path": False, |
|
1434 | } |
|
1435 | ||
1436 | evc_as_dict_mock.return_value = payload1 |
|
1437 | response = api.post( |
|
1438 | f"{self.server_name_url}/v2/evc/", |
|
1439 | data=json.dumps(payload1), |
|
1440 | content_type="application/json", |
|
1441 | ) |
|
1442 | self.assertEqual(201, response.status_code) |
|
1443 | ||
1444 | evc_as_dict_mock.return_value = payload2 |
|
1445 | current_data = json.loads(response.data) |
|
1446 | circuit_id = current_data["circuit_id"] |
|
1447 | response = api.patch( |
|
1448 | f"{self.server_name_url}/v2/evc/{circuit_id}", |
|
1449 | data=payload2, |
|
1450 | content_type="application/json", |
|
1451 | ) |
|
1452 | current_data = json.loads(response.data) |
|
1453 | expected_data = "The request body is not a well-formed JSON." |
|
1454 | self.assertEqual(current_data["description"], expected_data) |
|
@@ 1537-1599 (lines=63) @@ | ||
1534 | self.assertEqual(400, response.status_code) |
|
1535 | self.assertEqual(current_data["description"], expected_data) |
|
1536 | ||
1537 | @patch("napps.kytos.mef_eline.models.evc.EVC.deploy") |
|
1538 | @patch("napps.kytos.mef_eline.scheduler.Scheduler.add") |
|
1539 | @patch("napps.kytos.mef_eline.main.Main._uni_from_dict") |
|
1540 | @patch("napps.kytos.mef_eline.storehouse.StoreHouse.save_evc") |
|
1541 | @patch("napps.kytos.mef_eline.models.evc.EVC._validate") |
|
1542 | @patch("napps.kytos.mef_eline.main.EVC.as_dict") |
|
1543 | def test_update_evc_no_json_mime(self, *args): |
|
1544 | """Test update a circuit with wrong mimetype.""" |
|
1545 | # pylint: disable=too-many-locals |
|
1546 | ( |
|
1547 | evc_as_dict_mock, |
|
1548 | validate_mock, |
|
1549 | save_evc_mock, |
|
1550 | uni_from_dict_mock, |
|
1551 | sched_add_mock, |
|
1552 | evc_deploy_mock, |
|
1553 | ) = args |
|
1554 | ||
1555 | validate_mock.return_value = True |
|
1556 | save_evc_mock.return_value = True |
|
1557 | sched_add_mock.return_value = True |
|
1558 | evc_deploy_mock.return_value = True |
|
1559 | uni1 = create_autospec(UNI) |
|
1560 | uni2 = create_autospec(UNI) |
|
1561 | uni1.interface = create_autospec(Interface) |
|
1562 | uni2.interface = create_autospec(Interface) |
|
1563 | uni1.interface.switch = "00:00:00:00:00:00:00:01" |
|
1564 | uni2.interface.switch = "00:00:00:00:00:00:00:02" |
|
1565 | uni_from_dict_mock.side_effect = [uni1, uni2, uni1, uni2] |
|
1566 | ||
1567 | api = self.get_app_test_client(self.napp) |
|
1568 | payload1 = { |
|
1569 | "name": "my evc1", |
|
1570 | "uni_a": { |
|
1571 | "interface_id": "00:00:00:00:00:00:00:01:1", |
|
1572 | "tag": {"tag_type": 1, "value": 80}, |
|
1573 | }, |
|
1574 | "uni_z": { |
|
1575 | "interface_id": "00:00:00:00:00:00:00:02:2", |
|
1576 | "tag": {"tag_type": 1, "value": 1}, |
|
1577 | }, |
|
1578 | "dynamic_backup_path": True, |
|
1579 | } |
|
1580 | ||
1581 | payload2 = {"dynamic_backup_path": False} |
|
1582 | ||
1583 | evc_as_dict_mock.return_value = payload1 |
|
1584 | response = api.post( |
|
1585 | f"{self.server_name_url}/v2/evc/", |
|
1586 | data=json.dumps(payload1), |
|
1587 | content_type="application/json", |
|
1588 | ) |
|
1589 | self.assertEqual(201, response.status_code) |
|
1590 | ||
1591 | evc_as_dict_mock.return_value = payload2 |
|
1592 | current_data = json.loads(response.data) |
|
1593 | circuit_id = current_data["circuit_id"] |
|
1594 | response = api.patch( |
|
1595 | f"{self.server_name_url}/v2/evc/{circuit_id}", data=payload2 |
|
1596 | ) |
|
1597 | current_data = json.loads(response.data) |
|
1598 | expected_data = "The request body mimetype is not application/json." |
|
1599 | self.assertEqual(current_data["description"], expected_data) |
|
1600 | self.assertEqual(415, response.status_code) |
|
1601 | ||
1602 | def test_delete_no_evc(self): |