Files
DocsGPT/tests/test_openapi3parser.py
T
Alex 574f96341e refactor: rename the application package to docsgpt
The backend import package is now docsgpt, the name it will carry on PyPI;
application was far too generic to install into anyone's site-packages.
git mv plus a mechanical rewrite of every import, dotted string and path
reference: 734 Python files, the compose files, Dockerfile, workflows, docs,
setup scripts, devcontainer, k8s manifests, vscode config, pytest and coverage
config, .gitignore. Behaviour is unchanged.

Kept for one release:
- A top-level application package whose meta-path finder resolves
  application.x.y to the already-imported docsgpt.x.y object, so old imports
  and entry points (celery -A application.app.celery,
  uvicorn application.asgi:asgi_app) keep working with a FutureWarning.
- Celery registers every application.* task name as an alias of its
  docsgpt.* task on start-up, so messages queued by the previous release still
  run. The redbeat key prefix moves to redbeat:docsgpt:v2: so schedule entries
  the previous release wrote are left unread instead of firing twice.

The backend image builds from the repository root (docker build -f
docsgpt/Dockerfile .) so it can ship the alias package; a root .dockerignore
allow-lists docsgpt/ and application/ and keeps caches, local data, .env
files, the sample index files and the Dockerfile out. Compose and the image
workflows point at the new context.
2026-09-07 10:20:43 +01:00

54 lines
1.6 KiB
Python

import pytest
from docsgpt.parser.file.openapi3_parser import OpenAPI3Parser
from openapi_parser import parse
@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"],
),
],
)
@pytest.mark.unit
def test_get_base_urls(urls, expected_base_urls):
assert OpenAPI3Parser().get_base_urls(urls) == expected_base_urls
@pytest.mark.unit
def test_get_info_from_paths():
file_path = "tests/test_openapi3.yaml"
data = parse(file_path)
path = data.paths[1]
assert (
OpenAPI3Parser().get_info_from_paths(path)
== "\nget=Expected response to a valid request"
)
@pytest.mark.unit
def test_parse_file():
file_path = "tests/test_openapi3.yaml"
results_expected = (
"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"
)
openapi_parser_test = OpenAPI3Parser()
results = openapi_parser_test.parse_file(file_path)
assert results == results_expected
if __name__ == "__main__":
pytest.main()