'Testing whether the API returns inserted channels when fetching discovered channels'

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

    self.should_check_equality = False
    for i in xrange(0, 10):
        self.insert_channel_in_db(('rand%d' % i), (42 + i), ('Test    channel    %d' % i), ('Test    description    %d' % i))
    self.insert_channel_in_db('randbad', 100, 'badterm', 'Test    description    bad')
    def verify_channels(channels):
        channels_json = json.loads(channels)['channels']
        self.assertEqual(len(channels_json), 10)
        channels_json = sorted(channels_json, key=(lambda channel: channel['name']))
        for ind in xrange(len(channels_json)):
            self.assertEqual(channels_json[ind]['name'], ('Test    channel    %d' % ind))
    return self.do_request('channels/discovered', expected_code=200).addCallback(verify_channels)
