+ self.assertEqual(1, self.wm.call_count)
+
+ portfolio.Portfolio.repartition()
+ self.assertEqual(1, self.wm.call_count)
+
+ portfolio.Portfolio.repartition(refetch=True)
+ self.assertEqual(2, self.wm.call_count)
+
+ @mock.patch.object(portfolio.time, "sleep")
+ @mock.patch.object(portfolio.Portfolio, "repartition")
+ def test_wait_for_recent(self, repartition, sleep):
+ self.call_count = 0
+ def _repartition(refetch):
+ self.assertTrue(refetch)
+ self.call_count += 1
+ portfolio.Portfolio.last_date = portfolio.datetime.now()\
+ - portfolio.timedelta(10)\
+ + portfolio.timedelta(self.call_count)
+ repartition.side_effect = _repartition
+
+ portfolio.Portfolio.wait_for_recent()
+ sleep.assert_called_with(30)
+ self.assertEqual(6, sleep.call_count)
+ self.assertEqual(7, repartition.call_count)
+
+ sleep.reset_mock()
+ repartition.reset_mock()
+ portfolio.Portfolio.last_date = None
+ self.call_count = 0
+ portfolio.Portfolio.wait_for_recent(delta=15)
+ sleep.assert_not_called()
+ self.assertEqual(1, repartition.call_count)
+
+ sleep.reset_mock()
+ repartition.reset_mock()
+ portfolio.Portfolio.last_date = None
+ self.call_count = 0
+ portfolio.Portfolio.wait_for_recent(delta=1)
+ sleep.assert_called_with(30)
+ self.assertEqual(9, sleep.call_count)
+ self.assertEqual(10, repartition.call_count)
+