Skip to content

Commit

Permalink
test_get_all_tables_exception
Browse files Browse the repository at this point in the history
  • Loading branch information
feiazifeiazi committed Dec 27, 2024
1 parent a6b8497 commit f5e19bd
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions sql/engines/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,33 @@ def test_get_all_databases_with_less_than_15_dbs(self, mock_config_get, mock_inf
mock_config_get.assert_called_once_with("databases")
mock_info.assert_called_once_with("Keyspace")

@patch(
"redis.Redis.scan_iter", return_value=["table1", "table2", "table3", "table4"]
)
def test_get_all_tables_success(self, _scan_iter):
# 创建 RedisEngine 实例
new_engine = RedisEngine(instance=self.ins)

# 调用 get_all_tables 方法
db_name = "4"
result = new_engine.get_all_tables(db_name)
mask_result_rows = ["table1", "table2", "table3", "table4"]
# 验证返回的表格信息
self.assertEqual(result.rows, mask_result_rows)

@patch("redis.Redis.scan_iter", side_effect=Exception("Test Exception"))
def test_get_all_tables_exception(self, _scan_iter):
# 创建 RedisEngine 实例
new_engine = RedisEngine(instance=self.ins)

# 调用 get_all_tables 方法并模拟异常
db_name = "4"
result = new_engine.get_all_tables(db_name)

# 验证返回的异常信息
self.assertEqual(result.rows, [])
self.assertIn(result.message, "Test Exception")

def test_query_check_safe_cmd(self):
safe_cmd = "keys 1*"
new_engine = RedisEngine(instance=self.ins)
Expand Down

0 comments on commit f5e19bd

Please # to comment.