Esempio n. 1
0
    def test_search(self):
        songs_library = Songs(Songs.TEST_FILE)
        songs = json.loads(songs_library.search_songs('Lycanthropic'))
        self.assertEqual("Lycanthropic Metamorphosis", songs[0]['title'])
        self.assertEqual(1, len(songs))
        results = json.loads(songs_library.search_songs('metamorphosis'))
        self.assertEqual(1, len(songs))
        self.assertEqual("Lycanthropic Metamorphosis", songs[0]['title'])

        songs = json.loads(songs_library.search_songs('The YOUsicians'))
        self.assertEqual(5, len(songs))
        self.assertEqual("Lycanthropic Metamorphosis", songs[0]['title'])
        self.assertEqual("Wishing In The Night", songs[1]['title'])
        self.assertEqual("You've Got The Power", songs[2]['title'])
        self.assertEqual("Opa Opa Ta Bouzoukia", songs[3]['title'])
        self.assertEqual("A New Kennel", songs[4]['title'])

        songs = json.loads(songs_library.search_songs('xx'))
        self.assertEqual(0, len(songs))

        songs = json.loads(songs_library.search_songs(''))
        self.assertEqual(6, len(songs))
Esempio n. 2
0
def search_songs():
    phrase = request.args.get('phrase', '')
    songs_library = Songs(Songs.TEST_FILE)
    return songs_library.search_songs(phrase)