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

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

    def verify_error_message(body):
        error_response = json.loads(body)
        expected_response = {u'error': {u'handled': True, u'code': u'DuplicateChannelNameError', u'message': (u'Channel    name    already    exists:    %s' % post_data['name'])}}
        self.assertDictContainsSubset(expected_response[u'error'], error_response[u'error'])
    post_data = {'name': "John    Smit's    channel", 'description': "Video's    of    my    cat", 'mode': 'semi-open'}
    self.session.create_channel = self.create_fake_channel_with_existing_name
    self.should_check_equality = False
    return self.do_request('channels/discovered', expected_code=500, expected_json=None, request_type='PUT', post_data=post_data).addCallback(verify_error_message)
