From 9e70a504b430f1347f3e02e43c3f812282a218f7 Mon Sep 17 00:00:00 2001 From: mraniki <8766259+mraniki@users.noreply.github.com> Date: Sat, 6 Jul 2024 13:38:16 +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 | 144 ++++++-------------------------------- tests/test_unit_basic.py | 61 ++++++++++++++++ tests/test_unit_format.py | 131 ++++++++++++++++++++++++++++++++++ 3 files changed, 213 insertions(+), 123 deletions(-) create mode 100644 tests/test_unit_basic.py create mode 100644 tests/test_unit_format.py diff --git a/tests/test_unit.py b/tests/test_unit.py index e81c332..557eff5 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -21,65 +21,16 @@ def fmo(): return FindMyOrder() -@pytest.fixture -def order_basic(): - """return valid order""" - return "Buy EURUSD" - - -@pytest.fixture -def order_basic_crypto(): - """return valid order""" - return "Sell ETH" - - -@pytest.fixture -def ignore_order(): - """return order to ignore""" - return "buy DOGE" +async def test_create_client_exception(fmo, caplog): + result = fmo.create_client(parser_library="none") + assert result is not None + assert "No Client were created" in caplog.text @pytest.fixture def order_standard(): """return valid order""" - return "buy EURUSD sl=200 tp=400 q=2%" - - -@pytest.fixture -def order_standard_crypto(): - """return valid order""" - return "SHORT ETH sl=200 tp=400 q=2%" - - -@pytest.fixture -def order_format_2(): - """return order 2""" - return """ - 📊 FUTURES Exchanges: Binance, ByBit USDT - - #AAVEUSDT - - 🟢LONG ENTRY :- 65.20 - 63.70 - - Leverage: Cross (2X) - - 👇TAKE PROFIT - - 1) 65.70 - 2) 66.20 - 3) 66.70 - - Stop Loss : - 62.00 -""" - - -@pytest.fixture -def order_format_3(): - """return emoji type order""" - return """⚡️⚡️ #BNB/USDT ⚡️⚡️ - Exchanges: ByBit USDT, Binance Futures - Signal Type: Regular (Long) - Leverage: Cross (20.0X)""" + return "buy GOLD sl=200 tp=400 q=2%" @pytest.fixture @@ -87,7 +38,7 @@ def result_order(): """return standard expected results""" return { "action": "BUY", - "instrument": "EURUSD", + "instrument": "XAUUSD", "stop_loss": 200, "take_profit": 400, "quantity": 2, @@ -99,24 +50,9 @@ def result_order(): @pytest.fixture -def result_crypto_order(): - """return standard expected results""" - return { - "action": "SHORT", - "instrument": "WETH", - "stop_loss": 1000, - "take_profit": 1000, - "quantity": 10, - "order_type": None, - "leverage_type": None, - "comment": None, - "timestamp": datetime.now(), - } - - -@pytest.fixture -def bot_command(): - return "/bal" +def ignore_order(): + """return order to ignore""" + return "buy DOGE" @pytest.fixture @@ -125,6 +61,11 @@ def invalid_order(): return "This is not an order" +@pytest.fixture +def bot_command(): + return "/bal" + + @pytest.mark.asyncio async def test_settings(): """Search Testing""" @@ -143,16 +84,10 @@ async def test_info(fmo): @pytest.mark.asyncio -async def test_search_valid_order(fmo, order_standard_crypto): +async def test_search_valid_order(fmo, order_standard): """Search Testing""" print(settings) - assert await fmo.search(order_standard_crypto) is True - - -@pytest.mark.asyncio -async def test_search_normal_order_variation(fmo, order_standard_crypto): - """Search Testing""" - assert await fmo.search(order_standard_crypto) is True + assert await fmo.search(order_standard) is True @pytest.mark.asyncio @@ -173,17 +108,10 @@ async def test_search_exception(fmo): mystring = "" assert await fmo.search(mystring) is False - @pytest.mark.asyncio -async def test_search_standard_order(fmo, order_standard): - """Search Testing""" - assert await fmo.search(order_standard) is True - - -@pytest.mark.asyncio -async def test_identify_order(fmo, order_basic): +async def test_identify_order(fmo, order_standard): """Identify Testing""" - result = await fmo.identify_order(order_basic) + result = await fmo.identify_order(order_standard) assert result is not None @@ -196,25 +124,11 @@ async def test_identify_order_invalid_input(fmo, invalid_order): @pytest.mark.asyncio -async def test_identify_order_2(fmo, order_format_2): - """Identify Testing""" - result = await fmo.identify_order(order_format_2) - assert result is None - - -@pytest.mark.asyncio -async def test_identify_order_3(fmo, order_format_3): - """Identify Testing""" - result = await fmo.identify_order(order_format_3) - assert result is None - - -@pytest.mark.asyncio -async def test_replace_instrument(fmo, order_basic_crypto, result_crypto_order): +async def test_replace_instrument(fmo, order_standard, result_order): """replace instrument Testing""" - result = await fmo.get_order(order_basic_crypto) + result = await fmo.get_order(order_standard) print(result) - assert result["instrument"] == result_crypto_order["instrument"] + assert result["instrument"] == result_order["instrument"] assert type(result["timestamp"] is datetime) @@ -232,16 +146,6 @@ async def test_invalid_get_order(fmo, invalid_order): assert result is None -@pytest.mark.asyncio -async def test_basic_valid_get_order(fmo, order_basic, result_order): - """get order Testing""" - result = await fmo.get_order(order_basic) - assert result["action"] == result_order["action"] - assert result["instrument"] == result_order["instrument"] - assert int(result["quantity"]) == 1 - assert type(result["timestamp"] is datetime) - - async def test_standard_get_order(fmo, order_standard, result_order): """get order Testing""" result = await fmo.get_order(order_standard) @@ -255,9 +159,3 @@ 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 "No Client were created" in caplog.text diff --git a/tests/test_unit_basic.py b/tests/test_unit_basic.py new file mode 100644 index 0000000..e012abb --- /dev/null +++ b/tests/test_unit_basic.py @@ -0,0 +1,61 @@ +""" +FindMyOrder Unit Testing +""" + +from datetime import datetime + +import pytest + +from findmyorder import FindMyOrder +from findmyorder.config import settings + + +@pytest.fixture(scope="session", autouse=True) +def set_test_settings(): + settings.configure(FORCE_ENV_FOR_DYNACONF="basic") + + +@pytest.fixture(name="fmo") +def fmo(): + """return fmo""" + return FindMyOrder() + + +@pytest.fixture +def order_basic(): + """return valid order""" + return "Sell ETH" + + +@pytest.fixture +def result_order(): + """return standard expected results""" + return { + "action": "SHORT", + "instrument": "WETH", + "stop_loss": 1000, + "take_profit": 1000, + "quantity": 10, + "order_type": None, + "leverage_type": None, + "comment": None, + "timestamp": datetime.now(), + } + + +@pytest.mark.asyncio +async def test_settings(): + """Search Testing""" + assert settings.VALUE == "On Testing" + assert settings.findmyorder_enabled is True + + +@pytest.mark.asyncio +async def test_identify_order(fmo, order_basic): + """Identify Testing""" + result = await fmo.identify_order(order_basic) + 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) diff --git a/tests/test_unit_format.py b/tests/test_unit_format.py new file mode 100644 index 0000000..66715d9 --- /dev/null +++ b/tests/test_unit_format.py @@ -0,0 +1,131 @@ +# """ +# FindMyOrder Unit Testing +# """ + +# from datetime import datetime + +# import pytest + +# from findmyorder import FindMyOrder +# from findmyorder.config import settings + + +# @pytest.fixture(scope="session", autouse=True) +# def set_test_settings(): +# settings.configure(FORCE_ENV_FOR_DYNACONF="fmo") + + +# @pytest.fixture(name="fmo") +# def fmo(): +# """return fmo""" +# return FindMyOrder() + + +# @pytest.fixture +# def order_format_2(): +# """return order 2""" +# return """ +# 📊 FUTURES Exchanges: Binance, ByBit USDT + +# #AAVEUSDT + +# 🟢LONG ENTRY :- 65.20 - 63.70 + +# Leverage: Cross (2X) + +# 👇TAKE PROFIT + +# 1) 65.70 +# 2) 66.20 +# 3) 66.70 + +# Stop Loss : - 62.00 +# """ + + +# @pytest.fixture +# def order_format_3(): +# """return emoji type order""" +# return """⚡️⚡️ #BNB/USDT ⚡️⚡️ +# Exchanges: ByBit USDT, Binance Futures +# Signal Type: Regular (Long) +# Leverage: Cross (20.0X)""" + + +# @pytest.fixture +# def result_order(): +# """return standard expected results""" +# return { +# "action": "BUY", +# "instrument": "EURUSD", +# "stop_loss": 200, +# "take_profit": 400, +# "quantity": 2, +# "order_type": None, +# "leverage_type": None, +# "comment": None, +# "timestamp": datetime.now(), +# } + +# @pytest.mark.asyncio +# async def test_settings(): +# """Search Testing""" +# assert settings.VALUE == "On Testing" +# assert settings.findmyorder_enabled is True + +# @pytest.mark.asyncio +# async def test_identify_order_2(fmo, order_format_2): +# """Identify Testing""" +# result = await fmo.identify_order(order_format_2) +# assert result is None + + +# @pytest.mark.asyncio +# async def test_identify_order_3(fmo, order_format_3): +# """Identify Testing""" +# result = await fmo.identify_order(order_format_3) +# assert result is None + + +# @pytest.mark.asyncio +# async def test_identify_order_2(fmo, order_format_2): +# """Identify Testing""" +# result = await fmo.identify_order(order_format_2) +# assert result is None + + +# @pytest.mark.asyncio +# async def test_identify_order_3(fmo, order_format_3): +# """Identify Testing""" +# result = await fmo.identify_order(order_format_3) +# assert result is None + +# @pytest.mark.asyncio +# async def test_basic_valid_get_order(fmo, order_basic, result_order): +# """get order Testing""" +# result = await fmo.get_order(order_basic) +# assert result["action"] == result_order["action"] +# assert result["instrument"] == result_order["instrument"] +# assert int(result["quantity"]) == 1 +# assert type(result["timestamp"] is datetime) + + +# async def test_standard_get_order(fmo, order_standard, result_order): +# """get order Testing""" +# result = await fmo.get_order(order_standard) +# print(result) +# assert result["action"] == result_order["action"] +# 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"] +# assert result["order_type"] == result_order["order_type"] +# 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 "No Client were created" in caplog.text