typer integration and header for PAD AUF
This commit is contained in:
@@ -14,6 +14,7 @@ import xml.etree.ElementTree as ET
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Dict, Any, List
|
||||
from typer.testing import CliRunner
|
||||
|
||||
# Import modules to test
|
||||
from utils import (
|
||||
@@ -44,7 +45,8 @@ from fhir_to_pad_converter import (
|
||||
validate_pad_xml,
|
||||
compute_pad_stats,
|
||||
build_pad_xml,
|
||||
PAD_NS
|
||||
PAD_NS,
|
||||
app
|
||||
)
|
||||
|
||||
|
||||
@@ -999,6 +1001,173 @@ class TestConfigValidation:
|
||||
pytest.skip("config_schemas module not available")
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# CLI TESTS (Typer)
|
||||
# ============================================================================
|
||||
|
||||
class TestCLI:
|
||||
"""Tests for command-line interface using typer."""
|
||||
|
||||
def setup_method(self):
|
||||
"""Set up CLI test runner."""
|
||||
self.runner = CliRunner()
|
||||
|
||||
def test_cli_help(self):
|
||||
"""Test --help output."""
|
||||
result = self.runner.invoke(app, ["--help"])
|
||||
assert result.exit_code == 0
|
||||
assert "Convert FHIR Bundle JSON to PADneXt 2.12 XML format" in result.stdout
|
||||
assert "--input-json" in result.stdout
|
||||
assert "--output-dir" in result.stdout
|
||||
assert "--verbose" in result.stdout
|
||||
|
||||
def test_cli_missing_required_arg(self):
|
||||
"""Test error when required argument missing."""
|
||||
result = self.runner.invoke(app, [])
|
||||
assert result.exit_code != 0
|
||||
assert "Missing option '--input-json'" in result.stdout
|
||||
|
||||
def test_cli_short_aliases_in_help(self):
|
||||
"""Test that short aliases are shown in help."""
|
||||
result = self.runner.invoke(app, ["--help"])
|
||||
assert result.exit_code == 0
|
||||
assert "-i" in result.stdout # Short alias for --input-json
|
||||
assert "-o" in result.stdout # Short alias for --output-dir
|
||||
assert "-v" in result.stdout # Short alias for --verbose
|
||||
assert "-m" in result.stdout # Short alias for --mapping-config
|
||||
|
||||
def test_cli_invalid_file(self):
|
||||
"""Test error with nonexistent file."""
|
||||
result = self.runner.invoke(app, ["--input-json", "nonexistent.json"])
|
||||
assert result.exit_code != 0
|
||||
# Check for error message (may have formatting/line breaks)
|
||||
assert "does not" in result.stdout and "exist" in result.stdout
|
||||
|
||||
def test_cli_full_conversion(self, tmp_path):
|
||||
"""Test complete conversion workflow."""
|
||||
# Create test input file
|
||||
input_file = tmp_path / "input.json"
|
||||
test_bundle = {
|
||||
"resourceType": "Bundle",
|
||||
"type": "collection",
|
||||
"entry": [
|
||||
{
|
||||
"resource": {
|
||||
"resourceType": "Patient",
|
||||
"id": "patient-1",
|
||||
"name": [{"family": "Test", "given": ["John"]}],
|
||||
"birthDate": "1980-01-01",
|
||||
"gender": "male"
|
||||
}
|
||||
},
|
||||
{
|
||||
"resource": {
|
||||
"resourceType": "Encounter",
|
||||
"id": "encounter-1",
|
||||
"status": "finished",
|
||||
"subject": {"reference": "Patient/patient-1"}
|
||||
}
|
||||
},
|
||||
{
|
||||
"resource": {
|
||||
"resourceType": "Observation",
|
||||
"id": "obs-1",
|
||||
"status": "final",
|
||||
"code": {"coding": [{"code": "12345", "display": "Test"}]},
|
||||
"subject": {"reference": "Patient/patient-1"},
|
||||
"encounter": {"reference": "Encounter/encounter-1"},
|
||||
"effectiveDateTime": "2024-01-01T10:00:00Z"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
input_file.write_text(json.dumps(test_bundle))
|
||||
|
||||
# Run conversion
|
||||
result = self.runner.invoke(app, [
|
||||
"--input-json", str(input_file),
|
||||
"--output-dir", str(tmp_path)
|
||||
])
|
||||
|
||||
# Check result
|
||||
assert result.exit_code == 0
|
||||
assert "SUCCESS" in result.stdout or "Conversion completed" in result.stdout
|
||||
|
||||
def test_cli_with_short_aliases(self, tmp_path):
|
||||
"""Test using short aliases."""
|
||||
# Create test input file
|
||||
input_file = tmp_path / "input.json"
|
||||
test_bundle = {
|
||||
"resourceType": "Bundle",
|
||||
"type": "collection",
|
||||
"entry": [{
|
||||
"resource": {
|
||||
"resourceType": "Patient",
|
||||
"id": "patient-1",
|
||||
"name": [{"family": "Test"}]
|
||||
}
|
||||
}]
|
||||
}
|
||||
input_file.write_text(json.dumps(test_bundle))
|
||||
|
||||
# Run conversion with short aliases
|
||||
result = self.runner.invoke(app, [
|
||||
"-i", str(input_file),
|
||||
"-o", str(tmp_path)
|
||||
])
|
||||
|
||||
# Should work the same as long form
|
||||
assert result.exit_code == 0
|
||||
|
||||
def test_cli_verbose_flag(self, tmp_path):
|
||||
"""Test verbose flag."""
|
||||
# Create test input
|
||||
input_file = tmp_path / "input.json"
|
||||
input_file.write_text('{"resourceType": "Bundle", "type": "collection", "entry": []}')
|
||||
|
||||
# Run with verbose flag (short form)
|
||||
result = self.runner.invoke(app, [
|
||||
"-i", str(input_file),
|
||||
"-o", str(tmp_path),
|
||||
"-v"
|
||||
])
|
||||
|
||||
# Verbose flag should not cause errors
|
||||
assert result.exit_code == 0 or result.exit_code == 1 # May exit with error for empty bundle
|
||||
|
||||
def test_cli_with_config_files(self, tmp_path):
|
||||
"""Test with configuration files."""
|
||||
# Create test input
|
||||
input_file = tmp_path / "input.json"
|
||||
input_file.write_text('{"resourceType": "Bundle", "type": "collection", "entry": []}')
|
||||
|
||||
# Create minimal config
|
||||
placeholder_cfg = tmp_path / "placeholder.json"
|
||||
placeholder_cfg.write_text(json.dumps({
|
||||
"rechnungsersteller": {"name": "Test", "plz": "12345", "ort": "Test", "strasse": "Test"},
|
||||
"leistungserbringer": {"vorname": "Dr.", "name": "Test"},
|
||||
"goziffer": {"go": "EBM", "ziffer": "99999", "datum": "2024-01-01"}
|
||||
}))
|
||||
|
||||
# Run with config
|
||||
result = self.runner.invoke(app, [
|
||||
"-i", str(input_file),
|
||||
"-o", str(tmp_path),
|
||||
"--placeholder-cfg", str(placeholder_cfg)
|
||||
])
|
||||
|
||||
# Should work (may warn about empty bundle but shouldn't crash)
|
||||
assert result.exit_code in [0, 1] # 0 for success, 1 for validation errors
|
||||
|
||||
def test_cli_shell_completion(self):
|
||||
"""Test that shell completion is available."""
|
||||
result = self.runner.invoke(app, ["--help"])
|
||||
assert result.exit_code == 0
|
||||
# Typer automatically adds these
|
||||
assert "--install-completion" in result.stdout
|
||||
assert "--show-completion" in result.stdout
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# RUN CONFIGURATION
|
||||
# ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user