mirror of
https://github.com/Telecominfraproject/oopt-gnpy-api.git
synced 2025-10-30 17:37:47 +00:00
Added test for /path-request route with expected input and response
Change-Id: I1af159af39136416ea7a379e02296c8ef3b606bf
This commit is contained in:
1578
tests/data/req/planning_demand_example.json
Normal file
1578
tests/data/req/planning_demand_example.json
Normal file
File diff suppressed because it is too large
Load Diff
1469
tests/data/res/planning_demand_res.json
Normal file
1469
tests/data/res/planning_demand_res.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -2,21 +2,41 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# @Author: Esther Le Rouzic
|
# @Author: Esther Le Rouzic
|
||||||
# @Date: 2025-02-03
|
# @Date: 2025-02-03
|
||||||
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import subprocess
|
|
||||||
import pytest # noqa: F401
|
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from flask_injector import FlaskInjector
|
||||||
|
|
||||||
|
from gnpyapi.core import app
|
||||||
|
|
||||||
YANG_DIR = Path(__file__).parent.parent / 'gnpyapi' / 'yang'
|
YANG_DIR = Path(__file__).parent.parent / 'gnpyapi' / 'yang'
|
||||||
SAMPLE_DIR = Path(__file__).parent.parent / 'samples'
|
SAMPLE_DIR = Path(__file__).parent.parent / 'samples'
|
||||||
|
|
||||||
|
TEST_DATA_DIR = Path(__file__).parent / 'data'
|
||||||
|
TEST_REQ_DIR = TEST_DATA_DIR / 'req'
|
||||||
|
TEST_RES_DIR = TEST_DATA_DIR / 'res'
|
||||||
|
|
||||||
def test_pyang():
|
API_VERSION = '/api/v1'
|
||||||
"""Verify that yang models pss pyang
|
|
||||||
"""
|
|
||||||
res = subprocess.run(['pyang', '-f', 'tree', '--tree-line-length', '69',
|
def read_json_file(path):
|
||||||
'-p', YANG_DIR, YANG_DIR / 'gnpy-api@2021-01-06.yang'],
|
with open(path, "r") as file:
|
||||||
stdout=subprocess.PIPE, check=True)
|
return json.load(file)
|
||||||
if res.returncode != 0:
|
|
||||||
assert False, f'pyang failed: exit code {res.returncode}'
|
|
||||||
|
@pytest.fixture
|
||||||
|
def client():
|
||||||
|
app.testing = True
|
||||||
|
FlaskInjector(app=app)
|
||||||
|
with app.test_client() as client:
|
||||||
|
yield client
|
||||||
|
|
||||||
|
|
||||||
|
def test_echo(client):
|
||||||
|
input_data = read_json_file(TEST_REQ_DIR / "planning_demand_example.json")
|
||||||
|
expected_response = read_json_file(TEST_RES_DIR / "planning_demand_res.json")
|
||||||
|
|
||||||
|
response = client.post(f"{API_VERSION}/path-request", json=input_data)
|
||||||
|
assert response.status_code == 201
|
||||||
|
assert response.get_json() == expected_response
|
||||||
|
|||||||
Reference in New Issue
Block a user