Model-config web apps: describe the app in configuration instead of writing code. Built on Polars and DuckDB.
test_validate_email.py · 2.4 KB · 74 lines
| 1 | |
| 2 | #!/usr/bin/env python3 |
| 3 | """ |
| 4 | AI-Generated Tests for Service: validate-email |
| 5 | Description: Validate email addresses and check format compliance |
| 6 | Generated: 2025-09-19T16:21:11.092445 |
| 7 | """ |
| 8 | |
| 9 | import pytest |
| 10 | import asyncio |
| 11 | import sys |
| 12 | from pathlib import Path |
| 13 | |
| 14 | # Add services directory to path |
| 15 | sys.path.insert(0, str(Path(__file__).parent.parent / "services")) |
| 16 | |
| 17 | from validate_email import validate_email, validate_email_sync |
| 18 | |
| 19 | class TestValidateEmail: |
| 20 | """Test cases for validate_email service""" |
| 21 | |
| 22 | def test_basic_functionality_sync(self): |
| 23 | """Test basic functionality with synchronous wrapper""" |
| 24 | test_data = {"email": "test@example.com", "subject": "Test", "message": "Hello"} |
| 25 | result = validate_email_sync(test_data) |
| 26 | |
| 27 | assert result["success"] is True |
| 28 | assert "data" in result |
| 29 | assert "timestamp" in result |
| 30 | |
| 31 | @pytest.mark.asyncio |
| 32 | async def test_basic_functionality_async(self): |
| 33 | """Test basic functionality with async function""" |
| 34 | test_data = {"email": "test@example.com", "subject": "Test", "message": "Hello"} |
| 35 | result = await validate_email(test_data) |
| 36 | |
| 37 | assert result["success"] is True |
| 38 | assert "data" in result |
| 39 | assert "timestamp" in result |
| 40 | |
| 41 | def test_invalid_input(self): |
| 42 | """Test handling of invalid input""" |
| 43 | test_data = {} # Empty input |
| 44 | result = validate_email_sync(test_data) |
| 45 | |
| 46 | # Should either succeed with defaults or return error |
| 47 | assert "success" in result |
| 48 | assert "timestamp" in result |
| 49 | |
| 50 | def test_edge_cases(self): |
| 51 | """Test edge case scenarios""" |
| 52 | edge_cases = [ |
| 53 | {"email": "user@domain.co.uk", "subject": "", "message": "Short"}, |
| 54 | {"email": "long.email.address@very-long-domain-name.com", "subject": "Very long subject line", "message": "A" * 1000} |
| 55 | ] |
| 56 | |
| 57 | for test_data in edge_cases: |
| 58 | result = validate_email_sync(test_data) |
| 59 | assert "success" in result |
| 60 | assert "timestamp" in result |
| 61 | |
| 62 | @pytest.mark.asyncio |
| 63 | async def test_error_handling(self): |
| 64 | """Test error handling with malformed data""" |
| 65 | malformed_data = {"invalid": "data", "nested": {"bad": None}} |
| 66 | result = await validate_email(malformed_data) |
| 67 | |
| 68 | # Should gracefully handle errors |
| 69 | assert "success" in result |
| 70 | assert "timestamp" in result |
| 71 | |
| 72 | if __name__ == "__main__": |
| 73 | # Run tests directly |
| 74 | pytest.main([__file__, "-v"]) |