]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git/commitdiff
Add last tests for helper
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Sun, 11 Feb 2018 23:41:10 +0000 (00:41 +0100)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Sun, 11 Feb 2018 23:41:10 +0000 (00:41 +0100)
helper.py
test.py

index 421e8cdc9b7f0adcbe3af64328fe178681a16eed..f1aeaf2dbeba2807d29ca632d889761fe647274f 100644 (file)
--- a/helper.py
+++ b/helper.py
@@ -109,7 +109,7 @@ def follow_orders(verbose=True, sleep=None):
         print("All orders finished")
 
 def print_orders(market, base_currency="BTC"):
-    prepare_trades(market, base_currency=base_currency, compute_value="average")
+    prepare_trades(market, base_currency=base_currency, compute_value="average", debug=True)
     TradeStore.prepare_orders(compute_value="average")
     for currency, balance in BalanceStore.all.items():
         print(balance)
@@ -127,7 +127,7 @@ def process_sell_needed__1_sell(market, base_currency="BTC", debug=False):
     TradeStore.run_orders()
     follow_orders()
 
-def process_sell_needed__2_sell(market, base_currency="BTC", debug=False):
+def process_sell_needed__2_buy(market, base_currency="BTC", debug=False):
     update_trades(market, base_currency=base_currency, debug=debug, only="acquire")
     TradeStore.prepare_orders(compute_value="average", only="acquire")
     print("------------------")
diff --git a/test.py b/test.py
index f7df9a861ffc46240515f5868d5a508567122313..26646be24d8b87a75401e00fc3b5c150946aa41a 100644 (file)
--- a/test.py
+++ b/test.py
@@ -757,11 +757,141 @@ class HelperTest(WebMockTestCase):
                 }
         helper.print_orders(market)
         prepare_trades.assert_called_with(market, base_currency="BTC",
-                compute_value="average")
+                compute_value="average", debug=True)
         prepare_orders.assert_called_with(compute_value="average")
         print_all_with_order.assert_called()
         self.assertRegex(stdout_mock.getvalue(), "Balance")
 
+    @mock.patch.object(helper, "prepare_trades")
+    @mock.patch.object(helper, "follow_orders")
+    @mock.patch.object(portfolio.TradeStore, "prepare_orders")
+    @mock.patch.object(portfolio.TradeStore, "print_all_with_order")
+    @mock.patch.object(portfolio.TradeStore, "run_orders")
+    @mock.patch('sys.stdout', new_callable=StringIO)
+    def test_process_sell_needed__1_sell(self, stdout_mock, run_orders,
+            print_all_with_order, prepare_orders, follow_orders,
+            prepare_trades):
+        market = mock.Mock()
+        portfolio.BalanceStore.all = {
+                "BTC": portfolio.Balance("BTC", {
+                    "total": "0.65",
+                    "exchange_total":"0.65",
+                    "exchange_free": "0.35",
+                    "exchange_used": "0.30"}),
+                "ETH": portfolio.Balance("ETH", {
+                    "total": 3,
+                    "exchange_total": 3,
+                    "exchange_free": 3,
+                    "exchange_used": 0}),
+                }
+        helper.process_sell_needed__1_sell(market)
+        prepare_trades.assert_called_with(market, base_currency="BTC",
+                debug=False)
+        prepare_orders.assert_called_with(compute_value="average",
+                only="dispose")
+        print_all_with_order.assert_called()
+        run_orders.assert_called()
+        follow_orders.assert_called()
+        self.assertRegex(stdout_mock.getvalue(), "Balance")
+
+    @mock.patch.object(helper, "update_trades")
+    @mock.patch.object(helper, "follow_orders")
+    @mock.patch.object(helper, "move_balances")
+    @mock.patch.object(portfolio.TradeStore, "prepare_orders")
+    @mock.patch.object(portfolio.TradeStore, "print_all_with_order")
+    @mock.patch.object(portfolio.TradeStore, "run_orders")
+    @mock.patch('sys.stdout', new_callable=StringIO)
+    def test_process_sell_needed__2_buy(self, stdout_mock, run_orders,
+            print_all_with_order, prepare_orders, move_balances,
+            follow_orders, update_trades):
+        market = mock.Mock()
+        portfolio.BalanceStore.all = {
+                "BTC": portfolio.Balance("BTC", {
+                    "total": "0.65",
+                    "exchange_total":"0.65",
+                    "exchange_free": "0.35",
+                    "exchange_used": "0.30"}),
+                "ETH": portfolio.Balance("ETH", {
+                    "total": 3,
+                    "exchange_total": 3,
+                    "exchange_free": 3,
+                    "exchange_used": 0}),
+                }
+        helper.process_sell_needed__2_buy(market)
+        update_trades.assert_called_with(market, base_currency="BTC",
+                debug=False, only="acquire")
+        prepare_orders.assert_called_with(compute_value="average",
+                only="acquire")
+        print_all_with_order.assert_called()
+        move_balances.assert_called_with(market, debug=False)
+        run_orders.assert_called()
+        follow_orders.assert_called()
+        self.assertRegex(stdout_mock.getvalue(), "Balance")
+
+    @mock.patch.object(helper, "prepare_trades_to_sell_all")
+    @mock.patch.object(helper, "follow_orders")
+    @mock.patch.object(portfolio.TradeStore, "prepare_orders")
+    @mock.patch.object(portfolio.TradeStore, "print_all_with_order")
+    @mock.patch.object(portfolio.TradeStore, "run_orders")
+    @mock.patch('sys.stdout', new_callable=StringIO)
+    def test_process_sell_all__1_sell(self, stdout_mock, run_orders,
+            print_all_with_order, prepare_orders, follow_orders,
+            prepare_trades_to_sell_all):
+        market = mock.Mock()
+        portfolio.BalanceStore.all = {
+                "BTC": portfolio.Balance("BTC", {
+                    "total": "0.65",
+                    "exchange_total":"0.65",
+                    "exchange_free": "0.35",
+                    "exchange_used": "0.30"}),
+                "ETH": portfolio.Balance("ETH", {
+                    "total": 3,
+                    "exchange_total": 3,
+                    "exchange_free": 3,
+                    "exchange_used": 0}),
+                }
+        helper.process_sell_all__1_all_sell(market)
+        prepare_trades_to_sell_all.assert_called_with(market, base_currency="BTC",
+                debug=False)
+        prepare_orders.assert_called_with(compute_value="average")
+        print_all_with_order.assert_called()
+        run_orders.assert_called()
+        follow_orders.assert_called()
+        self.assertRegex(stdout_mock.getvalue(), "Balance")
+
+    @mock.patch.object(helper, "prepare_trades")
+    @mock.patch.object(helper, "follow_orders")
+    @mock.patch.object(helper, "move_balances")
+    @mock.patch.object(portfolio.TradeStore, "prepare_orders")
+    @mock.patch.object(portfolio.TradeStore, "print_all_with_order")
+    @mock.patch.object(portfolio.TradeStore, "run_orders")
+    @mock.patch('sys.stdout', new_callable=StringIO)
+    def test_process_sell_all__2_all_buy(self, stdout_mock, run_orders,
+            print_all_with_order, prepare_orders, move_balances,
+            follow_orders, prepare_trades):
+        market = mock.Mock()
+        portfolio.BalanceStore.all = {
+                "BTC": portfolio.Balance("BTC", {
+                    "total": "0.65",
+                    "exchange_total":"0.65",
+                    "exchange_free": "0.35",
+                    "exchange_used": "0.30"}),
+                "ETH": portfolio.Balance("ETH", {
+                    "total": 3,
+                    "exchange_total": 3,
+                    "exchange_free": 3,
+                    "exchange_used": 0}),
+                }
+        helper.process_sell_all__2_all_buy(market)
+        prepare_trades.assert_called_with(market, base_currency="BTC",
+                debug=False)
+        prepare_orders.assert_called_with()
+        print_all_with_order.assert_called()
+        move_balances.assert_called_with(market, debug=False)
+        run_orders.assert_called()
+        follow_orders.assert_called()
+        self.assertRegex(stdout_mock.getvalue(), "Balance")
+
 
 @unittest.skipUnless("unit" in limits, "Unit skipped")
 class TradeStoreTest(WebMockTestCase):