Skip to content

Commit

Permalink
✅ Unit Test
Browse files Browse the repository at this point in the history
  • Loading branch information
mraniki committed Jul 6, 2024
1 parent d6ba261 commit 9e70a50
Show file tree
Hide file tree
Showing 3 changed files with 213 additions and 123 deletions.
144 changes: 21 additions & 123 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,73 +21,24 @@ 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
def result_order():
"""return standard expected results"""
return {
"action": "BUY",
"instrument": "EURUSD",
"instrument": "XAUUSD",
"stop_loss": 200,
"take_profit": 400,
"quantity": 2,
Expand All @@ -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
Expand All @@ -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"""
Expand All @@ -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
Expand All @@ -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


Expand All @@ -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)


Expand All @@ -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)
Expand All @@ -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
61 changes: 61 additions & 0 deletions tests/test_unit_basic.py
Original file line number Diff line number Diff line change
@@ -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)
Loading

0 comments on commit 9e70a50

Please sign in to comment.