]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git/blobdiff - test.py
Move market processing to single method
[perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git] / test.py
diff --git a/test.py b/test.py
index c2c70cb469db5eca98158c809ac9193aef38c656..bbe0697bbfd47273106bddc29b8536320d4f34e7 100644 (file)
--- a/test.py
+++ b/test.py
@@ -3333,11 +3333,8 @@ class MainTest(WebMockTestCase):
                 self.assertIsInstance(m, market.Market)
                 self.assertTrue(m.debug)
 
-    def test_main(self):
-        with mock.patch("main.parse_args") as parse_args,\
-                mock.patch("main.parse_config") as parse_config,\
-                mock.patch("main.fetch_markets") as fetch_markets,\
-                mock.patch("market.Market") as market_mock,\
+    def test_process(self):
+        with mock.patch("market.Market") as market_mock,\
                 mock.patch('sys.stdout', new_callable=StringIO) as stdout_mock:
 
             args_mock = mock.Mock()
@@ -3347,6 +3344,29 @@ class MainTest(WebMockTestCase):
             args_mock.debug = "debug"
             args_mock.before = "before"
             args_mock.after = "after"
+            self.assertEqual("", stdout_mock.getvalue())
+
+            main.process("config", 1, "report_path", args_mock)
+
+            market_mock.from_config.assert_has_calls([
+                mock.call("config", debug="debug", user_id=1, report_path="report_path"),
+                mock.call().process("action", before="before", after="after"),
+                ])
+
+            with self.subTest(exception=True):
+                market_mock.from_config.side_effect = Exception("boo")
+                main.process("config", 1, "report_path", args_mock)
+                self.assertEqual("Exception: boo\n", stdout_mock.getvalue())
+
+    def test_main(self):
+        with mock.patch("main.parse_args") as parse_args,\
+                mock.patch("main.parse_config") as parse_config,\
+                mock.patch("main.fetch_markets") as fetch_markets,\
+                mock.patch("main.process") as process:
+
+            args_mock = mock.Mock()
+            args_mock.config = "config"
+            args_mock.user = "user"
             parse_args.return_value = args_mock
 
             parse_config.return_value = ["pg_config", "report_path"]
@@ -3359,21 +3379,12 @@ class MainTest(WebMockTestCase):
             parse_config.assert_called_with("config")
             fetch_markets.assert_called_with("pg_config", "user")
 
-            self.assertEqual(2, market_mock.from_config.call_count)
-            market_mock.from_config.assert_has_calls([
-                mock.call("config1", debug="debug", user_id=1, report_path="report_path"),
-                mock.call().process("action", before="before", after="after"),
-                mock.call("config2", debug="debug", user_id=2, report_path="report_path"),
-                mock.call().process("action", before="before", after="after")
+            self.assertEqual(2, process.call_count)
+            process.assert_has_calls([
+                mock.call("config1", 1, "report_path", args_mock),
+                mock.call("config2", 2, "report_path", args_mock),
                 ])
 
-            self.assertEqual("", stdout_mock.getvalue())
-
-            with self.subTest(exception=True):
-                market_mock.from_config.side_effect = Exception("boo")
-                main.main(["Foo", "Bar"])
-                self.assertEqual("Exception: boo\nException: boo\n", stdout_mock.getvalue())
-
     @mock.patch.object(main.sys, "exit")
     @mock.patch("main.configparser")
     @mock.patch("main.os")