'gather_subscriptions returns correct results with only 3 queries
(We also use this test to verify subscription notifications to
folks who get subscribed to streams.)'

@slow('common_subscribe_to_streams    is    slow')
def test_gather_subscriptions(self):

    streams = [('stream_%s' % i) for i in range(10)]
    for stream_name in streams:
        self.make_stream(stream_name)
    users_to_subscribe = [self.email, self.example_email('othello'), self.example_email('cordelia')]
    ret = self.common_subscribe_to_streams(self.email, streams, dict(principals=ujson.dumps(users_to_subscribe)))
    self.assert_json_success(ret)
    msg = "\n                                                Hi    there!        We    thought    you'd    like    to    know    that    King    Hamlet\n                                                just    subscribed    you    to    the    following    streams:\n\n                                                *    #**stream_0**\n                                                *    #**stream_1**\n                                                *    #**stream_2**\n                                                *    #**stream_3**\n                                                *    #**stream_4**\n                                                *    #**stream_5**\n                                                *    #**stream_6**\n                                                *    #**stream_7**\n                                                *    #**stream_8**\n                                                *    #**stream_9**\n\n                                                You    can    see    historical    content    on    a    non-invite-only    stream    by    narrowing    to    it.\n                                                "
    self.assert_user_got_subscription_notification(msg)
    ret = self.common_subscribe_to_streams(self.email, ['stream_invite_only_1'], dict(principals=ujson.dumps([self.email])), invite_only=True)
    self.assert_json_success(ret)
    ret = self.common_subscribe_to_streams(self.email, ['stream_invite_only_1'], dict(principals=ujson.dumps(users_to_subscribe)), invite_only=True)
    self.assert_json_success(ret)
    msg = "\n                                                Hi    there!        We    thought    you'd    like    to    know    that    King    Hamlet\n                                                just    subscribed    you    to    the    **invite-only**    stream\n                                                #**stream_invite_only_1**.\n                                                "
    self.assert_user_got_subscription_notification(msg)
    with queries_captured() as queries:
        subscriptions = gather_subscriptions(self.user_profile)
    self.assertTrue((len(subscriptions[0]) >= 11))
    for sub in subscriptions[0]:
        if (not sub['name'].startswith('stream_')):
            continue
        self.assertTrue((len(sub['subscribers']) == len(users_to_subscribe)))
    self.assert_length(queries, 4)
