'Testing whether the API returns a formatted 500 error if ValueError is raised'

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

    self.create_fake_channel('channel', '')
    def fake_get_metainfo(_, callback, timeout=10, timeout_callback=None, notify=True):
        raise ValueError(u'Test    error')
    self.session.lm.ltmgr.get_metainfo = fake_get_metainfo
    def verify_error_message(body):
        error_response = json.loads(body)
        expected_response = {u'error': {u'handled': True, u'code': u'ValueError', u'message': u'Test    error'}}
        self.assertDictContainsSubset(expected_response[u'error'], error_response[u'error'])
    torrent_url = 'magnet:fake'
    url = ('channels/discovered/%s/torrents/%s' % ('fakedispersyid'.encode('hex'), urllib.quote_plus(torrent_url)))
    self.should_check_equality = False
    return self.do_request(url, expected_code=500, expected_json=None, request_type='PUT').addCallback(verify_error_message)
