diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-04-05 12:14:49 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-04-05 12:14:49 +0200 |
commit | e6015816224f8f405e9b1c9557f22e73b21246e8 (patch) | |
tree | dc1e22add15b904f5c960024a23fd664769a09f7 | |
parent | dcc1e201c17dd096fb757f973341e98865809f33 (diff) | |
download | Trader-e6015816224f8f405e9b1c9557f22e73b21246e8.tar.gz Trader-e6015816224f8f405e9b1c9557f22e73b21246e8.tar.zst Trader-e6015816224f8f405e9b1c9557f22e73b21246e8.zip |
Fix console helper
-rw-r--r-- | main.py | 9 | ||||
-rw-r--r-- | test.py | 10 |
2 files changed, 14 insertions, 5 deletions
@@ -60,12 +60,15 @@ def make_order(market, value, currency, action="acquire", | |||
60 | market.report.log_stage("make_order_end") | 60 | market.report.log_stage("make_order_end") |
61 | 61 | ||
62 | def get_user_market(config_path, user_id, debug=False): | 62 | def get_user_market(config_path, user_id, debug=False): |
63 | pg_config, report_path = parse_config(config_path) | 63 | args = ["--config", config_path] |
64 | if debug: | ||
65 | args.append("--debug") | ||
66 | args = parse_args(args) | ||
67 | pg_config = parse_config(args) | ||
64 | market_id, market_config, user_id = list(fetch_markets(pg_config, str(user_id)))[0] | 68 | market_id, market_config, user_id = list(fetch_markets(pg_config, str(user_id)))[0] |
65 | args = type('Args', (object,), { "debug": debug, "quiet": False })() | ||
66 | return market.Market.from_config(market_config, args, | 69 | return market.Market.from_config(market_config, args, |
67 | pg_config=pg_config, market_id=market_id, | 70 | pg_config=pg_config, market_id=market_id, |
68 | user_id=user_id, report_path=report_path) | 71 | user_id=user_id) |
69 | 72 | ||
70 | def fetch_markets(pg_config, user): | 73 | def fetch_markets(pg_config, user): |
71 | connection = psycopg2.connect(**pg_config) | 74 | connection = psycopg2.connect(**pg_config) |
@@ -4585,22 +4585,28 @@ class MainTest(WebMockTestCase): | |||
4585 | 4585 | ||
4586 | def test_get_user_market(self): | 4586 | def test_get_user_market(self): |
4587 | with mock.patch("main.fetch_markets") as main_fetch_markets,\ | 4587 | with mock.patch("main.fetch_markets") as main_fetch_markets,\ |
4588 | mock.patch("main.parse_args") as main_parse_args,\ | ||
4588 | mock.patch("main.parse_config") as main_parse_config: | 4589 | mock.patch("main.parse_config") as main_parse_config: |
4589 | with self.subTest(debug=False): | 4590 | with self.subTest(debug=False): |
4590 | main_parse_config.return_value = ["pg_config", "report_path"] | 4591 | main_parse_args.return_value = self.market_args() |
4592 | main_parse_config.return_value = "pg_config" | ||
4591 | main_fetch_markets.return_value = [(1, {"key": "market_config"}, 3)] | 4593 | main_fetch_markets.return_value = [(1, {"key": "market_config"}, 3)] |
4592 | m = main.get_user_market("config_path.ini", 1) | 4594 | m = main.get_user_market("config_path.ini", 1) |
4593 | 4595 | ||
4594 | self.assertIsInstance(m, market.Market) | 4596 | self.assertIsInstance(m, market.Market) |
4595 | self.assertFalse(m.debug) | 4597 | self.assertFalse(m.debug) |
4598 | main_parse_args.assert_called_once_with(["--config", "config_path.ini"]) | ||
4596 | 4599 | ||
4600 | main_parse_args.reset_mock() | ||
4597 | with self.subTest(debug=True): | 4601 | with self.subTest(debug=True): |
4598 | main_parse_config.return_value = ["pg_config", "report_path"] | 4602 | main_parse_args.return_value = self.market_args(debug=True) |
4603 | main_parse_config.return_value = "pg_config" | ||
4599 | main_fetch_markets.return_value = [(1, {"key": "market_config"}, 3)] | 4604 | main_fetch_markets.return_value = [(1, {"key": "market_config"}, 3)] |
4600 | m = main.get_user_market("config_path.ini", 1, debug=True) | 4605 | m = main.get_user_market("config_path.ini", 1, debug=True) |
4601 | 4606 | ||
4602 | self.assertIsInstance(m, market.Market) | 4607 | self.assertIsInstance(m, market.Market) |
4603 | self.assertTrue(m.debug) | 4608 | self.assertTrue(m.debug) |
4609 | main_parse_args.assert_called_once_with(["--config", "config_path.ini", "--debug"]) | ||
4604 | 4610 | ||
4605 | def test_process(self): | 4611 | def test_process(self): |
4606 | with mock.patch("market.Market") as market_mock,\ | 4612 | with mock.patch("market.Market") as market_mock,\ |