You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
"""
无人机决策系统 - 数据库模块单元测试
作者:刘宇杰
日期: 2025-07-13
功能说明:
本文件使用unittest对数据库管理模块的主要接口进行单元测试, 包括分析记录、打击计划、用户相关操作的增删查。
"""
import unittest
from utils . database import DatabaseManager
class TestDatabaseManager ( unittest . TestCase ) :
def setUp ( self ) :
self . db = DatabaseManager ( )
def test_add_and_get_analysis_record ( self ) :
record_id = self . db . add_analysis_record ( ' text ' , ' test.txt ' , { ' result ' : ' ok ' } )
self . assertIsInstance ( record_id , int )
records = self . db . get_records ( )
self . assertIsInstance ( records , list )
def test_add_and_get_strike_plan ( self ) :
plan_id = self . db . add_strike_plan ( 1 , { ' plan ' : ' test ' } )
self . assertIsInstance ( plan_id , int )
plans = self . db . get_user_plans ( 1 )
self . assertIsInstance ( plans , list )
def test_get_user ( self ) :
user = self . db . get_user ( ' testuser ' )
self . assertIsInstance ( user , dict )
def test_add_user ( self ) :
result = self . db . add_user ( ' testuser ' , ' hash ' )
self . assertTrue ( result )
if __name__ == ' __main__ ' :
unittest . main ( )