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
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):
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)
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):