From: Ismaƫl Bouya Date: Wed, 25 Jul 2018 18:29:08 +0000 (+0200) Subject: Some fixes X-Git-Tag: v1.8.5^2 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=4b598ca6f91236c94da250282ac8c89c7d947ee2;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FTrader.git Some fixes - DB cursor expects an enumerable - None should be returned when repartition is not available --- diff --git a/main.py b/main.py index 1c65e56..ab523be 100644 --- a/main.py +++ b/main.py @@ -73,7 +73,7 @@ def fetch_markets(user): if user is None: cursor.execute("SELECT id,config,user_id FROM market_configs WHERE status='enabled'") else: - cursor.execute("SELECT id,config,user_id FROM market_configs WHERE status='enabled' AND user_id = %s", user) + cursor.execute("SELECT id,config,user_id FROM market_configs WHERE status='enabled' AND user_id = %s", [user]) for row in cursor: yield row diff --git a/store.py b/store.py index 1a1ed76..5533759 100644 --- a/store.py +++ b/store.py @@ -564,7 +564,8 @@ class Portfolio: cls.retrieve_cryptoportfolio() cls.get_cryptoportfolio() liquidities = cls.liquidities.get(liquidity) - return liquidities[cls.last_date.get()].copy() + if liquidities is not None and cls.last_date.get() in liquidities: + return liquidities[cls.last_date.get()].copy() @classmethod def get_cryptoportfolio(cls, refetch=False): diff --git a/tests/test_main.py b/tests/test_main.py index 298e29e..0b4745f 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -333,7 +333,7 @@ class MainTest(WebMockTestCase): with self.subTest(user=1): rows = list(main.fetch_markets(1)) - cursor_mock.execute.assert_called_once_with("SELECT id,config,user_id FROM market_configs WHERE status='enabled' AND user_id = %s", 1) + cursor_mock.execute.assert_called_once_with("SELECT id,config,user_id FROM market_configs WHERE status='enabled' AND user_id = %s", [1]) self.assertEqual(["row_1", "row_2"], rows) diff --git a/tests/test_store.py b/tests/test_store.py index 1a722b5..3097f6d 100644 --- a/tests/test_store.py +++ b/tests/test_store.py @@ -1537,6 +1537,18 @@ class PortfolioTest(WebMockTestCase): get_cryptoportfolio.assert_called_once_with() retrieve_cryptoportfolio.assert_called_once_with() + retrieve_cryptoportfolio.reset_mock() + get_cryptoportfolio.reset_mock() + + with self.subTest("absent liquidities"): + market.Portfolio.last_date = store.LockedVar("2018-03-15") + self.assertIsNone(market.Portfolio.repartition()) + + with self.subTest("no liquidities"): + market.Portfolio.liquidities = store.LockedVar({}) + market.Portfolio.last_date = store.LockedVar("2018-03-08") + self.assertIsNone(market.Portfolio.repartition()) + @mock.patch.object(market.time, "sleep") @mock.patch.object(market.Portfolio, "get_cryptoportfolio") def test_wait_for_recent(self, get_cryptoportfolio, sleep):