aboutsummaryrefslogtreecommitdiff
path: root/test.py
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2018-02-12 00:41:10 +0100
committerIsmaël Bouya <ismael.bouya@normalesup.org>2018-02-12 00:41:10 +0100
commit2f0939e1353f0a95d858fb45c12bdd6d9dcb84f3 (patch)
tree6788a27cfaf236803cd07b5fa5dfb3c442dff815 /test.py
parentdf9e4e7f30a3505675bf61f7da19af4453647772 (diff)
downloadTrader-2f0939e1353f0a95d858fb45c12bdd6d9dcb84f3.tar.gz
Trader-2f0939e1353f0a95d858fb45c12bdd6d9dcb84f3.tar.zst
Trader-2f0939e1353f0a95d858fb45c12bdd6d9dcb84f3.zip
Add last tests for helper
Diffstat (limited to 'test.py')
-rw-r--r--test.py132
1 files changed, 131 insertions, 1 deletions
diff --git a/test.py b/test.py
index f7df9a8..26646be 100644
--- a/test.py
+++ b/test.py
@@ -757,11 +757,141 @@ class HelperTest(WebMockTestCase):
757 } 757 }
758 helper.print_orders(market) 758 helper.print_orders(market)
759 prepare_trades.assert_called_with(market, base_currency="BTC", 759 prepare_trades.assert_called_with(market, base_currency="BTC",
760 compute_value="average") 760 compute_value="average", debug=True)
761 prepare_orders.assert_called_with(compute_value="average") 761 prepare_orders.assert_called_with(compute_value="average")
762 print_all_with_order.assert_called() 762 print_all_with_order.assert_called()
763 self.assertRegex(stdout_mock.getvalue(), "Balance") 763 self.assertRegex(stdout_mock.getvalue(), "Balance")
764 764
765 @mock.patch.object(helper, "prepare_trades")
766 @mock.patch.object(helper, "follow_orders")
767 @mock.patch.object(portfolio.TradeStore, "prepare_orders")
768 @mock.patch.object(portfolio.TradeStore, "print_all_with_order")
769 @mock.patch.object(portfolio.TradeStore, "run_orders")
770 @mock.patch('sys.stdout', new_callable=StringIO)
771 def test_process_sell_needed__1_sell(self, stdout_mock, run_orders,
772 print_all_with_order, prepare_orders, follow_orders,
773 prepare_trades):
774 market = mock.Mock()
775 portfolio.BalanceStore.all = {
776 "BTC": portfolio.Balance("BTC", {
777 "total": "0.65",
778 "exchange_total":"0.65",
779 "exchange_free": "0.35",
780 "exchange_used": "0.30"}),
781 "ETH": portfolio.Balance("ETH", {
782 "total": 3,
783 "exchange_total": 3,
784 "exchange_free": 3,
785 "exchange_used": 0}),
786 }
787 helper.process_sell_needed__1_sell(market)
788 prepare_trades.assert_called_with(market, base_currency="BTC",
789 debug=False)
790 prepare_orders.assert_called_with(compute_value="average",
791 only="dispose")
792 print_all_with_order.assert_called()
793 run_orders.assert_called()
794 follow_orders.assert_called()
795 self.assertRegex(stdout_mock.getvalue(), "Balance")
796
797 @mock.patch.object(helper, "update_trades")
798 @mock.patch.object(helper, "follow_orders")
799 @mock.patch.object(helper, "move_balances")
800 @mock.patch.object(portfolio.TradeStore, "prepare_orders")
801 @mock.patch.object(portfolio.TradeStore, "print_all_with_order")
802 @mock.patch.object(portfolio.TradeStore, "run_orders")
803 @mock.patch('sys.stdout', new_callable=StringIO)
804 def test_process_sell_needed__2_buy(self, stdout_mock, run_orders,
805 print_all_with_order, prepare_orders, move_balances,
806 follow_orders, update_trades):
807 market = mock.Mock()
808 portfolio.BalanceStore.all = {
809 "BTC": portfolio.Balance("BTC", {
810 "total": "0.65",
811 "exchange_total":"0.65",
812 "exchange_free": "0.35",
813 "exchange_used": "0.30"}),
814 "ETH": portfolio.Balance("ETH", {
815 "total": 3,
816 "exchange_total": 3,
817 "exchange_free": 3,
818 "exchange_used": 0}),
819 }
820 helper.process_sell_needed__2_buy(market)
821 update_trades.assert_called_with(market, base_currency="BTC",
822 debug=False, only="acquire")
823 prepare_orders.assert_called_with(compute_value="average",
824 only="acquire")
825 print_all_with_order.assert_called()
826 move_balances.assert_called_with(market, debug=False)
827 run_orders.assert_called()
828 follow_orders.assert_called()
829 self.assertRegex(stdout_mock.getvalue(), "Balance")
830
831 @mock.patch.object(helper, "prepare_trades_to_sell_all")
832 @mock.patch.object(helper, "follow_orders")
833 @mock.patch.object(portfolio.TradeStore, "prepare_orders")
834 @mock.patch.object(portfolio.TradeStore, "print_all_with_order")
835 @mock.patch.object(portfolio.TradeStore, "run_orders")
836 @mock.patch('sys.stdout', new_callable=StringIO)
837 def test_process_sell_all__1_sell(self, stdout_mock, run_orders,
838 print_all_with_order, prepare_orders, follow_orders,
839 prepare_trades_to_sell_all):
840 market = mock.Mock()
841 portfolio.BalanceStore.all = {
842 "BTC": portfolio.Balance("BTC", {
843 "total": "0.65",
844 "exchange_total":"0.65",
845 "exchange_free": "0.35",
846 "exchange_used": "0.30"}),
847 "ETH": portfolio.Balance("ETH", {
848 "total": 3,
849 "exchange_total": 3,
850 "exchange_free": 3,
851 "exchange_used": 0}),
852 }
853 helper.process_sell_all__1_all_sell(market)
854 prepare_trades_to_sell_all.assert_called_with(market, base_currency="BTC",
855 debug=False)
856 prepare_orders.assert_called_with(compute_value="average")
857 print_all_with_order.assert_called()
858 run_orders.assert_called()
859 follow_orders.assert_called()
860 self.assertRegex(stdout_mock.getvalue(), "Balance")
861
862 @mock.patch.object(helper, "prepare_trades")
863 @mock.patch.object(helper, "follow_orders")
864 @mock.patch.object(helper, "move_balances")
865 @mock.patch.object(portfolio.TradeStore, "prepare_orders")
866 @mock.patch.object(portfolio.TradeStore, "print_all_with_order")
867 @mock.patch.object(portfolio.TradeStore, "run_orders")
868 @mock.patch('sys.stdout', new_callable=StringIO)
869 def test_process_sell_all__2_all_buy(self, stdout_mock, run_orders,
870 print_all_with_order, prepare_orders, move_balances,
871 follow_orders, prepare_trades):
872 market = mock.Mock()
873 portfolio.BalanceStore.all = {
874 "BTC": portfolio.Balance("BTC", {
875 "total": "0.65",
876 "exchange_total":"0.65",
877 "exchange_free": "0.35",
878 "exchange_used": "0.30"}),
879 "ETH": portfolio.Balance("ETH", {
880 "total": 3,
881 "exchange_total": 3,
882 "exchange_free": 3,
883 "exchange_used": 0}),
884 }
885 helper.process_sell_all__2_all_buy(market)
886 prepare_trades.assert_called_with(market, base_currency="BTC",
887 debug=False)
888 prepare_orders.assert_called_with()
889 print_all_with_order.assert_called()
890 move_balances.assert_called_with(market, debug=False)
891 run_orders.assert_called()
892 follow_orders.assert_called()
893 self.assertRegex(stdout_mock.getvalue(), "Balance")
894
765 895
766@unittest.skipUnless("unit" in limits, "Unit skipped") 896@unittest.skipUnless("unit" in limits, "Unit skipped")
767class TradeStoreTest(WebMockTestCase): 897class TradeStoreTest(WebMockTestCase):