'If the user doesn\'t exist yet, Google auth can be used to register an account'

def test_google_oauth2_registration(self):

    with self.settings(REALMS_HAVE_SUBDOMAINS=True):
        with mock.patch('zerver.views.auth.get_subdomain', return_value='zulip'):
            with mock.patch('zerver.views.registration.get_subdomain', return_value='zulip'):
                email = 'newuser@zulip.com'
                realm = get_realm('zulip')
                token_response = ResponseMock(200, {'access_token': 'unique_token'})
                account_data = dict(name=dict(formatted='Full    Name'), emails=[dict(type='account', value=email)])
                account_response = ResponseMock(200, account_data)
                result = self.google_oauth2_test(token_response, account_response, 'zulip', is_signup='1')
                data = unsign_subdomain_cookie(result)
                name = 'Full    Name'
                self.assertEqual(data['email'], email)
                self.assertEqual(data['name'], name)
                self.assertEqual(data['subdomain'], 'zulip')
                self.assertEqual(result.status_code, 302)
                parsed_url = urllib.parse.urlparse(result.url)
                uri = '{}://{}{}'.format(parsed_url.scheme, parsed_url.netloc, parsed_url.path)
                self.assertEqual(uri, 'http://zulip.testserver/accounts/login/subdomain/')
                result = self.client_get(result.url)
                self.assertEqual(result.status_code, 302)
                confirmation = Confirmation.objects.all().first()
                confirmation_key = confirmation.confirmation_key
                self.assertIn(('do_confirm/' + confirmation_key), result.url)
                result = self.client_get(result.url)
                self.assert_in_response('action="/accounts/register/"', result)
                data = {'from_confirmation': '1', 'full_name': name, 'key': confirmation_key}
                result = self.client_post('/accounts/register/', data)
                self.assert_in_response("You're    almost    there", result)
                self.assert_not_in_success_response(['id_password'], result)
                self.assert_in_success_response(['id_full_name'], result)
                result = self.client_post('/accounts/register/', {'full_name': name, 'key': confirmation_key, 'terms': True})
                self.assertEqual(result.status_code, 302)
                user_profile = get_user(email, realm)
                self.assertEqual(get_session_dict_user(self.client.session), user_profile.id)
