'Calling POST /json/users/me/subscriptions in a new realm
should notify with a proper new stream link'

def test_successful_cross_realm_notification(self):

    (realm, _) = do_create_realm('testrealm', 'Test    Realm')
    notifications_stream = Stream.objects.get(name='announce', realm=realm)
    realm.notifications_stream = notifications_stream
    realm.save()
    invite_streams = ['cross_stream']
    user = self.example_user('AARON')
    user.realm = realm
    user.save()
    cache.cache_delete(cache.user_profile_by_email_cache_key(user.email))
    result = self.common_subscribe_to_streams(user.email, invite_streams, extra_post_data=dict(announce='true'))
    self.assert_json_success(result)
    msg = self.get_second_to_last_message()
    self.assertEqual(msg.recipient.type, Recipient.STREAM)
    self.assertEqual(msg.sender_id, self.notification_bot().id)
    stream_id = Stream.objects.latest('id').id
    expected_rendered_msg = ('<p>%s    just    created    a    new    stream    <a    class="stream"    data-stream-id="%d"    href="/#narrow/stream/%s">#%s</a>.</p>' % (user.full_name, stream_id, invite_streams[0], invite_streams[0]))
    self.assertEqual(msg.rendered_content, expected_rendered_msg)
