调整版本并做测试
This commit is contained in:
86
test_user_scenario.py
Normal file
86
test_user_scenario.py
Normal file
@@ -0,0 +1,86 @@
|
||||
#!/usr/bin/env python3.9
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Test the exact user scenario with real data and template
|
||||
"""
|
||||
|
||||
import os
|
||||
from pyenjoy.template.Engine import Engine
|
||||
from pyenjoy.kit.Kv import Kv
|
||||
|
||||
def test_user_scenario():
|
||||
"""Test the exact user scenario"""
|
||||
print("Testing user scenario...")
|
||||
|
||||
# User's data
|
||||
data = {
|
||||
'items': [
|
||||
{
|
||||
'id': 'wiwInpwBRcYlH5JfMuby',
|
||||
'title': 'CDMS 内容数据管理系统2',
|
||||
'content': 'CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统',
|
||||
'tags': ['cdms', ' 管理系统'],
|
||||
'author': '赵钱孙',
|
||||
'create_time': '2026-02-27T15:37:43.207513',
|
||||
'update_time': '2026-02-27T15:37:43.207530',
|
||||
'status': 'active'
|
||||
},
|
||||
{
|
||||
'id': 'wSwHnpwBRcYlH5Jf7-Zd',
|
||||
'title': 'CDMS 内容数据管理系统',
|
||||
'content': 'CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统CDMS 内容数据管理系统',
|
||||
'tags': ['cdms', ' 管理系统'],
|
||||
'author': '赵钱孙',
|
||||
'create_time': '2026-02-27T15:37:25.907558',
|
||||
'update_time': '2026-02-27T15:37:25.907576',
|
||||
'status': 'active'
|
||||
}
|
||||
],
|
||||
'total': 2,
|
||||
'page': 1,
|
||||
'size': 10,
|
||||
'pages': 1
|
||||
}
|
||||
|
||||
# User's template
|
||||
template_content = """
|
||||
#for(item in data.items)
|
||||
<tr>
|
||||
<td>#(item.id)</td>
|
||||
<td>#(item.title)</td>
|
||||
<td>#(item.author)</td>
|
||||
<td>#(item.tags | join(", "))</td>
|
||||
<td>#(item.create_time)</td>
|
||||
<td>
|
||||
</td>
|
||||
</tr>
|
||||
#end
|
||||
"""
|
||||
|
||||
# Create engine and test
|
||||
engine = Engine.use()
|
||||
|
||||
try:
|
||||
template = engine.get_template_by_string(template_content)
|
||||
result = template.render_to_string(Kv({"data": data}))
|
||||
|
||||
print("\nTemplate rendering result:")
|
||||
print("=" * 50)
|
||||
print(result)
|
||||
print("=" * 50)
|
||||
print("\n✓ User scenario test passed!")
|
||||
|
||||
# Verify the join filter worked correctly
|
||||
if "cdms, 管理系统" in result:
|
||||
print("✓ Join filter worked correctly!")
|
||||
else:
|
||||
print("✗ Join filter did not work as expected")
|
||||
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"\n✗ User scenario test failed: {e}")
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
success = test_user_scenario()
|
||||
exit(0 if success else 1)
|
||||
Reference in New Issue
Block a user