def test_removed_shortcuts_doesnt_return_shortcuts_that_still_exist(self): shortcut1 = steam_model.Shortcut("Game1", "/Path/to/game1", "/Path/to", "", [roms.ICE_FLAG_TAG]) shortcut2 = steam_model.Shortcut("Game2", "/Path/to/game2", "/Path/to", "", [roms.ICE_FLAG_TAG]) old = [shortcut1, shortcut2] new = [shortcut1, shortcut2] self.assertEquals(self.synchronizer.removed_shortcuts(old, new), [])
def test_added_shortcuts_returns_shortcuts_that_didnt_exist_previously( self): shortcut1 = steam_model.Shortcut("Game1", "/Path/to/game1", "/Path/to", "", [roms.ICE_FLAG_TAG]) shortcut2 = steam_model.Shortcut("Game2", "/Path/to/game2", "/Path/to", "", [roms.ICE_FLAG_TAG]) new = [shortcut1, shortcut2] self.assertEquals(self.synchronizer.added_shortcuts([], new), [shortcut1, shortcut2])
def test_removed_shortcuts_returns_shortcuts_that_dont_exist_anymore(self): shortcut1 = steam_model.Shortcut("Game1", "/Path/to/game1", "/Path/to", "", [roms.ICE_FLAG_TAG]) shortcut2 = steam_model.Shortcut("Game2", "/Path/to/game2", "/Path/to", "", [roms.ICE_FLAG_TAG]) old = [shortcut1, shortcut2] new = [] self.assertEqual(self.synchronizer.removed_shortcuts(old, new), [shortcut1, shortcut2])
def test_unmanaged_shortcuts_doesnt_return_shortcut_with_appid_in_managed_ids( self): managed_shortcut = steam_model.Shortcut("Game", "/Path/to/game", "/Path/to", "", []) random_shortcut = steam_model.Shortcut("Plex", "/Some/Random/Path/plex", "/Some/Random/Path", "", []) managed_ids = [shortcuts.shortcut_app_id(managed_shortcut)] all_shortcuts = [managed_shortcut, random_shortcut] unmanaged = self.synchronizer.unmanaged_shortcuts( managed_ids, all_shortcuts, None) self.assertEquals(unmanaged, [random_shortcut])
def test_sync_roms_for_user_logs_once_for_each_removed_rom(self): shortcut1 = steam_model.Shortcut("Game1", "/Path/to/game1", "/Path/to", "", [roms.ICE_FLAG_TAG]) shortcut2 = steam_model.Shortcut("Game2", "/Path/to/game2", "/Path/to", "", [roms.ICE_FLAG_TAG]) shortcut3 = steam_model.Shortcut("Game3", "/Path/to/game3", "/Path/to", "", [roms.ICE_FLAG_TAG]) self._set_users_shortcuts([shortcut1, shortcut2, shortcut3]) self.synchronizer.sync_roms_for_user(self.user_fixture.get_context(), [], None) verify(self.mock_logger, times=3).info(any())
def test_removed_shortcuts_only_returns_shortcuts_that_dont_exist_now_but_did_before( self): shortcut1 = steam_model.Shortcut("Game1", "/Path/to/game1", "/Path/to", "", [roms.ICE_FLAG_TAG]) shortcut2 = steam_model.Shortcut("Game2", "/Path/to/game2", "/Path/to", "", [roms.ICE_FLAG_TAG]) shortcut3 = steam_model.Shortcut("Game3", "/Path/to/game3", "/Path/to", "", [roms.ICE_FLAG_TAG]) shortcut4 = steam_model.Shortcut("Game4", "/Path/to/game4", "/Path/to", "", [roms.ICE_FLAG_TAG]) old = [shortcut1, shortcut2, shortcut3, shortcut4] new = [shortcut1, shortcut2] self.assertEquals(self.synchronizer.removed_shortcuts(old, new), [shortcut3, shortcut4])
class ROMsTests(unittest.TestCase): def setUp(self): pass @parameterized.expand([ ('Banjo Kazoomie', None, 'Banjo Kazoomie'), ('Banjo Kazoomie', '[Vapor]', '[Vapor] Banjo Kazoomie'), ('Game Name', '!Something!', '!Something! Game Name'), ]) def test_rom_shortcut_name(self, name, console_prefix, expected): console = model.Console( fullname='Nintendo Entertainment System', shortname='NES', extensions='', custom_roms_directory='', prefix=console_prefix, icon='', images_directory='', emulator=None, ) rom = model.ROM(name=name, path='/Path/to/ROM', console=console) self.assertEqual(roms.rom_shortcut_name(rom), expected) @parameterized.expand([( fixtures.roms.banjo_kazooie, steam_model.Shortcut( name='[NES] Banjo Kazooie', exe= '\"/emulators/Mednafen/mednafen\" \"/roms/nes/Banjo Kazooie.nes\"', startdir='/emulators/Mednafen', icon='/consoles/icons/nes.png', tags=['Nintendo Entertainment System']))]) def test_rom_to_shortcut(self, rom, expected): self.assertEqual(roms.rom_to_shortcut(rom), expected)
def json_to_shortcut(json): for field in ["name", "exe", "startdir", "icon", "tags"]: assert (field in json) return model.Shortcut(name=json.get("name"), exe=json.get("exe"), startdir=json.get("startdir"), icon=json.get("icon"), tags=json.get("tags"))
def test_sync_roms_for_user_logs_when_a_rom_is_removed(self): shortcut = steam_model.Shortcut("Game", "/Path/to/game", "/Path/to", "", [roms.ICE_FLAG_TAG]) self._set_users_shortcuts([shortcut]) self.synchronizer.sync_roms_for_user(self.user_fixture.get_context(), [], None) verify(self.mock_logger).info(any())
def test_unmanaged_shortcuts_doesnt_return_shortcut_with_flag_tag(self): tagged_shortcut = steam_model.Shortcut("Game", "/Path/to/game", "/Path/to", "", [roms.ICE_FLAG_TAG]) unmanaged = self.synchronizer.unmanaged_shortcuts([], [tagged_shortcut], None) self.assertEquals(unmanaged, [])
def _adjust_shortcut_exe(self, shortcut): return model.Shortcut( name=shortcut.name, exe=self._adjust_json_path(shortcut.exe), startdir=shortcut.startdir, icon=shortcut.icon, tags=shortcut.tags, )
def rom_to_shortcut(rom): emu = rom.console.emulator assert (emu is not None) return model.Shortcut(name=rom_shortcut_name(rom), exe=emulators.emulator_rom_launch_command(emu, rom), startdir=emulators.emulator_startdir(emu), icon=rom.console.icon, tags=[rom.console.fullname])
def test_unmanaged_shortcuts_returns_shortcut_not_affiliated_with_ice( self): random_shortcut = steam_model.Shortcut("Plex", "/Some/Random/Path/plex", "/Some/Random/Path", "", []) unmanaged = self.synchronizer.unmanaged_shortcuts([], [random_shortcut], None) self.assertEquals(unmanaged, [random_shortcut])
def test_unmanaged_shortcuts_filters_suspicious_shortcuts_when_given_no_history( self): dummy_console = self._create_dummy_console("/Some/Path") random_shortcut = steam_model.Shortcut( "Iron Man", "/Some/Emulator/Path/emulator /Some/Path/Iron Man", "/Some/Emulator/Path", "", []) unmanaged = self.synchronizer.unmanaged_shortcuts( None, [random_shortcut], [dummy_console]) self.assertEquals(unmanaged, [])
def test_unmanaged_shortcuts_returns_all_shortcuts_when_given_no_history( self): dummy_console = self._create_dummy_console("/Some/Other/Path") random_shortcut = steam_model.Shortcut("Plex", "/Some/Random/Path/plex", "/Some/Random/Path", "", []) unmanaged = self.synchronizer.unmanaged_shortcuts( None, [random_shortcut], [dummy_console]) self.assertEquals(unmanaged, [random_shortcut])
def test_unmanaged_shortcuts_filters_suspicious_shortcuts_when_given_no_history( self): mock_config = self._create_dummy_configuration_with_roms_dir( "/Some/Path") random_shortcut = steam_model.Shortcut( "Iron Man", "/Some/Emulator/Path/emulator /Some/Path/Iron Man", "/Some/Emulator/Path", "", []) unmanaged = self.synchronizer.unmanaged_shortcuts( None, [random_shortcut], mock_config) self.assertEquals(unmanaged, [])
def test_unmanaged_shortcuts_returns_all_shortcuts_when_given_no_history( self): mock_config = self._create_dummy_configuration_with_roms_dir( "/Some/Other/Path") random_shortcut = steam_model.Shortcut("Plex", "/Some/Random/Path/plex", "/Some/Random/Path", "", []) unmanaged = self.synchronizer.unmanaged_shortcuts( None, [random_shortcut], mock_config) self.assertEquals(unmanaged, [random_shortcut])
def test_add_rom_for_two_users_with_different_preexisting_shortcuts(self): self.env.load_test_data(os.path.join("smoke", "adding_single_rom")) u1 = self.env.create_fake_user() u2 = self.env.create_fake_user() u2_shortcut = model.Shortcut('Plex', '/Path/to/Plex', '/Path/to', '', []) preexisting_shortcuts = [u2_shortcut] self.env.set_user_shortcuts(u2, preexisting_shortcuts) self.env.run_command() expected = self.env.expected_shortcuts() u1_synced_shortcuts = self.env.user_shortcuts(u1) self.assertNotIn(u2_shortcut, u1_synced_shortcuts) for shortcut in expected: self.assertIn(shortcut, u1_synced_shortcuts) u2_synced_shortcuts = self.env.user_shortcuts(u2) self.assertIn(u2_shortcut, u2_synced_shortcuts) for shortcut in expected: self.assertIn(shortcut, u2_synced_shortcuts)
def test_create_backup_of_shortcuts_creates_copy_of_shortcuts_at_backup_path(self): tempdir = tempfile.mkdtemp() backup_dir = os.path.join(tempdir, "Backups") config = mock() config.backup_directory = backup_dir user = self.user_fixture.get_context() shortcut = model.Shortcut('Plex', '/Path/to/plex', '/Path/to', '', []) user_shortcuts = [shortcut] shortcuts.set_shortcuts(user, user_shortcuts) backups.create_backup_of_shortcuts(config, user) expected_path = backups.shortcuts_backup_path(backup_dir, user) self.assertTrue(os.path.exists(expected_path)) self.assertEqual(shortcuts.read_shortcuts(expected_path), user_shortcuts) shutil.rmtree(tempdir)
def test_sync_roms_for_user_keeps_unmanaged_shortcuts(self): random_shortcut = steam_model.Shortcut("Plex", "/Some/Random/Path/plex", "/Some/Random/Path", "", []) self._set_users_shortcuts([random_shortcut]) when(self.mock_archive).previous_managed_ids( self.user_fixture.get_context()).thenReturn([]) rom1 = model.ROM(name='Game1', path='/Path/to/game1', console=fixtures.consoles.flagged) shortcut1 = roms.rom_to_shortcut(rom1) rom2 = model.ROM(name='Game2', path='/Path/to/game2', console=fixtures.consoles.flagged) shortcut2 = roms.rom_to_shortcut(rom2) rom3 = model.ROM(name='Game3', path='/Path/to/game3', console=fixtures.consoles.flagged) shortcut3 = roms.rom_to_shortcut(rom3) rom4 = model.ROM(name='Game4', path='/Path/to/game4', console=fixtures.consoles.flagged) shortcut4 = roms.rom_to_shortcut(rom4) self.synchronizer.sync_roms_for_user(self.user_fixture.get_context(), [rom1, rom2, rom3, rom4], None) new_shortcuts = shortcuts.get_shortcuts( self.user_fixture.get_context()) self.assertEquals(len(new_shortcuts), 5) self.assertIn(random_shortcut, new_shortcuts) self.assertIn(shortcut1, new_shortcuts) self.assertIn(shortcut2, new_shortcuts) self.assertIn(shortcut3, new_shortcuts) self.assertIn(shortcut4, new_shortcuts)
def _dummy_shortcut(): return model.Shortcut("Banjo Kazooie", "Banjo Kazooie.exe", "", "", [])
def test_appid_generation(self, name, exe, expected): """Tests that pysteam generates the correct appid hash for shortcuts.""" s = model.Shortcut(name, exe, "", "", None) self.assertEqual(shortcuts.shortcut_app_id(s), expected)