🐛 config 中添加 clear_db 方法,用于清空数据库内容;添加clear_db fixture,用于在单测前后清空数据库

This commit is contained in:
2024-09-28 16:49:10 +08:00
parent aa897939d9
commit 1d1b9f6574
5 changed files with 89 additions and 62 deletions
+11
View File
@@ -363,5 +363,16 @@ class DBConfig:
res.sort(key=lambda x: (x.target.platform_name, x.cookie_id, x.target_id))
return res
async def clear_db(self):
"""清空数据库"""
async with create_session() as sess:
await sess.execute(delete(User))
await sess.execute(delete(Target))
await sess.execute(delete(ScheduleTimeWeight))
await sess.execute(delete(Subscribe))
await sess.execute(delete(Cookie))
await sess.execute(delete(CookieTarget))
await sess.commit()
config = DBConfig()