Skip to content

Commit

Permalink
修改单元测试方法
Browse files Browse the repository at this point in the history
  • Loading branch information
feiazifeiazi committed Sep 20, 2024
1 parent caba31d commit 3001ee3
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions sql/engines/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1840,16 +1840,24 @@ def test_fill_query_columns(self):

@patch("sql.engines.mongo.MongoEngine.get_connection")
def test_current_op(self, mock_get_connection):
class Aggregate:
def __enter__(self):
yield {"client": "single_client"}
yield {"clientMetadata": {"mongos": {"client": "sharding_client"}}}

def __exit__(self, *arg, **kwargs):
pass

mock_conn = Mock()
mock_conn.admin.aggregate.return_value = Aggregate()
# 模拟 cursor 返回的 operation 列表
mock_cursor = [
{
"client": "single_client",
"effectiveUsers": [{"user": "user_1"}],
"clientMetadata": {"mongos": {"client": "sharding_client"}},
},
{
"clientMetadata": {"mongos": {}},
"effectiveUsers": [{"user": "user_2"}],
},
{
"effectiveUsers": [],
},
]

mock_conn.admin.aggregate.return_value = mock_cursor
mock_get_connection.return_value = mock_conn
command_types = ["Full", "All", "Inner", "Active"]
for command_type in command_types:
Expand Down

0 comments on commit 3001ee3

Please sign in to comment.