Skip to content
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'origin/release/version_0.4.1' into dev/…
…BROK-653

# Conflicts:
#	test/unit/okx/websocket/test_ws_private_async.py
#	test/unit/okx/websocket/test_ws_public_async.py
  • Loading branch information
zihao.jiang
zihao.jiang committed Dec 22, 2025
commit 3f53945104333975fbaeebd2c312f8eba3cc70a5
32 changes: 15 additions & 17 deletions test/unit/okx/websocket/test_ws_private_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ class TestWsPrivateAsyncInit(unittest.TestCase):
"""Unit tests for WsPrivateAsync initialization"""

def test_init_with_required_params(self):
"""Test initialization with required parameters only"""
with patch('okx.websocket.WsPrivateAsync.WebSocketFactory') as mock_factory:
from okx.websocket.WsPrivateAsync import WsPrivateAsync
"""Test initialization with required parameters"""
with patch.object(ws_private_module, 'WebSocketFactory') as mock_factory:
ws = WsPrivateAsync(
apiKey="test_api_key",
passphrase="test_passphrase",
Expand Down Expand Up @@ -91,14 +90,14 @@ def test_init_without_useServerTime_no_warning(self):
class TestWsPrivateAsyncSubscribe(unittest.TestCase):
"""Unit tests for WsPrivateAsync subscribe method"""

def test_subscribe_without_id(self):
"""Test subscribe without id parameter"""
with patch('okx.websocket.WsPrivateAsync.WebSocketFactory'), \
patch('okx.websocket.WsPrivateAsync.WsUtils.initLoginParams') as mock_init_login, \
patch('okx.websocket.WsPrivateAsync.asyncio.sleep', new_callable=AsyncMock):
def test_subscribe_sends_correct_payload(self):
"""Test subscribe sends correct payload after login"""
with patch.object(ws_private_module, 'WebSocketFactory'), \
patch.object(ws_private_module, 'WsUtils') as mock_ws_utils, \
patch.object(ws_private_module.asyncio, 'sleep', new_callable=AsyncMock):

mock_ws_utils.initLoginParams.return_value = '{"op":"login"}'

ws = WsPrivateAsync(
apiKey="test_api_key",
passphrase="test_passphrase",
Expand Down Expand Up @@ -155,10 +154,9 @@ async def run_test():
class TestWsPrivateAsyncUnsubscribe(unittest.TestCase):
"""Unit tests for WsPrivateAsync unsubscribe method"""

def test_unsubscribe_without_id(self):
"""Test unsubscribe without id parameter"""
with patch('okx.websocket.WsPrivateAsync.WebSocketFactory'):
from okx.websocket.WsPrivateAsync import WsPrivateAsync
def test_unsubscribe_sends_correct_payload(self):
"""Test unsubscribe sends correct payload"""
with patch.object(ws_private_module, 'WebSocketFactory'):
ws = WsPrivateAsync(
apiKey="test_api_key",
passphrase="test_passphrase",
Expand Down Expand Up @@ -533,7 +531,7 @@ def test_login_calls_init_login_params(self):
patch.object(ws_private_module, 'WsUtils') as mock_ws_utils:

mock_ws_utils.initLoginParams.return_value = '{"op":"login","args":[...]}'

ws = WsPrivateAsync(
apiKey="test_api_key",
passphrase="test_passphrase",
Expand All @@ -546,8 +544,8 @@ def test_login_calls_init_login_params(self):
async def run_test():
result = await ws.login()
self.assertTrue(result)
mock_init_login.assert_called_once_with(
useServerTime=False,
mock_ws_utils.initLoginParams.assert_called_once_with(
useServerTime=True,
apiKey="test_api_key",
passphrase="test_passphrase",
secretKey="test_secret_key"
Expand All @@ -561,7 +559,7 @@ class TestWsPrivateAsyncStartStop(unittest.TestCase):

def test_stop(self):
"""Test stop method closes the factory"""
with patch('okx.websocket.WsPrivateAsync.WebSocketFactory') as mock_factory_class:
with patch.object(ws_private_module, 'WebSocketFactory') as mock_factory_class:
mock_factory_instance = MagicMock()
mock_factory_instance.close = AsyncMock()
mock_factory_class.return_value = mock_factory_instance
Expand Down
10 changes: 6 additions & 4 deletions test/unit/okx/websocket/test_ws_public_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
class TestWsPublicAsyncInit(unittest.TestCase):
"""Unit tests for WsPublicAsync initialization"""

def test_init_with_url_only(self):
"""Test initialization with only url parameter"""
with patch('okx.websocket.WsPublicAsync.WebSocketFactory'):
from okx.websocket.WsPublicAsync import WsPublicAsync
def test_init_with_url(self):
"""Test initialization with url parameter"""
with patch.object(ws_public_module, 'WebSocketFactory') as mock_factory:
ws = WsPublicAsync(url="wss://test.example.com")

self.assertEqual(ws.url, "wss://test.example.com")
Expand Down Expand Up @@ -112,6 +111,9 @@ async def run_test():
class TestWsPublicAsyncSubscribe(unittest.TestCase):
"""Unit tests for WsPublicAsync subscribe method"""

def test_subscribe_sets_callback(self):
"""Test subscribe sets callback correctly"""
with patch.object(ws_public_module, 'WebSocketFactory'):
def test_subscribe_without_id(self):
"""Test subscribe without id parameter"""
with patch('okx.websocket.WsPublicAsync.WebSocketFactory'):
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.