'Delete the stream and assess the result.'

def delete_stream(self, stream):

    active_name = stream.name
    realm = stream.realm
    stream_id = stream.id
    events = []
    with tornado_redirected_to_list(events):
        result = self.client_delete(('/json/streams/' + str(stream_id)))
    self.assert_json_success(result)
    sub_events = [e for e in events if (e['event']['type'] == 'subscription')]
    self.assertEqual(sub_events, [])
    stream_events = [e for e in events if (e['event']['type'] == 'stream')]
    self.assertEqual(len(stream_events), 1)
    event = stream_events[0]['event']
    self.assertEqual(event['op'], 'delete')
    self.assertEqual(event['streams'][0]['stream_id'], stream.id)
    with self.assertRaises(Stream.DoesNotExist):
        Stream.objects.get(realm=get_realm('zulip'), name=active_name)
    deactivated_stream_name = ('!DEACTIVATED:' + active_name)
    deactivated_stream = get_stream(deactivated_stream_name, realm)
    self.assertTrue(deactivated_stream.deactivated)
    self.assertTrue(deactivated_stream.invite_only)
    self.assertEqual(deactivated_stream.name, deactivated_stream_name)
    subscribers = self.users_subscribed_to_stream(deactivated_stream_name, realm)
    self.assertEqual(subscribers, [])
    result = self.client_get('/json/streams?include_subscribed=false')
    public_streams = [s['name'] for s in ujson.loads(result.content)['streams']]
    self.assertNotIn(active_name, public_streams)
    self.assertNotIn(deactivated_stream_name, public_streams)
    result = self.client_post('/json/users/me/subscriptions', {'subscriptions': ujson.dumps([{'name': deactivated_stream_name}])})
    self.assert_json_error(result, ('Unable    to    access    stream    (%s).' % (deactivated_stream_name,)))
