market.report.log_stage("make_order_end")
def get_user_market(config_path, user_id, debug=False):
- pg_config, report_path = parse_config(config_path)
+ args = ["--config", config_path]
+ if debug:
+ args.append("--debug")
+ args = parse_args(args)
+ pg_config = parse_config(args)
market_id, market_config, user_id = list(fetch_markets(pg_config, str(user_id)))[0]
- args = type('Args', (object,), { "debug": debug, "quiet": False })()
return market.Market.from_config(market_config, args,
pg_config=pg_config, market_id=market_id,
- user_id=user_id, report_path=report_path)
+ user_id=user_id)
def fetch_markets(pg_config, user):
connection = psycopg2.connect(**pg_config)
def test_get_user_market(self):
with mock.patch("main.fetch_markets") as main_fetch_markets,\
+ mock.patch("main.parse_args") as main_parse_args,\
mock.patch("main.parse_config") as main_parse_config:
with self.subTest(debug=False):
- main_parse_config.return_value = ["pg_config", "report_path"]
+ main_parse_args.return_value = self.market_args()
+ main_parse_config.return_value = "pg_config"
main_fetch_markets.return_value = [(1, {"key": "market_config"}, 3)]
m = main.get_user_market("config_path.ini", 1)
self.assertIsInstance(m, market.Market)
self.assertFalse(m.debug)
+ main_parse_args.assert_called_once_with(["--config", "config_path.ini"])
+ main_parse_args.reset_mock()
with self.subTest(debug=True):
- main_parse_config.return_value = ["pg_config", "report_path"]
+ main_parse_args.return_value = self.market_args(debug=True)
+ main_parse_config.return_value = "pg_config"
main_fetch_markets.return_value = [(1, {"key": "market_config"}, 3)]
m = main.get_user_market("config_path.ini", 1, debug=True)
self.assertIsInstance(m, market.Market)
self.assertTrue(m.debug)
+ main_parse_args.assert_called_once_with(["--config", "config_path.ini", "--debug"])
def test_process(self):
with mock.patch("market.Market") as market_mock,\