diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_store.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/test_store.py b/tests/test_store.py index 4ab9bdf..6f220c8 100644 --- a/tests/test_store.py +++ b/tests/test_store.py | |||
@@ -1379,11 +1379,19 @@ class PortfolioTest(WebMockTestCase): | |||
1379 | with self.subTest(worker=False): | 1379 | with self.subTest(worker=False): |
1380 | market.Portfolio.data = store.LockedVar(None) | 1380 | market.Portfolio.data = store.LockedVar(None) |
1381 | market.Portfolio.worker = mock.Mock() | 1381 | market.Portfolio.worker = mock.Mock() |
1382 | market.Portfolio.worker_started = True | ||
1382 | is_worker.return_value = False | 1383 | is_worker.return_value = False |
1383 | market.Portfolio.get_cryptoportfolio() | 1384 | market.Portfolio.get_cryptoportfolio() |
1384 | notify.assert_called_once_with() | 1385 | notify.assert_called_once_with() |
1385 | parse_cryptoportfolio.assert_not_called() | 1386 | parse_cryptoportfolio.assert_not_called() |
1386 | store_cryptoportfolio.assert_not_called() | 1387 | store_cryptoportfolio.assert_not_called() |
1388 | with self.subTest(worker_started=False): | ||
1389 | market.Portfolio.data = store.LockedVar(None) | ||
1390 | market.Portfolio.worker = mock.Mock() | ||
1391 | market.Portfolio.worker_started = False | ||
1392 | is_worker.return_value = False | ||
1393 | with self.assertRaises(Exception): | ||
1394 | market.Portfolio.get_cryptoportfolio() | ||
1387 | 1395 | ||
1388 | def test_parse_cryptoportfolio(self): | 1396 | def test_parse_cryptoportfolio(self): |
1389 | with self.subTest(description="Normal case"): | 1397 | with self.subTest(description="Normal case"): |
@@ -1649,6 +1657,22 @@ class PortfolioTest(WebMockTestCase): | |||
1649 | store.Portfolio.worker.join() | 1657 | store.Portfolio.worker.join() |
1650 | self.assertFalse(store.Portfolio.worker.is_alive()) | 1658 | self.assertFalse(store.Portfolio.worker.is_alive()) |
1651 | 1659 | ||
1660 | with self.subTest("overdue"),\ | ||
1661 | mock.patch.object(store.Portfolio, "get_cryptoportfolio") as get,\ | ||
1662 | mock.patch.object(store.Portfolio, "report") as report,\ | ||
1663 | mock.patch.object(store.Portfolio, "next_wait_time") as wait,\ | ||
1664 | mock.patch.object(store.time, "sleep") as sleep: | ||
1665 | wait.side_effect = Exception("Time over") | ||
1666 | store.Portfolio.start_worker() | ||
1667 | |||
1668 | store.Portfolio.worker_notify.set() | ||
1669 | |||
1670 | store.Portfolio.callback.wait() | ||
1671 | |||
1672 | report.print_log.assert_called_once_with("[Worker] Fetching cryptoportfolio") | ||
1673 | get.assert_called_once_with(refetch=True) | ||
1674 | self.assertFalse(store.Portfolio.worker.is_alive()) | ||
1675 | |||
1652 | def test_notify_and_wait(self): | 1676 | def test_notify_and_wait(self): |
1653 | with mock.patch.object(store.Portfolio, "callback") as callback,\ | 1677 | with mock.patch.object(store.Portfolio, "callback") as callback,\ |
1654 | mock.patch.object(store.Portfolio, "worker_notify") as worker_notify: | 1678 | mock.patch.object(store.Portfolio, "worker_notify") as worker_notify: |