From 98c7e9d40380e89dbd08c9d39a07339a29ff44be Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sun, 1 Feb 2026 16:20:39 +0000 Subject: [PATCH] Initial upload with CI/CD workflow --- tests/test_parser.py | 74 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 tests/test_parser.py diff --git a/tests/test_parser.py b/tests/test_parser.py new file mode 100644 index 0000000..845b540 --- /dev/null +++ b/tests/test_parser.py @@ -0,0 +1,74 @@ +import pytest +from src.core.parser import parse_openapi_spec, load_spec_file, ParseError + + +@pytest.fixture +def sample_spec(tmp_path): + spec = { + "openapi": "3.0.0", + "info": { + "title": "Test API", + "version": "1.0.0" + }, + "paths": { + "/users": { + "get": { + "summary": "Get users", + "description": "Retrieve a list of users", + "tags": ["users"], + "responses": { + "200": {"description": "Successful response"} + } + } + } + } + } + path = tmp_path / "test.json" + path.write_text(__import__('json').dumps(spec)) + return path + + +def test_parse_valid_spec(sample_spec): + result = parse_openapi_spec(str(sample_spec)) + assert result['valid'] == True + assert result['title'] == 'Test API' + assert result['version_num'] == '1.0.0' + + +def test_parse_invalid_spec(tmp_path): + invalid = tmp_path / "invalid.json" + invalid.write_text('{"invalid": "spec"}') + result = parse_openapi_spec(str(invalid)) + assert result['valid'] == False + assert 'errors' in result + + +def test_load_json_spec(sample_spec): + spec = load_spec_file(str(sample_spec)) + assert spec['info']['title'] == 'Test API' + + +def test_load_yaml_spec(tmp_path): + content = ''' +openapi: "3.0.0" +info: + title: Test API + version: "1.0.0" +paths: {} +''' + path = tmp_path / "test.yaml" + path.write_text(content) + spec = load_spec_file(str(path)) + assert spec['info']['title'] == 'Test API' + + +def test_parse_error_missing_file(): + with pytest.raises(ParseError): + load_spec_file('/nonexistent/path.json') + + +def test_parse_error_unsupported_format(tmp_path): + path = tmp_path / "test.txt" + path.write_text('some content') + with pytest.raises(ParseError): + load_spec_file(str(path))