Пример #1
0
 def test_hate(self):
     genre_p = []
     artist_p = []
     album_p = []
     white_p = []
     task = ImportTask()
     task.cur_artist = u'Test Artist'
     task.cur_album = u'Test Album'
     task.items = [Item({'genre': 'Test Genre'})]
     self.assertFalse(IHatePlugin.do_i_hate_this(task, genre_p, artist_p, 
                                                 album_p, white_p))
     genre_p = 'some_genre test\sgenre'.split()
     self.assertTrue(IHatePlugin.do_i_hate_this(task, genre_p, artist_p, 
                                                album_p, white_p))
     genre_p = []
     artist_p = 'bad_artist test\sartist'
     self.assertTrue(IHatePlugin.do_i_hate_this(task, genre_p, artist_p, 
                                                album_p, white_p))
     artist_p = []
     album_p = 'tribute christmas test'.split() 
     self.assertTrue(IHatePlugin.do_i_hate_this(task, genre_p, artist_p, 
                                                album_p, white_p))
     album_p = []
     white_p = 'goodband test\sartist another_band'.split()
     genre_p = 'some_genre test\sgenre'.split()
     self.assertFalse(IHatePlugin.do_i_hate_this(task, genre_p, artist_p, 
                                                album_p, white_p))
     genre_p = []
     artist_p = 'bad_artist test\sartist'
     self.assertFalse(IHatePlugin.do_i_hate_this(task, genre_p, artist_p, 
                                                album_p, white_p))
     artist_p = []
     album_p = 'tribute christmas test'.split() 
     self.assertFalse(IHatePlugin.do_i_hate_this(task, genre_p, artist_p, 
                                                album_p, white_p))
Пример #2
0
    def test_hate(self):

        match_pattern = {}
        testItem = Item(
            genre='TestGenre',
            album = u'TestAlbum',
            artist = u'TestArtist')
        task = ImportTask()
        task.items = [testItem]
        task.is_album = False
        #empty query should let it pass
        self.assertFalse(IHatePlugin.do_i_hate_this(task, match_pattern))
        #1 query match
        match_pattern = ["artist:bad_artist","artist:TestArtist"]
        self.assertTrue(IHatePlugin.do_i_hate_this(task, match_pattern))
        #2 query matches, either should trigger
        match_pattern = ["album:test","artist:testartist"]
        self.assertTrue(IHatePlugin.do_i_hate_this(task, match_pattern))
        #query is blocked by AND clause
        match_pattern = ["album:notthis genre:testgenre"]
        self.assertFalse(IHatePlugin.do_i_hate_this(task, match_pattern))
        #both queries are blocked by AND clause with unmatched condition
        match_pattern = ["album:notthis genre:testgenre","artist:testartist album:notthis"]
        self.assertFalse(IHatePlugin.do_i_hate_this(task, match_pattern))
        #only one query should fire
        match_pattern = ["album:testalbum genre:testgenre","artist:testartist album:notthis"]
        self.assertTrue(IHatePlugin.do_i_hate_this(task, match_pattern))
Пример #3
0
    def resolve_duplicate(self, task: ImportTask, found_duplicates):
        old = model_to_cadidate(found_duplicates[0])
        new = model_to_cadidate(task.match)
        event = ImportEvent(EventType.RESOLVE_DUPLICATE, [old, new])
        result = self._adapter.consume_event(event)

        if result.action_type is ActionType.REPLACE_OLD:
            task.should_remove_duplicates = True
        elif result.action_type is ActionType.SKIP_NEW:
            task.set_choice(action.SKIP)
        elif result.action_type is ActionType.KEEP_BOTH:
            pass
        elif result.action_type is ActionType.MERGE:
            task.should_merge_duplicates = True
        elif result.action_type is ActionType.ABORT:
            logging.warn("User initiated abort")
            raise ImportAbort()
        else:
            print("Unkown Action Type")
            raise NotImplementedError
Пример #4
0
    def merge_duplicates(self, task):
        # def emitter():
        duplicate_items = task.duplicate_items(self.lib)
        _freshen_items(duplicate_items)
        duplicate_paths = [item.path for item in duplicate_items]

        # Record merged paths in the session so they are not reimported
        self.mark_merged(duplicate_paths)

        merged_task = ImportTask(None, task.paths + duplicate_paths,
                                 task.items + duplicate_items)

        self.new_pipeline([merged_task], self.lookup_stages())
Пример #5
0
    def test_hate_album(self):
        """ iHate tests for album """

        genre_p = []
        artist_p = []
        album_p = []
        white_p = []
        task = ImportTask()
        task.cur_artist = u'Test Artist'
        task.cur_album = u'Test Album'
        task.items = [Item(genre='Test Genre')]
        self.assertFalse(IHatePlugin.do_i_hate_this(task, genre_p, artist_p,
                                                    album_p, white_p))
        genre_p = 'some_genre test\sgenre'.split()
        self.assertTrue(IHatePlugin.do_i_hate_this(task, genre_p, artist_p,
                                                   album_p, white_p))
        genre_p = []
        artist_p = 'bad_artist test\sartist'
        self.assertTrue(IHatePlugin.do_i_hate_this(task, genre_p, artist_p,
                                                   album_p, white_p))
        artist_p = []
        album_p = 'tribute christmas test'.split()
        self.assertTrue(IHatePlugin.do_i_hate_this(task, genre_p, artist_p,
                                                   album_p, white_p))
        album_p = []
        white_p = 'goodband test\sartist another_band'.split()
        genre_p = 'some_genre test\sgenre'.split()
        self.assertFalse(IHatePlugin.do_i_hate_this(task, genre_p, artist_p,
                                                   album_p, white_p))
        genre_p = []
        artist_p = 'bad_artist test\sartist'
        self.assertFalse(IHatePlugin.do_i_hate_this(task, genre_p, artist_p,
                                                   album_p, white_p))
        artist_p = []
        album_p = 'tribute christmas test'.split()
        self.assertFalse(IHatePlugin.do_i_hate_this(task, genre_p, artist_p,
                                                   album_p, white_p))
Пример #6
0
    def merge_duplicates(self, task_id):
        task = self.tasks.pop(task_id, None)
        if not task:
            print(task, "not in tasks")
            return
        task = self.tasks[task_id]
        # def emitter():
        duplicate_items = task.duplicate_items(self.lib)
        _freshen_items(duplicate_items)
        duplicate_paths = [item.path for item in duplicate_items]

        # Record merged paths in the session so they are not reimported
        self.mark_merged(duplicate_paths)

        merged_task = ImportTask(None, task.paths + duplicate_paths,
                                 task.items + duplicate_items)

        self.new_pipeline([merged_task], self.lookup_stages())