Loading cog/actions.py +9 −7 Original line number Diff line number Diff line Loading @@ -548,6 +548,7 @@ class BGS(Action): controls = cogdb.side.WATCH_BUBBLES else: controls = process_system_args(system_name.split(' ')) controls = [x.name for x in cogdb.eddb.get_systems(kwargs['eddb_session'], controls)] resp = "__**EDMC Route**__\nIf no systems listed under control, up to date." resp += "\n\n__Bubbles By Proximity__\n" Loading @@ -557,14 +558,15 @@ class BGS(Action): controls = [sys.name for sys in route] resp += "\n".join(controls) for control in controls: resp += "\n\n__{}__\n".format(string.capwords(control)) systems = await self.bot.loop.run_in_executor(None, cogdb.side.get_edmc_systems, kwargs['side_session'], [control]) if len(systems) > 2: control_ages = await self.bot.loop.run_in_executor(None, cogdb.side.get_system_ages, kwargs['side_session'], controls) for control_name in control_ages: resp += "\n\n__{}__\n".format(string.capwords(control_name)) ages = control_ages[control_name] if len(ages) > 2: _, systems = await self.bot.loop.run_in_executor(None, cogdb.eddb.find_best_route, kwargs['eddb_session'], [system.name for system in systems]) [age.system for age in ages]) resp += "\n".join([sys.name for sys in systems]) return resp Loading cogdb/side.py +12 −4 Original line number Diff line number Diff line Loading @@ -1224,15 +1224,23 @@ def monitor_factions(session, faction_names=None): @wrap_exceptions def get_edmc_systems(session, controls): def get_system_ages(session, controls): """ Get the list of Systems that have stale EDDN data. Returns: A dictionary of form: {'control': [system, system], ...} """ return session.query(System).\ filter(SystemAge.control.in_(controls), SystemAge.system == System.name).\ ages = session.query(SystemAge).\ filter(SystemAge.control.in_(controls)).\ all() map_ages = {x: [] for x in controls} for age in ages: map_ages[age.control] += [age] return map_ages def main(): # pragma: no cover pass Loading tests/cog/test_actions.py +11 −0 Original line number Diff line number Diff line Loading @@ -262,6 +262,17 @@ async def test_cmd_bgs_dash(f_bot, f_dusers, f_fort_testbed): assert 'Chelgit' in str(f_bot.send_message.call_args).replace("\\n", "\n") @pytest.mark.asyncio async def test_cmd_bgs_edmc(side_session, f_bot, f_dusers, f_fort_testbed): msg = fake_msg_gears("!bgs edmc rana, frey") await action_map(msg, f_bot).execute() cap = str(f_bot.send_message.call_args).replace("\\n", "\n") assert "__Rana__" in cap assert "__Frey" in cap @pytest.mark.asyncio async def test_cmd_bgs_exp(f_bot): msg = fake_msg_gears("!bgs exp rana") Loading tests/cogdb/test_side.py +13 −0 Original line number Diff line number Diff line Loading @@ -171,3 +171,16 @@ def test_system_calc_um_trigger(side_session): order_by(System.name).\ all() assert target.calc_um_trigger(pow_hq) == 13786 # TODO: Think a better test, other data optional def test_get_system_ages(side_session): sys_ages = cogdb.side.get_system_ages(side_session, ['Rana', 'Sol']) assert isinstance(sys_ages, type({})) assert isinstance(sys_ages['Rana'], type([])) for age in sys_ages['Rana']: assert age.control == 'Rana' assert isinstance(sys_ages['Sol'], type([])) for age in sys_ages['Sol']: assert age.control == 'Sol' Loading
cog/actions.py +9 −7 Original line number Diff line number Diff line Loading @@ -548,6 +548,7 @@ class BGS(Action): controls = cogdb.side.WATCH_BUBBLES else: controls = process_system_args(system_name.split(' ')) controls = [x.name for x in cogdb.eddb.get_systems(kwargs['eddb_session'], controls)] resp = "__**EDMC Route**__\nIf no systems listed under control, up to date." resp += "\n\n__Bubbles By Proximity__\n" Loading @@ -557,14 +558,15 @@ class BGS(Action): controls = [sys.name for sys in route] resp += "\n".join(controls) for control in controls: resp += "\n\n__{}__\n".format(string.capwords(control)) systems = await self.bot.loop.run_in_executor(None, cogdb.side.get_edmc_systems, kwargs['side_session'], [control]) if len(systems) > 2: control_ages = await self.bot.loop.run_in_executor(None, cogdb.side.get_system_ages, kwargs['side_session'], controls) for control_name in control_ages: resp += "\n\n__{}__\n".format(string.capwords(control_name)) ages = control_ages[control_name] if len(ages) > 2: _, systems = await self.bot.loop.run_in_executor(None, cogdb.eddb.find_best_route, kwargs['eddb_session'], [system.name for system in systems]) [age.system for age in ages]) resp += "\n".join([sys.name for sys in systems]) return resp Loading
cogdb/side.py +12 −4 Original line number Diff line number Diff line Loading @@ -1224,15 +1224,23 @@ def monitor_factions(session, faction_names=None): @wrap_exceptions def get_edmc_systems(session, controls): def get_system_ages(session, controls): """ Get the list of Systems that have stale EDDN data. Returns: A dictionary of form: {'control': [system, system], ...} """ return session.query(System).\ filter(SystemAge.control.in_(controls), SystemAge.system == System.name).\ ages = session.query(SystemAge).\ filter(SystemAge.control.in_(controls)).\ all() map_ages = {x: [] for x in controls} for age in ages: map_ages[age.control] += [age] return map_ages def main(): # pragma: no cover pass Loading
tests/cog/test_actions.py +11 −0 Original line number Diff line number Diff line Loading @@ -262,6 +262,17 @@ async def test_cmd_bgs_dash(f_bot, f_dusers, f_fort_testbed): assert 'Chelgit' in str(f_bot.send_message.call_args).replace("\\n", "\n") @pytest.mark.asyncio async def test_cmd_bgs_edmc(side_session, f_bot, f_dusers, f_fort_testbed): msg = fake_msg_gears("!bgs edmc rana, frey") await action_map(msg, f_bot).execute() cap = str(f_bot.send_message.call_args).replace("\\n", "\n") assert "__Rana__" in cap assert "__Frey" in cap @pytest.mark.asyncio async def test_cmd_bgs_exp(f_bot): msg = fake_msg_gears("!bgs exp rana") Loading
tests/cogdb/test_side.py +13 −0 Original line number Diff line number Diff line Loading @@ -171,3 +171,16 @@ def test_system_calc_um_trigger(side_session): order_by(System.name).\ all() assert target.calc_um_trigger(pow_hq) == 13786 # TODO: Think a better test, other data optional def test_get_system_ages(side_session): sys_ages = cogdb.side.get_system_ages(side_session, ['Rana', 'Sol']) assert isinstance(sys_ages, type({})) assert isinstance(sys_ages['Rana'], type([])) for age in sys_ages['Rana']: assert age.control == 'Rana' assert isinstance(sys_ages['Sol'], type([])) for age in sys_ages['Sol']: assert age.control == 'Sol'