async def test_selectcomp_view_existing(storage_dir, activity_testbed) -> None: # GIVEN details_screen = activity_testbed.mock( "compman.ui.compdetails.CompetitionDetailsScreen") storage.save_competition(storage.StoredCompetition("one", title="One")) storage.save_competition(storage.StoredCompetition("two", title="Two")) # WHEN async with activity_testbed.shown(SelectCompetitionScreen) as act: content = activity_testbed.render() assert "One" in content assert "Two" in content focus = activity_testbed.get_focus_widgets()[-1] assert focus.get_label() == "One" await activity_testbed.keypress("enter") # THEN selected = act.response.result() assert selected.id == "one" settings = storage.get_settings() assert settings.current_competition_id == "one"
async def test_mainmenu_details(storage_dir, activity_testbed) -> None: # GIVEN welcome_screen = activity_testbed.mock("compman.ui.welcome.WelcomeScreen") details_screen = activity_testbed.mock( "compman.ui.compdetails.CompetitionDetailsScreen") async with activity_testbed.shown(MainMenuScreen): # WHEN await asyncio.sleep(0) assert welcome_screen.shown comp = storage.StoredCompetition("test", "Test competition") storage.save_competition(comp) settings = storage.get_settings() settings.current_competition_id = comp.id await activity_testbed.keypress("esc") contents = activity_testbed.render() assert "Current Competition" in contents focused = activity_testbed.get_focus_widgets()[-1] assert focused.get_label() == "Current Competition" await activity_testbed.keypress("enter") # THEN assert details_screen.shown
async def test_remove_competition_cancel(storage_dir, activity_testbed, xcsoar_dir, async_sleep, sample_competition) -> None: # WHEN async with activity_testbed.shown(CompetitionDetailsScreen): # Let everything to be downloaded await activity_testbed.gather_tasks() rendered = activity_testbed.render() # WHEN # Navigate to "remove" button and press it await activity_testbed.keypress("down", "right", "enter") # THEN rendered = activity_testbed.render() assert "Test competition" in rendered assert "Are you sure you want to remove this competion?" in rendered # Cancel await activity_testbed.keypress("enter") rendered = activity_testbed.render() # We are back to details screen assert "XCSoar profiles" in rendered # The test competition should be gone assert storage.list_competitions() == [sample_competition] assert storage.get_settings( ).current_competition_id is sample_competition.id
async def _on_remove(self) -> None: screen = CompetitionRemoveConfirmationScreen(self.container, self.competition) screen.show() confirmed = await screen.response if confirmed: storage.delete_competition(self.competition.id) storage.get_settings().current_competition_id = None storage.save_settings() self.finish(None)
def test_save_settings_modified(storage_dir) -> None: settings = storage.get_settings() settings.current_competition_id = "hello" # WHEN storage.save_settings() # THEN settings = storage.load_settings() assert settings.current_competition_id == "hello"
def sample_competition(storage_dir): comp = storage.StoredCompetition("test", "Test competition") storage.save_competition(comp) settings = storage.get_settings() settings.current_competition_id = comp.id storage.save_settings() try: yield comp finally: settings.current_competition_id = None storage.save_settings() storage.delete_competition(comp.id)
def test_get_settings_bad_file(storage_dir) -> None: # GIVEN settings_fname = storage._get_settings_fname() with open(settings_fname, "w") as f: f.write(";garbage;") # WHEN settings = storage.get_settings() # THEN assert settings is not None assert settings.current_competition_id is None
def show(self) -> None: cid = storage.get_settings().current_competition_id assert cid is not None comp = storage.load_competition(cid) assert comp is not None self.competition = comp self.airspaces = storage.get_airspace_files(cid) self.waypoints = storage.get_waypoint_files(cid) self.profiles = xcsoar.list_xcsoar_profiles() super().show() self._flashtask = None self.async_task(self._update_competition_files())
async def test_welcomescreen_setup_comp( storage_dir, soaringspot, activity_testbed ) -> None: # User picks a competition and end up in competition details screen # GIVEN sspicker_screen = activity_testbed.mock( "compman.ui.soaringspot.SoaringSpotPickerScreen" ) sspicker_screen.result = storage.StoredCompetition( id="test", title="Test", soaringspot_url="http://test" ) details_screen = activity_testbed.mock( "compman.ui.compdetails.CompetitionDetailsScreen" ) async with activity_testbed.shown(WelcomeScreen): # WHEN await activity_testbed.keypress("enter") # THEN assert sspicker_screen.shown assert storage.get_settings().current_competition_id == "test"
def _comp_selected(self, comp): storage.get_settings().current_competition_id = comp.id storage.save_settings() self.finish(comp)
def _get_current_comp_id(self) -> Optional[str]: curid = storage.get_settings().current_competition_id return curid if curid and storage.exists(curid) else None
def test_get_settings_new(storage_dir) -> None: settings = storage.get_settings() assert settings is not None assert settings.current_competition_id is None