Example #1
0
    def test_sync_roms_for_user_keeps_unmanaged_shortcuts(self):
        random_shortcut = Shortcut("Plex", "/Some/Random/Path/plex",
                                   "/Some/Random/Path")
        self.mock_user.shortcuts = [random_shortcut]
        when(self.mock_archive).previous_managed_ids(
            self.mock_user).thenReturn([])

        shortcut1 = Shortcut("Game1", "/Path/to/game1", "/Path/to", "",
                             ICE_FLAG_TAG)
        shortcut2 = Shortcut("Game2", "/Path/to/game2", "/Path/to", "",
                             ICE_FLAG_TAG)
        shortcut3 = Shortcut("Game3", "/Path/to/game3", "/Path/to", "",
                             ICE_FLAG_TAG)
        shortcut4 = Shortcut("Game4", "/Path/to/game4", "/Path/to", "",
                             ICE_FLAG_TAG)

        rom1 = mock()
        when(rom1).to_shortcut().thenReturn(shortcut1)
        rom2 = mock()
        when(rom2).to_shortcut().thenReturn(shortcut2)
        rom3 = mock()
        when(rom3).to_shortcut().thenReturn(shortcut3)
        rom4 = mock()
        when(rom4).to_shortcut().thenReturn(shortcut4)

        self.synchronizer.sync_roms_for_user(self.mock_user,
                                             [rom1, rom2, rom3, rom4], None)
        new_shortcuts = self.mock_user.shortcuts

        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)
Example #2
0
    def test_sync_roms_for_user_both_adds_and_removes_roms(self):
        shortcut1 = Shortcut("Game1", "/Path/to/game1", "/Path/to", "",
                             ICE_FLAG_TAG)
        shortcut2 = Shortcut("Game2", "/Path/to/game2", "/Path/to", "",
                             ICE_FLAG_TAG)
        shortcut3 = Shortcut("Game3", "/Path/to/game3", "/Path/to", "",
                             ICE_FLAG_TAG)
        shortcut4 = Shortcut("Game4", "/Path/to/game4", "/Path/to", "",
                             ICE_FLAG_TAG)

        rom1 = mock.MagicMock()
        rom1.to_shortcut.return_value = shortcut1
        rom2 = mock.MagicMock()
        rom2.to_shortcut.return_value = shortcut2
        rom3 = mock.MagicMock()
        rom3.to_shortcut.return_value = shortcut3

        old_shortcuts = [shortcut1, shortcut2, shortcut4]
        self.mock_user.shortcuts = old_shortcuts
        self.synchronizer.sync_roms_for_user(self.mock_user,
                                             [rom1, rom2, rom3])
        new_shortcuts = self.mock_user.shortcuts

        self.assertEquals(self.mock_logger.info.call_count, 2)
        self.assertEquals(len(new_shortcuts), 3)
        self.assertIn(shortcut1, new_shortcuts)
        self.assertIn(shortcut2, new_shortcuts)
        self.assertIn(shortcut3, new_shortcuts)
Example #3
0
    def test_sync_roms_for_user_both_adds_and_removes_roms(self):
        shortcut1 = Shortcut("Game1", "/Path/to/game1", "/Path/to", "",
                             ICE_FLAG_TAG)
        shortcut2 = Shortcut("Game2", "/Path/to/game2", "/Path/to", "",
                             ICE_FLAG_TAG)
        shortcut3 = Shortcut("Game3", "/Path/to/game3", "/Path/to", "",
                             ICE_FLAG_TAG)
        shortcut4 = Shortcut("Game4", "/Path/to/game4", "/Path/to", "",
                             ICE_FLAG_TAG)

        rom1 = mock()
        when(rom1).to_shortcut().thenReturn(shortcut1)
        rom2 = mock()
        when(rom2).to_shortcut().thenReturn(shortcut2)
        rom3 = mock()
        when(rom3).to_shortcut().thenReturn(shortcut3)

        old_shortcuts = [shortcut1, shortcut2, shortcut4]
        self.mock_user.shortcuts = old_shortcuts

        self.synchronizer.sync_roms_for_user(self.mock_user,
                                             [rom1, rom2, rom3], None)
        new_shortcuts = self.mock_user.shortcuts

        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_unmanaged_shortcuts_doesnt_return_shortcut_with_appid_in_managed_ids(self):
   managed_shortcut = Shortcut("Game", "/Path/to/game", "/Path/to", "")
   random_shortcut = Shortcut("Plex", "/Some/Random/Path/plex", "/Some/Random/Path")
   managed_ids = [managed_shortcut.appid()]
   shortcuts = [managed_shortcut, random_shortcut]
   unmanaged = self.synchronizer.unmanaged_shortcuts(managed_ids,shortcuts, None)
   self.assertEquals(unmanaged, [random_shortcut])
Example #5
0
    def test_sync_roms_for_user_keeps_unmanaged_shortcuts(self):
        random_shortcut = Shortcut("Plex", "/Some/Random/Path/plex",
                                   "/Some/Random/Path")
        self.mock_user.shortcuts = [random_shortcut]

        shortcut1 = Shortcut("Game1", "/Path/to/game1", "/Path/to", "",
                             ICE_FLAG_TAG)
        shortcut2 = Shortcut("Game2", "/Path/to/game2", "/Path/to", "",
                             ICE_FLAG_TAG)
        shortcut3 = Shortcut("Game3", "/Path/to/game3", "/Path/to", "",
                             ICE_FLAG_TAG)
        shortcut4 = Shortcut("Game4", "/Path/to/game4", "/Path/to", "",
                             ICE_FLAG_TAG)

        rom1 = mock.MagicMock()
        rom1.to_shortcut.return_value = shortcut1
        rom2 = mock.MagicMock()
        rom2.to_shortcut.return_value = shortcut2
        rom3 = mock.MagicMock()
        rom3.to_shortcut.return_value = shortcut3
        rom4 = mock.MagicMock()
        rom4.to_shortcut.return_value = shortcut4

        self.synchronizer.sync_roms_for_user(self.mock_user,
                                             [rom1, rom2, rom3, rom4])
        new_shortcuts = self.mock_user.shortcuts

        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)
Example #6
0
 def test_removed_shortcuts_doesnt_return_shortcuts_that_still_exist(self):
     shortcut1 = Shortcut("Game1", "/Path/to/game1", "/Path/to", "",
                          ICE_FLAG_TAG)
     shortcut2 = Shortcut("Game2", "/Path/to/game2", "/Path/to", "",
                          ICE_FLAG_TAG)
     old = [shortcut1, shortcut2]
     new = [shortcut1, shortcut2]
     self.assertEquals(self.synchronizer.removed_shortcuts(old, new), [])
Example #7
0
 def test_added_shortcuts_returns_shortcuts_that_didnt_exist_previously(
         self):
     shortcut1 = Shortcut("Game1", "/Path/to/game1", "/Path/to", "",
                          ICE_FLAG_TAG)
     shortcut2 = Shortcut("Game2", "/Path/to/game2", "/Path/to", "",
                          ICE_FLAG_TAG)
     new = [shortcut1, shortcut2]
     self.assertEquals(self.synchronizer.added_shortcuts([], new),
                       [shortcut1, shortcut2])
Example #8
0
 def test_removed_shortcuts_returns_shortcuts_that_dont_exist_anymore(self):
     shortcut1 = Shortcut("Game1", "/Path/to/game1", "/Path/to", "",
                          ICE_FLAG_TAG)
     shortcut2 = Shortcut("Game2", "/Path/to/game2", "/Path/to", "",
                          ICE_FLAG_TAG)
     old = [shortcut1, shortcut2]
     new = []
     self.assertEquals(self.synchronizer.removed_shortcuts(old, new),
                       [shortcut1, shortcut2])
Example #9
0
 def test_unmanaged_shortcuts_doesnt_return_shortcut_with_appid_in_managed_ids(
         self):
     managed_shortcut = Shortcut("Game", "/Path/to/game", "/Path/to", "")
     random_shortcut = Shortcut("Plex", "/Some/Random/Path/plex",
                                "/Some/Random/Path")
     managed_ids = [managed_shortcut.appid()]
     shortcuts = [managed_shortcut, random_shortcut]
     unmanaged = self.synchronizer.unmanaged_shortcuts(
         managed_ids, shortcuts)
     self.assertEquals(unmanaged, [random_shortcut])
Example #10
0
    def test_sync_roms_for_user_logs_once_for_each_removed_rom(self):
        shortcut1 = Shortcut("Game1", "/Path/to/game1", "/Path/to", "",
                             ICE_FLAG_TAG)
        shortcut2 = Shortcut("Game2", "/Path/to/game2", "/Path/to", "",
                             ICE_FLAG_TAG)
        shortcut3 = Shortcut("Game3", "/Path/to/game3", "/Path/to", "",
                             ICE_FLAG_TAG)
        self.mock_user.shortcuts = [shortcut1, shortcut2, shortcut3]

        self.synchronizer.sync_roms_for_user(self.mock_user, [], None)
        verify(self.mock_logger, times=3).info(any())
Example #11
0
    def test_sync_roms_for_user_logs_once_for_each_removed_rom(self):
        shortcut1 = Shortcut("Game1", "/Path/to/game1", "/Path/to", "",
                             ICE_FLAG_TAG)
        shortcut2 = Shortcut("Game2", "/Path/to/game2", "/Path/to", "",
                             ICE_FLAG_TAG)
        shortcut3 = Shortcut("Game3", "/Path/to/game3", "/Path/to", "",
                             ICE_FLAG_TAG)
        self.mock_user.shortcuts = [shortcut1, shortcut2, shortcut3]

        self.synchronizer.sync_roms_for_user(self.mock_user, [])
        self.assertEquals(self.mock_logger.info.call_count, 3)
  def test_sync_roms_for_user_sets_managed_ids(self):
    shortcut1 = Shortcut("Game1", "/Path/to/game1", "/Path/to", "")
    shortcut2 = Shortcut("Game2", "/Path/to/game2", "/Path/to", "")

    rom1 = mock.MagicMock()
    rom1.to_shortcut.return_value = shortcut1
    rom2 = mock.MagicMock()
    rom2.to_shortcut.return_value = shortcut2

    self.synchronizer.sync_roms_for_user(self.mock_user, [rom1, rom2])

    new_managed_ids = [shortcut1.appid(), shortcut2.appid()]
    self.mock_archive.set_managed_ids.assert_called_with(self.mock_user, new_managed_ids)
Example #13
0
 def test_removed_shortcuts_only_returns_shortcuts_that_dont_exist_now_but_did_before(
         self):
     shortcut1 = Shortcut("Game1", "/Path/to/game1", "/Path/to", "",
                          ICE_FLAG_TAG)
     shortcut2 = Shortcut("Game2", "/Path/to/game2", "/Path/to", "",
                          ICE_FLAG_TAG)
     shortcut3 = Shortcut("Game3", "/Path/to/game3", "/Path/to", "",
                          ICE_FLAG_TAG)
     shortcut4 = Shortcut("Game4", "/Path/to/game4", "/Path/to", "",
                          ICE_FLAG_TAG)
     old = [shortcut1, shortcut2, shortcut3, shortcut4]
     new = [shortcut1, shortcut2]
     self.assertEquals(self.synchronizer.removed_shortcuts(old, new),
                       [shortcut3, shortcut4])
  def test_sync_roms_for_user_sets_managed_ids(self):
    shortcut1 = Shortcut("Game1", "/Path/to/game1", "/Path/to", "")
    shortcut2 = Shortcut("Game2", "/Path/to/game2", "/Path/to", "")

    rom1 = mock()
    when(rom1).to_shortcut().thenReturn(shortcut1)
    rom2 = mock()
    when(rom2).to_shortcut().thenReturn(shortcut2)

    self.mock_user.shortcuts = []

    self.synchronizer.sync_roms_for_user(self.mock_user, [rom1, rom2], None)

    new_managed_ids = [shortcut1.appid(), shortcut2.appid()]
    verify(self.mock_archive).set_managed_ids(self.mock_user, new_managed_ids)
Example #15
0
 def test_unmanaged_shortcuts_doesnt_return_shortcut_with_flag_tag(self):
     tagged_shortcut = Shortcut("Game", "/Path/to/game", "/Path/to", "",
                                ICE_FLAG_TAG)
     unmanaged = self.synchronizer.unmanaged_shortcuts([],
                                                       [tagged_shortcut],
                                                       None)
     self.assertEquals(unmanaged, [])
Example #16
0
    def test_sync_roms_for_user_logs_when_a_rom_is_removed(self):
        shortcut = Shortcut("Game", "/Path/to/game", "/Path/to", "",
                            ICE_FLAG_TAG)
        self.mock_user.shortcuts = [shortcut]

        self.synchronizer.sync_roms_for_user(self.mock_user, [])
        self.assertTrue(self.mock_logger.info.called)
Example #17
0
 def test_unmanaged_shortcuts_returns_shortcut_not_affiliated_with_ice(
         self):
     random_shortcut = Shortcut("Plex", "/Some/Random/Path/plex",
                                "/Some/Random/Path")
     unmanaged = self.synchronizer.unmanaged_shortcuts([],
                                                       [random_shortcut])
     self.assertEquals(unmanaged, [random_shortcut])
Example #18
0
    def test_sync_roms_for_user_logs_when_a_rom_is_removed(self):
        shortcut = Shortcut("Game", "/Path/to/game", "/Path/to", "",
                            ICE_FLAG_TAG)
        self.mock_user.shortcuts = [shortcut]

        self.synchronizer.sync_roms_for_user(self.mock_user, [], None)
        verify(self.mock_logger).info(any())
Example #19
0
    def test_sync_roms_for_user_logs_once_for_each_added_rom(self):
        shortcut1 = Shortcut("Game1", "/Path/to/game1", "/Path/to", "",
                             ICE_FLAG_TAG)
        rom1 = mock.MagicMock()
        rom1.to_shortcut.return_value = shortcut1
        shortcut2 = Shortcut("Game2", "/Path/to/game2", "/Path/to", "",
                             ICE_FLAG_TAG)
        rom2 = mock.MagicMock()
        rom2.to_shortcut.return_value = shortcut2
        shortcut3 = Shortcut("Game3", "/Path/to/game3", "/Path/to", "",
                             ICE_FLAG_TAG)
        rom3 = mock.MagicMock()
        rom3.to_shortcut.return_value = shortcut3

        self.synchronizer.sync_roms_for_user(self.mock_user,
                                             [rom1, rom2, rom3])
        self.assertEquals(self.mock_logger.info.call_count, 3)
Example #20
0
    def test_sync_roms_for_user_logs_when_a_rom_is_added(self):
        shortcut = Shortcut("Game", "/Path/to/game", "/Path/to", "",
                            ICE_FLAG_TAG)
        rom = mock.MagicMock()
        rom.to_shortcut.return_value = shortcut

        self.synchronizer.sync_roms_for_user(self.mock_user, [rom])
        self.assertTrue(self.mock_logger.info.called)
Example #21
0
 def to_shortcut(self):
   appname = self.prefixed_name()
   exe = self.console.emulator.command_string(self)
   startdir = self.console.emulator.startdir(self)
   icon = self.console.icon
   category = self.console.fullname
   tags = [category]
   return Shortcut(appname, exe, startdir, icon, tags)
Example #22
0
    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 = Shortcut("Plex", "/Some/Random/Path/plex",
                                   "/Some/Random/Path")

        unmanaged = self.synchronizer.unmanaged_shortcuts(
            None, [random_shortcut], mock_config)

        self.assertEquals(unmanaged, [random_shortcut])
Example #23
0
    def test_sync_roms_for_user_logs_when_a_rom_is_added(self):
        self.mock_user.shortcuts = []

        shortcut = Shortcut("Game", "/Path/to/game", "/Path/to", "",
                            ICE_FLAG_TAG)
        rom = mock()
        when(rom).to_shortcut().thenReturn(shortcut)

        self.synchronizer.sync_roms_for_user(self.mock_user, [rom], None)

        verify(self.mock_logger).info(any())
Example #24
0
    def test_sync_roms_for_user_saves_shortcuts_after_running(self):
        shortcut1 = Shortcut("Game1", "/Path/to/game1", "/Path/to", "",
                             ICE_FLAG_TAG)
        rom1 = mock.MagicMock()
        rom1.to_shortcut.return_value = shortcut1

        self.mock_user.shortcuts = []
        self.synchronizer.sync_roms_for_user(self.mock_user, [rom1])

        self.assertEquals(self.mock_user.shortcuts, [shortcut1])
        self.assertTrue(self.mock_user.save_shortcuts.called)
Example #25
0
    def test_sync_roms_for_user_saves_shortcuts_after_running(self):
        shortcut1 = Shortcut("Game1", "/Path/to/game1", "/Path/to", "",
                             ICE_FLAG_TAG)
        rom1 = mock()
        when(rom1).to_shortcut().thenReturn(shortcut1)

        self.mock_user.shortcuts = []

        self.synchronizer.sync_roms_for_user(self.mock_user, [rom1], None)

        self.assertEquals(self.mock_user.shortcuts, [shortcut1])
        verify(self.mock_user).save_shortcuts()
Example #26
0
    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 = 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, [])
Example #27
0
    def test_sync_roms_for_user_logs_once_for_each_added_rom(self):
        self.mock_user.shortcuts = []

        shortcut1 = Shortcut("Game1", "/Path/to/game1", "/Path/to", "",
                             ICE_FLAG_TAG)
        rom1 = mock()
        when(rom1).to_shortcut().thenReturn(shortcut1)

        shortcut2 = Shortcut("Game2", "/Path/to/game2", "/Path/to", "",
                             ICE_FLAG_TAG)
        rom2 = mock()
        when(rom2).to_shortcut().thenReturn(shortcut2)

        shortcut3 = Shortcut("Game3", "/Path/to/game3", "/Path/to", "",
                             ICE_FLAG_TAG)
        rom3 = mock()
        when(rom3).to_shortcut().thenReturn(shortcut3)

        self.synchronizer.sync_roms_for_user(self.mock_user,
                                             [rom1, rom2, rom3], None)

        verify(self.mock_logger, times=3).info(any())
Example #28
0
    def test_sync_roms_for_user_sets_managed_ids(self):
        shortcut1 = Shortcut("Game1", "/Path/to/game1", "/Path/to", "")
        shortcut2 = Shortcut("Game2", "/Path/to/game2", "/Path/to", "")

        rom1 = mock.MagicMock()
        rom1.to_shortcut.return_value = shortcut1
        rom2 = mock.MagicMock()
        rom2.to_shortcut.return_value = shortcut2

        self.synchronizer.sync_roms_for_user(self.mock_user, [rom1, rom2])

        new_managed_ids = [shortcut1.appid(), shortcut2.appid()]
        self.mock_archive.set_managed_ids.assert_called_with(
            self.mock_user, new_managed_ids)
Example #29
0
    def test_sync_roms_for_user_sets_managed_ids(self):
        shortcut1 = Shortcut("Game1", "/Path/to/game1", "/Path/to", "")
        shortcut2 = Shortcut("Game2", "/Path/to/game2", "/Path/to", "")

        rom1 = mock()
        when(rom1).to_shortcut().thenReturn(shortcut1)
        rom2 = mock()
        when(rom2).to_shortcut().thenReturn(shortcut2)

        self.mock_user.shortcuts = []

        self.synchronizer.sync_roms_for_user(self.mock_user, [rom1, rom2],
                                             None)

        new_managed_ids = [shortcut1.appid(), shortcut2.appid()]
        verify(self.mock_archive).set_managed_ids(self.mock_user,
                                                  new_managed_ids)