示例#1
0
    def test_set_custom_image_removes_preexisting_image(self):
        app_id = '4567'
        ext = '.png'

        self._create_file_with_extension(app_id, ext)
        original_path = grid.get_custom_image(self.context, app_id)

        new_image_source = os.path.join(self.tempdir, 'foo.jpeg')
        self._write_file_to_path(new_image_source, 'bar')
        self.assertTrue(
            grid.set_custom_image(self.context, app_id, new_image_source))

        new_path = grid.get_custom_image(self.context, app_id)
        self.assertFalse(original_path == new_path)
        self.assertFalse(os.path.exists(original_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')
示例#3
0
    def test_set_custom_image_doesnt_remove_old_image_or_write_new_one_when_image_has_an_invalid_extension(
            self):
        app_id = '4567'
        ext = '.png'

        self._create_file_with_extension(app_id, ext)
        original_path = grid.get_custom_image(self.context, app_id)

        new_image_source = os.path.join(self.tempdir, 'foo.bmp')
        self._write_file_to_path(new_image_source, 'bar')
        self.assertFalse(
            grid.set_custom_image(self.context, app_id, new_image_source))

        self.assertEqual(grid.get_custom_image(self.context, app_id),
                         original_path)
        self.assertFalse(
            os.path.exists(self._custom_image_path(app_id, '.bmp')))
示例#4
0
    def test_set_custom_image_doesnt_remove_old_image_if_new_path_is_none_or_dne(
            self):
        app_id = '4567'
        ext = '.png'

        self._create_file_with_extension(app_id, ext)
        original_path = grid.get_custom_image(self.context, app_id)

        self.assertFalse(grid.set_custom_image(self.context, app_id, None))
        self.assertEqual(grid.get_custom_image(self.context, app_id),
                         original_path)

        new_image = os.path.join(self.tempdir, 'dne.png')
        self.assertFalse(grid.set_custom_image(self.context, app_id,
                                               new_image))
        self.assertEqual(grid.get_custom_image(self.context, app_id),
                         original_path)
示例#5
0
    def test_set_custom_image_writes_image_to_new_location(self):
        app_id = '4567'
        ext = '.png'

        self._create_file_with_extension(app_id, ext)
        old_contents = self._read_file(
            grid.get_custom_image(self.context, app_id))

        new_image_source = os.path.join(self.tempdir, 'foo.png')
        self._write_file_to_path(new_image_source, 'bar')
        self.assertTrue(
            grid.set_custom_image(self.context, app_id, new_image_source))

        new_contents = self._read_file(
            grid.get_custom_image(self.context, app_id))
        self.assertEqual(new_contents, 'bar')
        self.assertFalse(old_contents == new_contents)
示例#6
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)
示例#7
0
 def test_get_custom_image(self):
     app_id = '4567'
     extension = '.png'
     self._create_file_with_extension(app_id, extension)
     expected = self._custom_image_path(app_id, extension)
     self.assertEqual(grid.get_custom_image(self.context, app_id), expected)
示例#8
0
 def test_get_custom_image_returns_none_for_invalid_extension(self):
     app_id = '4567'
     self._create_file_with_extension(app_id, '.bmp')
     self.assertEqual(grid.get_custom_image(self.context, app_id), None)