2023-10-15 11:30:54 +00:00
|
|
|
import pytest
|
|
|
|
from openapi_parser import parse
|
2023-10-25 11:20:01 +00:00
|
|
|
from application.parser.file.openapi3_parser import OpenAPI3Parser
|
2023-10-15 11:30:54 +00:00
|
|
|
|
|
|
|
|
2023-10-15 11:46:12 +00:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"urls, expected_base_urls",
|
|
|
|
[
|
|
|
|
(
|
|
|
|
[
|
|
|
|
"http://petstore.swagger.io/v1",
|
|
|
|
"https://api.example.com/v1/resource",
|
|
|
|
"https://api.example.com/v1/another/resource",
|
|
|
|
"https://api.example.com/v1/some/endpoint",
|
|
|
|
],
|
|
|
|
["http://petstore.swagger.io", "https://api.example.com"],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
2023-10-15 11:30:54 +00:00
|
|
|
def test_get_base_urls(urls, expected_base_urls):
|
|
|
|
assert OpenAPI3Parser().get_base_urls(urls) == expected_base_urls
|
|
|
|
|
2023-10-15 11:46:12 +00:00
|
|
|
|
2023-10-15 11:30:54 +00:00
|
|
|
def test_get_info_from_paths():
|
|
|
|
file_path = "tests/test_openapi3.yaml"
|
|
|
|
data = parse(file_path)
|
2023-10-15 11:46:12 +00:00
|
|
|
path = data.paths[1]
|
|
|
|
assert (
|
|
|
|
OpenAPI3Parser().get_info_from_paths(path)
|
|
|
|
== "\nget=Expected response to a valid request"
|
|
|
|
)
|
2023-10-15 11:30:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_parse_file():
|
|
|
|
file_path = "tests/test_openapi3.yaml"
|
2023-10-24 02:13:57 +00:00
|
|
|
results_expected = (
|
2023-10-15 11:46:12 +00:00
|
|
|
"Base URL:http://petstore.swagger.io,https://api.example.com\nPath1: "
|
|
|
|
+ "/pets\ndescription: None\nparameters: []\nmethods: \n"
|
|
|
|
+ "get=A paged array of pets\npost=Null "
|
|
|
|
+ "response\nPath2: /pets/{petId}\ndescription: None\n"
|
|
|
|
+ "parameters: []\nmethods: "
|
|
|
|
+ "\nget=Expected response to a valid request\n"
|
|
|
|
)
|
2023-10-15 11:30:54 +00:00
|
|
|
openapi_parser_test = OpenAPI3Parser()
|
2023-10-15 11:46:12 +00:00
|
|
|
results = openapi_parser_test.parse_file(file_path)
|
2023-10-24 02:13:57 +00:00
|
|
|
assert results == results_expected
|
2023-10-15 11:30:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
pytest.main()
|