From b1af6b21fb97f736d0f7be7200610186bdba8f75 Mon Sep 17 00:00:00 2001 From: rcholic Date: Thu, 27 Jun 2024 18:06:40 -0700 Subject: [PATCH] test cancel orders --- tests/test_models.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/test_models.py b/tests/test_models.py index 95d77c3..e6bca15 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -234,6 +234,44 @@ async def test_place_order(httpx_mock: HTTPXMock): assert new_order_id2 == order_id +@pytest.mark.asyncio +async def test_cancel_order(httpx_mock: HTTPXMock): + mocked_token = mock_tokens() + token_store = LocalTokenStore() + if os.path.exists(Path(token_store.token_output_path)): + os.remove(token_store.token_output_path) # clean up before test + + order_id = 1000847830245 + token_store.save_tokens(mocked_token) + httpx_mock.add_response(status_code=200) + async with httpx.AsyncClient() as client: + cschwab_client = SchwabAsyncClient( + app_client_id="fake_id", + app_secret="fake_secret", + token_store=token_store, + tokens=mocked_token, + http_client=client, + ) + is_canceled = await cschwab_client.cancel_order_async( + account_number_hash=mock_account(), order_id=order_id + ) + assert is_canceled + + with httpx.Client() as client2: + cschwab_client = SchwabClient( + app_client_id="fake_id", + app_secret="fake_secret", + token_store=token_store, + http_client=client2, + ) + + is_canceled2 = cschwab_client.cancel_order( + account_number_hash=mock_account(), + order_id=order_id, + ) + assert is_canceled2 + + @pytest.mark.asyncio async def test_get_order_by_id(httpx_mock: HTTPXMock): json_mock = get_mock_response()["filled_order"]