From ea9b57f9872a008c8e829ad9ff4ef2f1396157c7 Mon Sep 17 00:00:00 2001 From: mraniki Date: Tue, 11 Jul 2023 19:05:00 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=A5=9Aignore=5Finstrument=20=20settin?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- findmyorder/default_settings.toml | 2 +- findmyorder/main.py | 3 +++ tests/test_unit.py | 12 ++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/findmyorder/default_settings.toml b/findmyorder/default_settings.toml index bcdfbd1f..cf4743bd 100644 --- a/findmyorder/default_settings.toml +++ b/findmyorder/default_settings.toml @@ -33,7 +33,7 @@ mapping = [ { id = "BTC", alt = "WBTC" }, { id = "ETH", alt = "WETH" }, ] - +ignore_instrument = "US500 USTEC DOGE" [testing] diff --git a/findmyorder/main.py b/findmyorder/main.py index 1231637e..46048c89 100644 --- a/findmyorder/main.py +++ b/findmyorder/main.py @@ -105,6 +105,9 @@ async def get_order( print(settings.instrument_mapping) if settings.instrument_mapping: await self.replace_instrument(order) + if order["instrument"] in settings.ignore_instrument: + """ ignoring instrument""" + return return order return None diff --git a/tests/test_unit.py b/tests/test_unit.py index ee43411d..a9a76b6c 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -45,6 +45,10 @@ def result_order(): "timestamp": datetime.now() } +@pytest.fixture +def ignore_order(): + """return valid order""" + return "buy US500" @pytest.fixture def crypto_order(): @@ -173,6 +177,14 @@ async def test_short_valid_get_order(fmo, short_order, result_order): assert int(result["quantity"]) == 1 assert type(result["timestamp"] is datetime) + +@pytest.mark.asyncio +async def test_ignoteorder(fmo, ignore_order): + """ignore order Testing""" + result = await fmo.get_order(ignore_order) + assert result is None + + @pytest.mark.asyncio async def test_mapping_order( fmo, From 79ef2ba396cfbed6f478ff31c8c5cff78f9802e4 Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Tue, 11 Jul 2023 17:07:14 +0000 Subject: [PATCH 2/3] 'Refactored by Sourcery' --- findmyorder/main.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/findmyorder/main.py b/findmyorder/main.py index 46048c89..7ace469b 100644 --- a/findmyorder/main.py +++ b/findmyorder/main.py @@ -97,19 +97,19 @@ async def get_order( msg: str, ): """get an order.""" - if await self.search(msg): - order = await self.identify_order(msg) - if isinstance(order, dict): - order["timestamp"] = datetime.utcnow().strftime( - "%Y-%m-%dT%H:%M:%SZ") - print(settings.instrument_mapping) - if settings.instrument_mapping: - await self.replace_instrument(order) - if order["instrument"] in settings.ignore_instrument: - """ ignoring instrument""" - return - return order - return None + if not await self.search(msg): + return None + order = await self.identify_order(msg) + if isinstance(order, dict): + order["timestamp"] = datetime.utcnow().strftime( + "%Y-%m-%dT%H:%M:%SZ") + print(settings.instrument_mapping) + if settings.instrument_mapping: + await self.replace_instrument(order) + if order["instrument"] in settings.ignore_instrument: + """ ignoring instrument""" + return + return order async def replace_instrument(self, order): """ replace instrument by an alternative instrument """ From b8deab5d763ea3a17296fedd7ed6956584517806 Mon Sep 17 00:00:00 2001 From: mraniki <8766259+mraniki@users.noreply.github.com> Date: Tue, 11 Jul 2023 20:19:30 +0200 Subject: [PATCH 3/3] =?UTF-8?q?=E2=9C=85=20=20added=20unit=20test=20for=20?= =?UTF-8?q?get=5Finfo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_unit.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tests/test_unit.py b/tests/test_unit.py index a9a76b6c..216aff2f 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -4,12 +4,9 @@ from datetime import datetime import pytest -from unittest.mock import patch from findmyorder import FindMyOrder, settings - - @pytest.fixture(scope="session", autouse=True) def set_test_settings(): settings.configure(FORCE_ENV_FOR_DYNACONF="testing") @@ -98,9 +95,17 @@ def invalid_order(): async def test_settings(): """Search Testing""" assert settings.VALUE == "On Testing" - assert settings.findmyorder_enabled == True + assert settings.findmyorder_enabled is True +@pytest.mark.asyncio +async def test_info(fmo): + """Search Testing""" + result = await fmo.get_info() + print(result) + assert result is not None + assert str(result).startswith("FindMyOrder") + @pytest.mark.asyncio async def test_search_valid_order(fmo, crypto_order): """Search Testing""" @@ -179,7 +184,7 @@ async def test_short_valid_get_order(fmo, short_order, result_order): @pytest.mark.asyncio -async def test_ignoteorder(fmo, ignore_order): +async def test_ignore_eorder(fmo, ignore_order): """ignore order Testing""" result = await fmo.get_order(ignore_order) assert result is None @@ -193,10 +198,11 @@ async def test_mapping_order( """replace instrument Testing""" result = await fmo.get_order(crypto_short_order) print(result) - assert settings.instrument_mapping == True + assert settings.instrument_mapping is True assert result["instrument"] == result_crypto_order["instrument"] assert type(result["timestamp"] is datetime) + @pytest.mark.asyncio async def test_contains_no_emoji(fmo, order): """check emoji""" @@ -226,4 +232,3 @@ def func_that_raises(): # Check that the function returned None assert result is None -