jira-webhook-llm/tests/test_llm_validation.py
Ireneusz Bachanowicz 2763b40b60
Some checks are pending
CI/CD Pipeline / test (push) Waiting to run
Refactor Jira Webhook LLM integration
- Simplified the FastAPI application structure and improved error handling with middleware.
- Introduced a retry decorator for asynchronous functions to enhance reliability.
- Modularized the LLM initialization and prompt loading into separate functions for better maintainability.
- Updated Pydantic models for Jira webhook payload and analysis flags to ensure proper validation and structure.
- Implemented a structured logging configuration for better traceability and debugging.
- Added comprehensive unit tests for prompt loading, response validation, and webhook handling.
- Established a CI/CD pipeline with GitHub Actions for automated testing and coverage reporting.
- Enhanced the prompt template for LLM analysis to include specific instructions for handling escalations.
2025-07-13 13:19:10 +02:00

34 lines
1.3 KiB
Python

import pytest
from fastapi.testclient import TestClient
from jira_webhook_llm import app
from llm.models import JiraWebhookPayload
def test_llm_response_format(test_client, mock_jira_payload):
response = test_client.post("/jira-webhook", json=mock_jira_payload)
assert response.status_code == 200
response_data = response.json()
# Validate response structure
assert "response" in response_data
assert "analysis" in response_data["response"]
assert "recommendations" in response_data["response"]
assert "status" in response_data["response"]
def test_llm_response_content_validation(test_client, mock_jira_payload):
response = test_client.post("/jira-webhook", json=mock_jira_payload)
response_data = response.json()
# Validate content types
assert isinstance(response_data["response"]["analysis"], str)
assert isinstance(response_data["response"]["recommendations"], list)
assert isinstance(response_data["response"]["status"], str)
def test_llm_error_handling(test_client):
# Test with invalid payload
invalid_payload = {"invalid": "data"}
response = test_client.post("/jira-webhook", json=invalid_payload)
assert response.status_code == 422
# Test with empty payload
response = test_client.post("/jira-webhook", json={})
assert response.status_code == 422