44
55import asyncio
66import json
7+
78from app import app
89
10+
911async def test_routes ():
1012 """Test basic route accessibility"""
1113 print ("🧪 Testing FlowerPower Web UI Routes" )
1214 print ("=" * 40 )
13-
15+
1416 # Create test client
1517 request , response = await app .asgi_client .get ("/" )
1618 assert response .status == 200
1719 assert "FlowerPower" in response .text
1820 print ("✅ Home page loads correctly" )
19-
21+
2022 # Test projects list
2123 request , response = await app .asgi_client .get ("/projects" )
2224 assert response .status == 200
2325 assert "Projects" in response .text
2426 print ("✅ Projects page loads correctly" )
25-
27+
2628 # Test new project form
2729 request , response = await app .asgi_client .get ("/projects/new" )
2830 assert response .status == 200
2931 assert "Create New Project" in response .text
3032 print ("✅ New project form loads correctly" )
31-
33+
3234 # Test API endpoint
3335 request , response = await app .asgi_client .get ("/api/projects" )
3436 assert response .status == 200
3537 data = json .loads (response .text )
3638 assert "projects" in data
3739 print ("✅ API endpoint works correctly" )
38-
40+
3941 # Test project detail
4042 request , response = await app .asgi_client .get ("/projects/1" )
4143 assert response .status == 200
4244 print ("✅ Project detail page loads correctly" )
43-
45+
4446 # Test non-existent project
4547 request , response = await app .asgi_client .get ("/projects/999" )
4648 assert response .status == 200
4749 assert "Project Not Found" in response .text
4850 print ("✅ 404 handling works correctly" )
49-
51+
5052 print ("\n 🎉 All tests passed!" )
5153
54+
5255async def test_project_creation ():
5356 """Test project creation via form submission"""
5457 print ("\n 🧪 Testing Project Creation" )
5558 print ("=" * 30 )
56-
59+
5760 # Test valid project creation
58- form_data = {
59- "name" : "Test Project" ,
60- "description" : "A test project for validation"
61- }
62-
61+ form_data = {"name" : "Test Project" , "description" : "A test project for validation" }
62+
6363 request , response = await app .asgi_client .post ("/projects" , data = form_data )
6464 assert response .status == 200
6565 data = json .loads (response .text )
6666 assert data ["status" ] == "success"
6767 print ("✅ Project creation works correctly" )
68-
68+
6969 # Test empty name validation
70- form_data = {
71- "name" : "" ,
72- "description" : "Project with empty name"
73- }
74-
70+ form_data = {"name" : "" , "description" : "Project with empty name" }
71+
7572 request , response = await app .asgi_client .post ("/projects" , data = form_data )
7673 assert response .status == 200
7774 data = json .loads (response .text )
7875 assert data ["status" ] == "error"
7976 print ("✅ Empty name validation works correctly" )
80-
77+
8178 print ("\n 🎉 Project creation tests passed!" )
8279
80+
8381def test_template_generation ():
8482 """Test htpy template generation"""
8583 print ("\n 🧪 Testing Template Generation" )
8684 print ("=" * 30 )
87-
85+
8886 from app import base_layout , project_card
8987 from htpy import html as h
90-
88+
9189 # Test base layout
9290 content = h .div ("Test content" )
9391 layout = base_layout ("Test Page" , content )
9492 assert "Test Page - FlowerPower" in layout
9593 assert "Test content" in layout
9694 assert "data-ds-stream" in layout
9795 print ("✅ Base layout generation works correctly" )
98-
96+
9997 # Test project card
10098 test_project = {
10199 "id" : 1 ,
102100 "name" : "Test Project" ,
103101 "description" : "Test description" ,
104- "created_at" : "2025-01-23T12:00:00Z"
102+ "created_at" : "2025-01-23T12:00:00Z" ,
105103 }
106-
104+
107105 card_html = str (project_card (test_project ))
108106 assert "Test Project" in card_html
109107 assert "Test description" in card_html
110108 assert "2025-01-23" in card_html
111109 print ("✅ Project card generation works correctly" )
112-
110+
113111 print ("\n 🎉 Template generation tests passed!" )
114112
113+
115114async def main ():
116115 """Run all tests"""
117116 try :
118117 test_template_generation ()
119118 await test_routes ()
120119 await test_project_creation ()
121-
120+
122121 print ("\n " + "=" * 50 )
123122 print ("🎉 All FlowerPower Web UI tests passed!" )
124123 print ("✨ Application is ready for deployment" )
125-
124+
126125 except Exception as e :
127126 print (f"\n ❌ Test failed: { e } " )
128127 raise
129128
129+
130130if __name__ == "__main__" :
131- asyncio .run (main ())
131+ asyncio .run (main ())
0 commit comments