'Check users getting add_peer_event is correct'

def test_users_getting_remove_peer_event(self):

    email1 = self.example_email('othello')
    email2 = self.example_email('cordelia')
    email3 = self.example_email('hamlet')
    email4 = self.example_email('iago')
    realm = get_realm('zulip')
    stream1 = self.make_stream('stream1')
    stream2 = self.make_stream('stream2')
    private = self.make_stream('private_stream', invite_only=True)
    self.subscribe_to_stream(email1, 'stream1')
    self.subscribe_to_stream(email2, 'stream1')
    self.subscribe_to_stream(email3, 'stream1')
    self.subscribe_to_stream(email2, 'stream2')
    self.subscribe_to_stream(email1, 'private_stream')
    self.subscribe_to_stream(email2, 'private_stream')
    self.subscribe_to_stream(email3, 'private_stream')
    user1 = get_user(email1, realm)
    user2 = get_user(email2, realm)
    user3 = get_user(email3, realm)
    user4 = get_user(email4, realm)
    events = []
    with tornado_redirected_to_list(events):
        bulk_remove_subscriptions(users=[user1, user2], streams=[stream1, stream2, private])
    peer_events = [e for e in events if (e['event'].get('op') == 'peer_remove')]
    notifications = set()
    for event in peer_events:
        for user_id in event['users']:
            for stream_name in event['event']['subscriptions']:
                removed_user_id = event['event']['user_id']
                notifications.add((user_id, removed_user_id, stream_name))
    self.assertIn((user3.id, user1.id, 'stream1'), notifications)
    self.assertIn((user4.id, user1.id, 'stream1'), notifications)
    self.assertIn((user3.id, user2.id, 'stream1'), notifications)
    self.assertIn((user4.id, user2.id, 'stream1'), notifications)
    self.assertIn((user1.id, user2.id, 'stream2'), notifications)
    self.assertIn((user3.id, user2.id, 'stream2'), notifications)
    self.assertIn((user4.id, user2.id, 'stream2'), notifications)
    self.assertIn((user3.id, user1.id, 'private_stream'), notifications)
    self.assertIn((user3.id, user2.id, 'private_stream'), notifications)
    self.assertNotIn((user1.id, user1.id, 'stream1'), notifications)
    self.assertNotIn((user3.id, user1.id, 'stream2'), notifications)
    self.assertNotIn((user3.id, user4.id, 'stream2'), notifications)
    self.assertNotIn((user4.id, user1.id, 'private_stream'), notifications)
