askrobots / dbbasic Public

Model-config web apps: describe the app in configuration instead of writing code. Built on Polars and DuckDB.

0 downloads

dbbasic/tests/test_validate_email.py
Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 Add DBBasic crate engine logo and update README 0d628db 1 year, 2 months ago History
test_validate_email.py · 2.4 KB · 74 lines
1
2#!/usr/bin/env python3
3"""
4AI-Generated Tests for Service: validate-email
5Description: Validate email addresses and check format compliance
6Generated: 2025-09-19T16:21:11.092445
7"""
8
9import pytest
10import asyncio
11import sys
12from pathlib import Path
13
14# Add services directory to path
15sys.path.insert(0, str(Path(__file__).parent.parent / "services"))
16
17from validate_email import validate_email, validate_email_sync
18
19class 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
72if __name__ == "__main__":
73 # Run tests directly
74 pytest.main([__file__, "-v"])