<commit_before>"""Tests for the ``signed_request`` module."""

from datetime import datetime, timedelta

from facepy import SignedRequest

TEST_ACCESS_TOKEN = '<KEY>'

TEST_SIGNED_REQUEST = u'mnrG8Wc9CH_rh-GCqq97GFAPOh6AY7cMO8IYVKb6Pa4.eyJhbGdvcml0aG0iOi' \
                      '<KEY>' \
                      '<KEY>' \
                      '<KEY>' \
                      '<KEY>' \
                      '<KEY>'

TEST_FACEBOOK_APPLICATION_SECRET_KEY = '<KEY>'

def test_parse_signed_request():
    signed_request = SignedRequest.parse(
        signed_request = TEST_SIGNED_REQUEST,
        application_secret_key = TEST_FACEBOOK_APPLICATION_SECRET_KEY
    )

    assert signed_request == {
        'user_id': '499729129',
        'algorithm': 'HMAC-SHA256',
        'expires': 0,
        'oauth_token': '<KEY>',
        'user': {
            'locale': 'en_US',
            'country': 'no',
            'age': { 'min': 21 }
        },
        'issued_at': 1306179904
    }

def test_initialize_signed_request():
    signed_request = SignedRequest(
        signed_request = TEST_SIGNED_REQUEST,
        application_secret_key = TEST_FACEBOOK_APPLICATION_SECRET_KEY
    )

    assert signed_request.user.id == '499729129'
    assert signed_request.user.oauth_token.token == TEST_ACCESS_TOKEN
    assert signed_request.user.oauth_token.expires_at == None

    assert signed_request.raw == {
        'user_id': '499729129',
        'algorithm': 'HMAC-SHA256',
        'expires': 0,
        'oauth_token': '<PASSWORD>|<PASSWORD>CW<PASSWORD>_zRk<PASSWORD>',
        'user': {
            'locale': 'en_US',
            'country': 'no',
            'age': { 'min': 21 }
        },
        'issued_at': 1306179904
    }

def test_signed_request_user_has_authorized_application():
    oauth_token = SignedRequest.User.OAuthToken(
        token = '<token>',
        issued_at = datetime.now(),
        expires_at = None
    )

    user = SignedRequest.User(id=1, oauth_token=oauth_token)

    assert user.has_authorized_application == True<commit_msg>Test SignedRequest.User#profile_url<commit_after>"""Tests for the ``signed_request`` module."""

from datetime import datetime, timedelta

from facepy import SignedRequest

TEST_ACCESS_TOKEN = '<KEY>'

TEST_SIGNED_REQUEST = u'mnrG8Wc9CH_rh-GCqq97GFAPOh6AY7cMO8IYVKb6Pa4.eyJhbGdvcml0aG0iOi' \
                      '<KEY>' \
                      '<KEY>' \
                      '<KEY>' \
                      '<KEY>' \
                      '<KEY>'

TEST_FACEBOOK_APPLICATION_SECRET_KEY = '<KEY>'

def test_parse_signed_request():
    signed_request = SignedRequest.parse(
        signed_request = TEST_SIGNED_REQUEST,
        application_secret_key = TEST_FACEBOOK_APPLICATION_SECRET_KEY
    )

    assert signed_request == {
        'user_id': '499729129',
        'algorithm': 'HMAC-SHA256',
        'expires': 0,
        'oauth_token': '<KEY>',
        'user': {
            'locale': 'en_US',
            'country': 'no',
            'age': { 'min': 21 }
        },
        'issued_at': 1306179904
    }

def test_initialize_signed_request():
    signed_request = SignedRequest(
        signed_request = TEST_SIGNED_REQUEST,
        application_secret_key = TEST_FACEBOOK_APPLICATION_SECRET_KEY
    )

    assert signed_request.user.id == '499729129'
    assert signed_request.user.oauth_token.token == TEST_ACCESS_TOKEN
    assert signed_request.user.oauth_token.expires_at == None

    assert signed_request.raw == {
        'user_id': '499729129',
        'algorithm': 'HMAC-SHA256',
        'expires': 0,
        'oauth_token': '<PASSWORD>|<PASSWORD>_<PASSWORD>',
        'user': {
            'locale': 'en_US',
            'country': 'no',
            'age': { 'min': 21 }
        },
        'issued_at': 1306179904
    }

def test_signed_request_user_profile_url():
    user = SignedRequest.User(id=1)

    assert user.profile_url == 'http://facebook.com/1'

def test_signed_request_user_has_authorized_application():
    oauth_token = SignedRequest.User.OAuthToken(
        token = '<token>',
        issued_at = datetime.now(),
        expires_at = None
    )

    user = SignedRequest.User(id=1, oauth_token=oauth_token)

    assert user.has_authorized_application == True
{'fraction_non_alphanumeric': 0.11956521739130435, 'fraction_numerical': 0.034026465028355386, 'mean_word_length': 2.486820428336079, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, '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': '5422489', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1388, 'n_words': 219}