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_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)
Exemple #4
0
    def update_rom_artwork(self, user, rom, dry_run=False):
        shortcut = roms.rom_to_shortcut(rom)
        logger.debug("Updating image for %s (%s)" % (rom, shortcut))
        app_id = shortcuts.shortcut_app_id(shortcut)

        if grid.has_custom_image(user, app_id):
            existing_image = grid.get_custom_image(user, app_id)
            logger.debug(
                "Not looking for new images for %s, it already has a grid image (%s)"
                % (shortcut.name, existing_image)
            )
            return

        path = self.provider.image_for_rom(rom)

        if path is None:
            logger.info("No image found for `%s`" % shortcut.name)
            return

        if dry_run:
            logger.debug("Found image, but not setting because its a dry run")
            return

        logger.info("Found grid image for `%s`" % shortcut.name)
        grid.set_custom_image(user, app_id, path)
    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")
Exemple #8
0
  def update_rom_artwork(self, user, rom, dry_run=False):
    shortcut = roms.rom_to_shortcut(rom)
    logger.debug("Updating image for %s (%s)" % (rom, shortcut))
    app_id = shortcuts.shortcut_app_id(shortcut)

    if grid.has_custom_image(user, app_id):
      existing_image = grid.get_custom_image(user, app_id)
      logger.debug("Not looking for new images for %s, it already has a grid image (%s)" % (shortcut.name, existing_image))
      return

    path = self.provider.image_for_rom(rom)

    if path is None:
      logger.info("No image found for `%s`" % shortcut.name)
      return

    if dry_run:
      logger.debug("Found image, but not setting because its a dry run")
      return

    logger.info("Found grid image for `%s`" % shortcut.name)
    grid.set_custom_image(user, app_id, path)
Exemple #9
0
 def test_has_custom_image(self, extension, expected):
   """Tests that has_custom_image finds images with the right extension"""
   app_id = '4567'
   self._create_file_with_extension(app_id, extension)
   self.assertEqual(grid.has_custom_image(self.context, app_id), expected)
Exemple #10
0
 def test_has_custom_image(self, extension, expected):
     """Tests that has_custom_image finds images with the right extension"""
     app_id = '4567'
     self._create_file_with_extension(app_id, extension)
     self.assertEqual(grid.has_custom_image(self.context, app_id), expected)