Skip to content

Commit

Permalink
✅ Unit Test
Browse files Browse the repository at this point in the history
  • Loading branch information
mraniki committed Jul 7, 2024
1 parent c2a068b commit b654144
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 21 deletions.
31 changes: 21 additions & 10 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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%"

Expand Down Expand Up @@ -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
Expand All @@ -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


Expand All @@ -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)
Expand All @@ -141,16 +141,27 @@ 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"]
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 any(
record.message
== "No Client were created. Check your settings or disable the module."
for record in caplog.records
if record.levelname == "WARNING"
)
9 changes: 5 additions & 4 deletions tests/test_unit_exception
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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"
)


20 changes: 13 additions & 7 deletions tests/test_unit_format_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def fmo():


@pytest.fixture
def order_basic():
def order():
"""return valid order"""
return "Short ETH"

Expand Down Expand Up @@ -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)

0 comments on commit b654144

Please sign in to comment.