'Check never_subscribed streams are fetched correctly and not include invite_only streams.'

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

    realm = get_realm('zulip')
    streams = [('stream_%s' % i) for i in range(10)]
    for stream_name in streams:
        self.make_stream(stream_name, realm=realm)
    users_to_subscribe = [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)
    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)
    with queries_captured() as queries:
        (subscribed, unsubscribed, never_subscribed) = gather_subscriptions_helper(self.user_profile)
    self.assertTrue((len(never_subscribed) >= 10))
    for stream_dict in never_subscribed:
        if stream_dict['name'].startswith('stream_'):
            self.assertFalse((stream_dict['name'] == 'stream_invite_only_1'))
            self.assertTrue((len(stream_dict['subscribers']) == len(users_to_subscribe)))
    self.assert_length(queries, 3)
