aboutsummaryrefslogtreecommitdiff
path: root/test.py
diff options
context:
space:
mode:
Diffstat (limited to 'test.py')
-rw-r--r--test.py52
1 files changed, 44 insertions, 8 deletions
diff --git a/test.py b/test.py
index a4ec8d2..4ed0477 100644
--- a/test.py
+++ b/test.py
@@ -2562,7 +2562,7 @@ class HelperTest(WebMockTestCase):
2562 @mock.patch("portfolio.Portfolio.wait_for_recent") 2562 @mock.patch("portfolio.Portfolio.wait_for_recent")
2563 def test_main_process_market(self, wait, buy, sell): 2563 def test_main_process_market(self, wait, buy, sell):
2564 with self.subTest(before=False, after=False): 2564 with self.subTest(before=False, after=False):
2565 helper.main_process_market("user") 2565 helper.main_process_market("user", None)
2566 2566
2567 wait.assert_not_called() 2567 wait.assert_not_called()
2568 buy.assert_not_called() 2568 buy.assert_not_called()
@@ -2572,7 +2572,7 @@ class HelperTest(WebMockTestCase):
2572 wait.reset_mock() 2572 wait.reset_mock()
2573 sell.reset_mock() 2573 sell.reset_mock()
2574 with self.subTest(before=True, after=False): 2574 with self.subTest(before=True, after=False):
2575 helper.main_process_market("user", before=True) 2575 helper.main_process_market("user", None, before=True)
2576 2576
2577 wait.assert_not_called() 2577 wait.assert_not_called()
2578 buy.assert_not_called() 2578 buy.assert_not_called()
@@ -2582,7 +2582,7 @@ class HelperTest(WebMockTestCase):
2582 wait.reset_mock() 2582 wait.reset_mock()
2583 sell.reset_mock() 2583 sell.reset_mock()
2584 with self.subTest(before=False, after=True): 2584 with self.subTest(before=False, after=True):
2585 helper.main_process_market("user", after=True) 2585 helper.main_process_market("user", None, after=True)
2586 2586
2587 wait.assert_called_once_with("user") 2587 wait.assert_called_once_with("user")
2588 buy.assert_called_once_with("user") 2588 buy.assert_called_once_with("user")
@@ -2592,12 +2592,37 @@ class HelperTest(WebMockTestCase):
2592 wait.reset_mock() 2592 wait.reset_mock()
2593 sell.reset_mock() 2593 sell.reset_mock()
2594 with self.subTest(before=True, after=True): 2594 with self.subTest(before=True, after=True):
2595 helper.main_process_market("user", before=True, after=True) 2595 helper.main_process_market("user", None, before=True, after=True)
2596 2596
2597 wait.assert_called_once_with("user") 2597 wait.assert_called_once_with("user")
2598 buy.assert_called_once_with("user") 2598 buy.assert_called_once_with("user")
2599 sell.assert_called_once_with("user") 2599 sell.assert_called_once_with("user")
2600 2600
2601 buy.reset_mock()
2602 wait.reset_mock()
2603 sell.reset_mock()
2604 with self.subTest(action="print_balances"),\
2605 mock.patch("helper.print_balances") as print_balances:
2606 helper.main_process_market("user", "print_balances")
2607
2608 buy.assert_not_called()
2609 wait.assert_not_called()
2610 sell.assert_not_called()
2611 print_balances.assert_called_once_with("user")
2612
2613 with self.subTest(action="print_orders"),\
2614 mock.patch("helper.print_orders") as print_orders:
2615 helper.main_process_market("user", "print_orders")
2616
2617 buy.assert_not_called()
2618 wait.assert_not_called()
2619 sell.assert_not_called()
2620 print_orders.assert_called_once_with("user")
2621
2622 with self.subTest(action="unknown"),\
2623 self.assertRaises(NotImplementedError):
2624 helper.main_process_market("user", "unknown")
2625
2601 @mock.patch.object(helper, "psycopg2") 2626 @mock.patch.object(helper, "psycopg2")
2602 def test_fetch_markets(self, psycopg2): 2627 def test_fetch_markets(self, psycopg2):
2603 connect_mock = mock.Mock() 2628 connect_mock = mock.Mock()
@@ -2607,12 +2632,23 @@ class HelperTest(WebMockTestCase):
2607 connect_mock.cursor.return_value = cursor_mock 2632 connect_mock.cursor.return_value = cursor_mock
2608 psycopg2.connect.return_value = connect_mock 2633 psycopg2.connect.return_value = connect_mock
2609 2634
2610 rows = list(helper.main_fetch_markets({"foo": "bar"})) 2635 with self.subTest(user=None):
2636 rows = list(helper.main_fetch_markets({"foo": "bar"}, None))
2637
2638 psycopg2.connect.assert_called_once_with(foo="bar")
2639 cursor_mock.execute.assert_called_once_with("SELECT config,user_id FROM market_configs")
2640
2641 self.assertEqual(["row_1", "row_2"], rows)
2642
2643 psycopg2.connect.reset_mock()
2644 cursor_mock.execute.reset_mock()
2645 with self.subTest(user=1):
2646 rows = list(helper.main_fetch_markets({"foo": "bar"}, 1))
2611 2647
2612 psycopg2.connect.assert_called_once_with(foo="bar") 2648 psycopg2.connect.assert_called_once_with(foo="bar")
2613 cursor_mock.execute.assert_called_once_with("SELECT config,user_id FROM market_configs") 2649 cursor_mock.execute.assert_called_once_with("SELECT config,user_id FROM market_configs WHERE user_id = %s", 1)
2614 2650
2615 self.assertEqual(["row_1", "row_2"], rows) 2651 self.assertEqual(["row_1", "row_2"], rows)
2616 2652
2617 @mock.patch.object(helper.sys, "exit") 2653 @mock.patch.object(helper.sys, "exit")
2618 def test_main_parse_args(self, exit): 2654 def test_main_parse_args(self, exit):