'Testing whether the API returns the right JSON data if playlists are fetched'

@deferred(timeout=10)
def test_playlists_endpoint(self):

    my_channel_id = self.create_my_channel('my    channel', 'this    is    a    short    description')
    channel_cid = 'fakedispersyid'.encode('hex')
    self.create_playlist(my_channel_id, 1234, 42, 'test    playlist', 'test    description')
    torrent_list = [[my_channel_id, 1, 1, ('a' * 40).decode('hex'), 1460000000, 'ubuntu-torrent.iso', [['file1.txt', 42]], []], [my_channel_id, 1, 1, ('b' * 40).decode('hex'), 1460000000, 'badterm', [['file1.txt', 42]], []]]
    self.insert_torrents_into_channel(torrent_list)
    self.insert_torrent_into_playlist(1234, ('a' * 40).decode('hex'))
    self.insert_torrent_into_playlist(1234, ('b' * 40).decode('hex'))
    def verify_playlists(results):
        json_result = json.loads(results)
        self.assertTrue(('playlists' in json_result))
        self.assertEqual(len(json_result['playlists']), 1)
        self.assertTrue(('torrents' in json_result['playlists'][0]))
        self.assertEqual(len(json_result['playlists'][0]['torrents']), 1)
        torrent = json_result['playlists'][0]['torrents'][0]
        self.assertEqual(torrent['infohash'], ('a' * 40))
        self.assertEqual(torrent['name'], 'ubuntu-torrent.iso')
    self.should_check_equality = False
    return self.do_request(('channels/discovered/%s/playlists' % channel_cid), expected_code=200).addCallback(verify_playlists)
