<commit_before>import re
import functools
import json
from io import BytesIO

from pytest import fixture, mark
from urllib.parse import urlparse, parse_qs
from tornado.httpclient import HTTPRequest, HTTPResponse
from tornado.httputil import HTTPHeaders

from ..cilogon import CILogonOAuthenticator

from .mocks import setup_oauth_mock


def user_model(username):
    """Return a user model"""
    return {
        'sub': 'http://cilogon.org/dinosaurs/users/%s/1729' % username,
    }


@fixture
def cilogon_client(client):
    setup_oauth_mock(client,
                     host='cilogon.org',
                     access_token_path='/oauth2/token',
                     user_path='/oauth2/userinfo',
                     token_type='token',
                     )
    return client


@mark.gen_test
def test_cilogon(cilogon_client):
    authenticator = CILogonOAuthenticator()
    handler = cilogon_client.handler_for_user(user_model('wash'))
    user_info = yield authenticator.authenticate(handler)
    print(json.dumps(user_info, sort_keys=True, indent=4))
    name = user_info['name']
    assert name == 'http://cilogon.org/dinosaurs/users/wash/1729'
    auth_state = user_info['auth_state']
    assert 'access_token' in auth_state
    assert auth_state == {
        'access_token': auth_state['access_token'],
        'cilogon_user': {
            'sub': name
        }
    }<commit_msg>update cilogon test<commit_after>import json

from pytest import fixture, mark

from ..cilogon import CILogonOAuthenticator

from .mocks import setup_oauth_mock


def user_model(username):
    """Return a user model"""
    return {
        'eppn': username + '@serenity.space',
    }


@fixture
def cilogon_client(client):
    setup_oauth_mock(client,
                     host='cilogon.org',
                     access_token_path='/oauth2/token',
                     user_path='/oauth2/userinfo',
                     token_type='token',
                     )
    return client


@mark.gen_test
def test_cilogon(cilogon_client):
    authenticator = CILogonOAuthenticator()
    handler = cilogon_client.handler_for_user(user_model('wash'))
    user_info = yield authenticator.authenticate(handler)
    print(json.dumps(user_info, sort_keys=True, indent=4))
    name = user_info['name']
    assert name == '<EMAIL>'
    auth_state = user_info['auth_state']
    assert 'access_token' in auth_state
    assert auth_state == {
        'access_token': auth_state['access_token'],
        'cilogon_user': user_model('wash'),
    }
{'fraction_non_alphanumeric': 0.10400952759031362, 'fraction_numerical': 0.0055577610162763, 'mean_word_length': 2.9375, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1867814', 'n_tokens_mistral': 823, 'n_tokens_neox': 770, 'n_words': 155}