]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git/commitdiff
Some fixes
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Wed, 25 Jul 2018 18:29:08 +0000 (20:29 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Wed, 25 Jul 2018 18:29:08 +0000 (20:29 +0200)
- DB cursor expects an enumerable
- None should be returned when repartition is not available

main.py
store.py
tests/test_main.py
tests/test_store.py

diff --git a/main.py b/main.py
index 1c65e5644ca6ebbe855813da68bbef18ba995b16..ab523bec068fa4c00e08de16a1bf54ea7ef378ae 100644 (file)
--- 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
index 1a1ed762ec33245ffa46cb6f3bb4cb7e78a828d1..5533759a2f766159b6d098f77bffd7fa4eedd34f 100644 (file)
--- 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):
index 298e29e136ca1f4062a32af0e874d6aa331a4eaf..0b4745f659d5a11e6b66faee79aa20f603f26e8a 100644 (file)
@@ -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)
 
index 1a722b514e8057fb8472f10e0426047c9664f305..3097f6d5d49d30f97bea413c3138cac6c21683ce 100644 (file)
@@ -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):