From b6541445656412509fad366df6371f1a0c277580 Mon Sep 17 00:00:00 2001 From: mraniki <8766259+mraniki@users.noreply.github.com> Date: Sun, 7 Jul 2024 06:36:41 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Unit=20Test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_unit.py | 31 +++++++++++++++++++++---------- tests/test_unit_exception | 9 +++++---- tests/test_unit_format_basic.py | 20 +++++++++++++------- 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/tests/test_unit.py b/tests/test_unit.py index b04de5c..1006e95 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -22,7 +22,7 @@ def fmo(): @pytest.fixture -def order_standard(): +def order(): """return valid order""" return "buy GOLD sl=200 tp=400 q=2%" @@ -78,10 +78,10 @@ async def test_info(fmo): @pytest.mark.asyncio -async def test_search_valid_order(fmo, order_standard): +async def test_search_valid_order(fmo, order): """Search Testing""" print(settings) - assert await fmo.search(order_standard) is True + assert await fmo.search(order) is True @pytest.mark.asyncio @@ -104,9 +104,9 @@ async def test_search_exception(fmo): @pytest.mark.asyncio -async def test_identify_order(fmo, order_standard): +async def test_identify_order(fmo, order): """Identify Testing""" - result = await fmo.identify_order(order_standard) + result = await fmo.identify_order(order) assert result is not None @@ -119,9 +119,9 @@ async def test_identify_order_invalid_input(fmo, invalid_order): @pytest.mark.asyncio -async def test_replace_instrument(fmo, order_standard, result_order): +async def test_replace_instrument(fmo, order, result_order): """replace instrument Testing""" - result = await fmo.get_order(order_standard) + result = await fmo.get_order(order) print(result) assert result["instrument"] == result_order["instrument"] assert type(result["timestamp"] is datetime) @@ -141,12 +141,12 @@ async def test_invalid_get_order(fmo, invalid_order): assert result is None -async def test_standard_get_order(fmo, order_standard, result_order): +async def test_standard_get_order(fmo, order, result_order): """get order Testing""" - result = await fmo.get_order(order_standard) + result = await fmo.get_order(order) print(result) assert result["action"] == result_order["action"] - # assert result["instrument"] == result_order["instrument"] + assert result["instrument"] == result_order["instrument"] assert int(result["stop_loss"]) == result_order["stop_loss"] assert int(result["take_profit"]) == result_order["take_profit"] assert int(result["quantity"]) == result_order["quantity"] @@ -154,3 +154,14 @@ async def test_standard_get_order(fmo, order_standard, result_order): assert result["leverage_type"] == result_order["leverage_type"] assert result["comment"] == result_order["comment"] assert type(result["timestamp"] is datetime) + + +async def test_create_client_exception(fmo, caplog): + result = fmo.create_client(parser_library="none") + assert result is not None + assert any( + record.message + == "No Client were created. Check your settings or disable the module." + for record in caplog.records + if record.levelname == "WARNING" + ) diff --git a/tests/test_unit_exception b/tests/test_unit_exception index 8ed629e..a634ccd 100644 --- a/tests/test_unit_exception +++ b/tests/test_unit_exception @@ -10,7 +10,7 @@ from findmyorder.config import settings @pytest.fixture(scope="session", autouse=True) def set_test_settings(): - settings.configure(FORCE_ENV_FOR_DYNACONF="fmo") + settings.configure(FORCE_ENV_FOR_DYNACONF="exception") @pytest.fixture(name="fmo") @@ -23,8 +23,9 @@ async def test_create_client_exception(fmo, caplog): result = fmo.create_client(parser_library="none") assert result is not None assert any( - record.message - == "No Client were created. Check your settings or disable the module." + record.message == "FindMyOrder is disabled. No Parser will be created." for record in caplog.records - if record.levelname == "WARNING" + if record.levelname == "INFO" ) + + diff --git a/tests/test_unit_format_basic.py b/tests/test_unit_format_basic.py index d6d5a59..d4b6b7d 100644 --- a/tests/test_unit_format_basic.py +++ b/tests/test_unit_format_basic.py @@ -22,7 +22,7 @@ def fmo(): @pytest.fixture -def order_basic(): +def order(): """return valid order""" return "Short ETH" @@ -51,11 +51,17 @@ async def test_settings(): @pytest.mark.asyncio -async def test_identify_order(fmo, order_basic, result_order): +async def test_identify_order(fmo, order, result_order): """Identify Testing""" - result = await fmo.identify_order(order_basic) + result = await fmo.identify_order(order) assert result is not None - # assert result["action"] == result_order["action"] - # assert result["instrument"] == result_order["instrument"] - # assert int(result["quantity"]) == 10 - #assert type(result["timestamp"] is datetime) + + +async def test_standard_get_order(fmo, order, result_order): + """get order Testing""" + result = await fmo.get_order(order) + print(result) + assert result["action"] == result_order["action"] + assert result["instrument"] == result_order["instrument"] + assert int(result["quantity"]) == result_order["quantity"] + assert type(result["timestamp"] is datetime)