def test_sync_roms_for_user_both_adds_and_removes_roms(self): 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) old_shortcuts = [shortcut1, shortcut2, shortcut4] self._set_users_shortcuts(old_shortcuts) self.synchronizer.sync_roms_for_user(self.user_fixture.get_context(), [rom1, rom2, rom3], None) new_shortcuts = shortcuts.get_shortcuts( self.user_fixture.get_context()) verify(self.mock_logger, times=2).info(any()) self.assertEquals(len(new_shortcuts), 3) self.assertIn(shortcut1, new_shortcuts) self.assertIn(shortcut2, new_shortcuts) self.assertIn(shortcut3, new_shortcuts)
def test_sync_roms_for_user_sets_managed_ids(self): 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) self._set_users_shortcuts([]) self.synchronizer.sync_roms_for_user(self.user_fixture.get_context(), [rom1, rom2], None) new_managed_ids = map(shortcuts.shortcut_app_id, [shortcut1, shortcut2]) verify(self.mock_archive).set_managed_ids(self.user_fixture.get_context(), new_managed_ids)
def test_sync_roms_for_user_logs_once_for_each_added_rom(self): self._set_users_shortcuts([]) 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) self.synchronizer.sync_roms_for_user(self.user_fixture.get_context(), [rom1, rom2, rom3], None) verify(self.mock_logger, times=3).info(any())
def test_updater_keeps_image_if_already_exists(self): rom = model.ROM(name='Game1', path='/Path/to/game1', console=fixtures.consoles.flagged) shortcut = roms.rom_to_shortcut(rom) # Start with a custom image, say a .png (handle, path) = tempfile.mkstemp('.png') grid.set_custom_image(self.user_fixture.get_context(), shortcuts.shortcut_app_id(shortcut), path) os.remove(path) # Make the provider return a .jpg (handle, path) = tempfile.mkstemp('.jpg') when(self.mock_provider).image_for_rom(rom).thenReturn(path) self.assertTrue( grid.has_custom_image(self.user_fixture.get_context(), shortcuts.shortcut_app_id(shortcut))) self.updater.update_rom_artwork(self.user_fixture.get_context(), rom) self.assertTrue( grid.has_custom_image(self.user_fixture.get_context(), shortcuts.shortcut_app_id(shortcut))) # Ensure that we are still using the .png, not the .jpg (_, ext) = os.path.splitext( grid.get_custom_image(self.user_fixture.get_context(), shortcuts.shortcut_app_id(shortcut))) self.assertEqual(ext, '.png')
def test_sync_roms_for_user_logs_when_a_rom_is_added(self): self._set_users_shortcuts([]) rom = model.ROM(name = 'Game1', path = '/Path/to/game1', console = fixtures.consoles.flagged) shortcut = roms.rom_to_shortcut(rom) self.synchronizer.sync_roms_for_user(self.user_fixture.get_context(), [rom], None) verify(self.mock_logger).info(any())
def test_sync_roms_for_user_sets_managed_ids(self): 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) self._set_users_shortcuts([]) self.synchronizer.sync_roms_for_user(self.user_fixture.get_context(), [rom1, rom2], None) new_managed_ids = map(shortcuts.shortcut_app_id, [shortcut1, shortcut2]) verify(self.mock_archive).set_managed_ids( self.user_fixture.get_context(), new_managed_ids)
def test_sync_roms_for_user_saves_shortcuts_after_running(self): rom1 = model.ROM(name = 'Game1', path = '/Path/to/game1', console = fixtures.consoles.flagged) shortcut1 = roms.rom_to_shortcut(rom1) self._set_users_shortcuts([]) self.synchronizer.sync_roms_for_user(self.user_fixture.get_context(), [rom1], None) updated_shortcuts = shortcuts.get_shortcuts(self.user_fixture.get_context()) self.assertEquals(updated_shortcuts, [shortcut1])
def test_updater_does_nothing_if_provider_has_no_image(self): rom = model.ROM(name="Game1", path="/Path/to/game1", console=fixtures.consoles.flagged) shortcut = roms.rom_to_shortcut(rom) when(self.mock_provider).image_for_rom(rom).thenReturn(None) self.assertFalse(grid.has_custom_image(self.user_fixture.get_context(), shortcuts.shortcut_app_id(shortcut))) self.updater.update_rom_artwork(self.user_fixture.get_context(), rom) self.assertFalse(grid.has_custom_image(self.user_fixture.get_context(), shortcuts.shortcut_app_id(shortcut)))
def test_sync_roms_for_user_logs_once_for_each_added_rom(self): self._set_users_shortcuts([]) 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) self.synchronizer.sync_roms_for_user(self.user_fixture.get_context(), [rom1, rom2, rom3], None) verify(self.mock_logger, times=3).info(any())
def test_sync_roms_for_user_logs_when_a_rom_is_added(self): self._set_users_shortcuts([]) rom = model.ROM(name='Game1', path='/Path/to/game1', console=fixtures.consoles.flagged) shortcut = roms.rom_to_shortcut(rom) self.synchronizer.sync_roms_for_user(self.user_fixture.get_context(), [rom], None) verify(self.mock_logger).info(any())
def test_updater_sets_image_if_provider_has_one(self): rom = model.ROM(name="Game1", path="/Path/to/game1", console=fixtures.consoles.flagged) shortcut = roms.rom_to_shortcut(rom) (handle, path) = tempfile.mkstemp(".png") when(self.mock_provider).image_for_rom(rom).thenReturn(path) self.assertFalse(grid.has_custom_image(self.user_fixture.get_context(), shortcuts.shortcut_app_id(shortcut))) self.updater.update_rom_artwork(self.user_fixture.get_context(), rom) self.assertTrue(grid.has_custom_image(self.user_fixture.get_context(), shortcuts.shortcut_app_id(shortcut))) os.remove(path)
def test_sync_roms_for_user_both_adds_and_removes_roms(self): 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) old_shortcuts = [shortcut1, shortcut2, shortcut4] self._set_users_shortcuts(old_shortcuts) self.synchronizer.sync_roms_for_user(self.user_fixture.get_context(), [rom1, rom2, rom3], None) new_shortcuts = shortcuts.get_shortcuts(self.user_fixture.get_context()) verify(self.mock_logger, times=2).info(any()) self.assertEquals(len(new_shortcuts), 3) self.assertIn(shortcut1, new_shortcuts) self.assertIn(shortcut2, new_shortcuts) self.assertIn(shortcut3, new_shortcuts)
def test_sync_roms_for_user_saves_shortcuts_after_running(self): rom1 = model.ROM(name='Game1', path='/Path/to/game1', console=fixtures.consoles.flagged) shortcut1 = roms.rom_to_shortcut(rom1) self._set_users_shortcuts([]) self.synchronizer.sync_roms_for_user(self.user_fixture.get_context(), [rom1], None) updated_shortcuts = shortcuts.get_shortcuts( self.user_fixture.get_context()) self.assertEquals(updated_shortcuts, [shortcut1])
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 test_sync_roms_for_user_keeps_unmanaged_shortcuts(self): random_shortcut = steam_model.Shortcut("Plex", "/Some/Random/Path/plex", "/Some/Random/Path", "", "", "", False, False, False, 0, []) 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 test_updater_does_nothing_if_provider_has_no_image(self): rom = model.ROM(name='Game1', path='/Path/to/game1', console=fixtures.consoles.flagged) shortcut = roms.rom_to_shortcut(rom) when(self.mock_provider).image_for_rom(rom).thenReturn(None) self.assertFalse( grid.has_custom_image(self.user_fixture.get_context(), shortcuts.shortcut_app_id(shortcut))) self.updater.update_rom_artwork(self.user_fixture.get_context(), rom) self.assertFalse( grid.has_custom_image(self.user_fixture.get_context(), shortcuts.shortcut_app_id(shortcut)))
def test_updater_sets_image_if_provider_has_one(self): rom = model.ROM(name='Game1', path='/Path/to/game1', console=fixtures.consoles.flagged) shortcut = roms.rom_to_shortcut(rom) (handle, path) = tempfile.mkstemp('.png') when(self.mock_provider).image_for_rom(rom).thenReturn(path) self.assertFalse( grid.has_custom_image(self.user_fixture.get_context(), shortcuts.shortcut_app_id(shortcut))) self.updater.update_rom_artwork(self.user_fixture.get_context(), rom) self.assertTrue( grid.has_custom_image(self.user_fixture.get_context(), shortcuts.shortcut_app_id(shortcut))) os.remove(path)
def test_updater_keeps_image_if_already_exists(self): rom = model.ROM(name="Game1", path="/Path/to/game1", console=fixtures.consoles.flagged) shortcut = roms.rom_to_shortcut(rom) # Start with a custom image, say a .png (handle, path) = tempfile.mkstemp(".png") grid.set_custom_image(self.user_fixture.get_context(), shortcuts.shortcut_app_id(shortcut), path) os.remove(path) # Make the provider return a .jpg (handle, path) = tempfile.mkstemp(".jpg") when(self.mock_provider).image_for_rom(rom).thenReturn(path) self.assertTrue(grid.has_custom_image(self.user_fixture.get_context(), shortcuts.shortcut_app_id(shortcut))) self.updater.update_rom_artwork(self.user_fixture.get_context(), rom) self.assertTrue(grid.has_custom_image(self.user_fixture.get_context(), shortcuts.shortcut_app_id(shortcut))) # Ensure that we are still using the .png, not the .jpg (_, ext) = os.path.splitext( grid.get_custom_image(self.user_fixture.get_context(), shortcuts.shortcut_app_id(shortcut)) ) self.assertEqual(ext, ".png")
def test_rom_to_shortcut(self, rom, expected): self.assertEqual(roms.rom_to_shortcut(rom), expected)