mirror of
https://github.com/Telecominfraproject/oopt-gnpy-api.git
synced 2025-10-29 09:02:39 +00:00
Implemented unit tests for PathRequestService: invalid equipment, topology, and success case
Change-Id: If863b6d2458642a682f2e687501433045c2311c9
This commit is contained in:
1578
tests/data/req/planning_demand_wrong_eqpt.json
Normal file
1578
tests/data/req/planning_demand_wrong_eqpt.json
Normal file
File diff suppressed because it is too large
Load Diff
1578
tests/data/req/planning_demand_wrong_topology.json
Normal file
1578
tests/data/req/planning_demand_wrong_topology.json
Normal file
File diff suppressed because it is too large
Load Diff
0
tests/service/__init__.py
Normal file
0
tests/service/__init__.py
Normal file
55
tests/service/test_path_request_service.py
Normal file
55
tests/service/test_path_request_service.py
Normal file
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Author: Esther Le Rouzic
|
||||
# @Date: 2025-02-03
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from gnpyapi.core.exception.equipment_error import EquipmentError
|
||||
|
||||
from gnpyapi.core.service.path_request_service import PathRequestService
|
||||
from gnpyapi.core.exception.topology_error import TopologyError
|
||||
|
||||
TEST_DATA_DIR = Path(__file__).parent.parent / 'data'
|
||||
TEST_REQ_DIR = TEST_DATA_DIR / 'req'
|
||||
TEST_RES_DIR = TEST_DATA_DIR / 'res'
|
||||
|
||||
|
||||
def read_json_file(path):
|
||||
with open(path, "r") as file:
|
||||
return json.load(file)
|
||||
|
||||
|
||||
def test_path_request_success():
|
||||
input_data = read_json_file(TEST_REQ_DIR / "planning_demand_example.json")
|
||||
expected_response = read_json_file(TEST_RES_DIR / "planning_demand_res.json")
|
||||
topology = input_data["gnpy-api:topology"]
|
||||
equipment = input_data["gnpy-api:equipment"]
|
||||
service = input_data["gnpy-api:service"]
|
||||
|
||||
result = PathRequestService.path_request(topology, equipment, service)
|
||||
assert result == expected_response
|
||||
|
||||
|
||||
def test_path_request_invalid_equipment():
|
||||
input_data = read_json_file(TEST_REQ_DIR / "planning_demand_wrong_eqpt.json")
|
||||
topology = input_data["gnpy-api:topology"]
|
||||
equipment = input_data["gnpy-api:equipment"]
|
||||
service = input_data["gnpy-api:service"]
|
||||
|
||||
with pytest.raises(EquipmentError) as exc:
|
||||
PathRequestService.path_request(topology, equipment, service)
|
||||
assert "invalid" in str(exc.value).lower()
|
||||
assert "deltap" in str(exc.value).lower()
|
||||
|
||||
|
||||
def test_path_request_invalid_topology():
|
||||
input_data = read_json_file(TEST_REQ_DIR / "planning_demand_wrong_topology.json")
|
||||
topology = input_data["gnpy-api:topology"]
|
||||
equipment = input_data["gnpy-api:equipment"]
|
||||
service = input_data["gnpy-api:service"]
|
||||
|
||||
with pytest.raises(TopologyError) as exc:
|
||||
PathRequestService.path_request(topology, equipment, service)
|
||||
assert "can not find" in str(exc.value).lower()
|
||||
Reference in New Issue
Block a user