aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2018-07-25 20:29:08 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2018-07-25 20:29:08 +0200
commit4b598ca6f91236c94da250282ac8c89c7d947ee2 (patch)
tree15d903ed7edb9154d1a58a7b7f01cddc15429e42
parent3d6f74ee1a8b061e4b274dad70125ab6388f4d83 (diff)
downloadTrader-4b598ca6f91236c94da250282ac8c89c7d947ee2.tar.gz
Trader-4b598ca6f91236c94da250282ac8c89c7d947ee2.tar.zst
Trader-4b598ca6f91236c94da250282ac8c89c7d947ee2.zip
Some fixes
- DB cursor expects an enumerable - None should be returned when repartition is not available
-rw-r--r--main.py2
-rw-r--r--store.py3
-rw-r--r--tests/test_main.py2
-rw-r--r--tests/test_store.py12
4 files changed, 16 insertions, 3 deletions
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):
73 if user is None: 73 if user is None:
74 cursor.execute("SELECT id,config,user_id FROM market_configs WHERE status='enabled'") 74 cursor.execute("SELECT id,config,user_id FROM market_configs WHERE status='enabled'")
75 else: 75 else:
76 cursor.execute("SELECT id,config,user_id FROM market_configs WHERE status='enabled' AND user_id = %s", user) 76 cursor.execute("SELECT id,config,user_id FROM market_configs WHERE status='enabled' AND user_id = %s", [user])
77 77
78 for row in cursor: 78 for row in cursor:
79 yield row 79 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:
564 cls.retrieve_cryptoportfolio() 564 cls.retrieve_cryptoportfolio()
565 cls.get_cryptoportfolio() 565 cls.get_cryptoportfolio()
566 liquidities = cls.liquidities.get(liquidity) 566 liquidities = cls.liquidities.get(liquidity)
567 return liquidities[cls.last_date.get()].copy() 567 if liquidities is not None and cls.last_date.get() in liquidities:
568 return liquidities[cls.last_date.get()].copy()
568 569
569 @classmethod 570 @classmethod
570 def get_cryptoportfolio(cls, refetch=False): 571 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):
333 with self.subTest(user=1): 333 with self.subTest(user=1):
334 rows = list(main.fetch_markets(1)) 334 rows = list(main.fetch_markets(1))
335 335
336 cursor_mock.execute.assert_called_once_with("SELECT id,config,user_id FROM market_configs WHERE status='enabled' AND user_id = %s", 1) 336 cursor_mock.execute.assert_called_once_with("SELECT id,config,user_id FROM market_configs WHERE status='enabled' AND user_id = %s", [1])
337 337
338 self.assertEqual(["row_1", "row_2"], rows) 338 self.assertEqual(["row_1", "row_2"], rows)
339 339
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):
1537 get_cryptoportfolio.assert_called_once_with() 1537 get_cryptoportfolio.assert_called_once_with()
1538 retrieve_cryptoportfolio.assert_called_once_with() 1538 retrieve_cryptoportfolio.assert_called_once_with()
1539 1539
1540 retrieve_cryptoportfolio.reset_mock()
1541 get_cryptoportfolio.reset_mock()
1542
1543 with self.subTest("absent liquidities"):
1544 market.Portfolio.last_date = store.LockedVar("2018-03-15")
1545 self.assertIsNone(market.Portfolio.repartition())
1546
1547 with self.subTest("no liquidities"):
1548 market.Portfolio.liquidities = store.LockedVar({})
1549 market.Portfolio.last_date = store.LockedVar("2018-03-08")
1550 self.assertIsNone(market.Portfolio.repartition())
1551
1540 @mock.patch.object(market.time, "sleep") 1552 @mock.patch.object(market.time, "sleep")
1541 @mock.patch.object(market.Portfolio, "get_cryptoportfolio") 1553 @mock.patch.object(market.Portfolio, "get_cryptoportfolio")
1542 def test_wait_for_recent(self, get_cryptoportfolio, sleep): 1554 def test_wait_for_recent(self, get_cryptoportfolio, sleep):