<commit_before># -*- coding: utf-8 -*-
'''
    rauth.test_service
    ------------------

    Test suite for rauth.service.
'''

from base import RauthTestCase

from rauth.service import OAuth1Service, OAuth2Service, OflyService, Service
from rauth.session import (OAUTH1_DEFAULT_TIMEOUT, OAUTH2_DEFAULT_TIMEOUT,
                           OFLY_DEFAULT_TIMEOUT, OAuth1Session, OAuth2Session,
                           OflySession)
from rauth.utils import FORM_URLENCODED

from datetime import datetime
from functools import wraps
from hashlib import sha1
from urlparse import parse_qsl

from mock import patch

import rauth

import requests

import json


class MutableDatetime(datetime):
    def __new__(cls, *args, **kwargs):
        return datetime.__new__(datetime, *args, **kwargs)


class FakeHexdigest(object):
    def __init__(self, *args):
        pass

    def hexdigest(self):
        return 'foo'


class HttpMixin(object):
    http_url = 'http://example.com/'

    def assert_ok(self, r):
        self.assertEqual(json.loads(r.content), {'status': 'ok'})

    def test_get(self):
        r = self.service.get(self.http_url)
        self.assert_ok(r)

    def test_options(self):
        r = self.service.options(self.http_url)
        self.assert_ok(r)

    def test_head(self):
        r = self.service.head(self.http_url)
        self.assert_ok(r)

    def test_post(self):
        r = self.service.post(self.http_url)
        self.assert_ok(r)

    def test_put(self):
        r = self.service.put(self.http_url)
        self.assert_ok(r)

    def test_patch(self):
        r = self.service.patch(self.http_url)
        self.assert_ok(r)

    def test_delete(self):
        r = self.service.delete(self.http_url)
        self.assert_ok(r)


class RequestMixin(HttpMixin):
    def test_request(self):
        r = self.service.request('GET', 'foo')
        self.assert_ok(r)

    def test_request_with_params(self):
        r = self.service.get('foo', params={'format': 'json'})
        self.assert_ok(r)

    def test_request_with_data(self):
        r = self.service.post('foo', data={'format': 'json'})
        self.assert_ok(r)

    def test_request_with_params_as_string(self):
        r = self.service.get('foo', params='format=json')
        self.assert_ok(r)

    def test_request_with_data_as_string(self):
        r = self.service.post('foo', data='format=json')
        self.assert_ok(r)

    def test_request_with_params_as_unicode_string(self):
        r = self.service.get('foo', params=u'format=json')
        self.assert_ok(r)

    def test_request_with_data_as_unicode_string(self):
        r = self.service.post('foo', data=u'format=json')
        self.assert_ok(r)

    def test_request_with_params_and_data_as_strings(self):
        r = self.service.post('foo', params='format=json', data='format=json')
        self.assert_ok(r)

    def test_request_with_params_and_data_as_unicode_strings(self):
        r = self.service.post('foo',
                              params=u'format=json',
                              data=u'format=json')
        self.assert_ok(r)

    def test_request_with_header(self):
        r = self.service.get('foo', headers={'x-foo-bar': 'baz'})
        self.assert_ok(r)

    def test_request_with_params_and_headar(self):
        r = self.service.get('foo',
                             params={'format': 'json'},
                             headers={'x-foo-bar': 'baz'})
        self.assert_ok(r)

    def test_request_with_params_and_data_and_header(self):
        r = self.service.post('foo',
                              params={'format': 'json'},
                              data={'foo': 'bar'},
                              headers={'x-foo-bar': 'baz'})
        self.assert_ok(r)


class OAuth1ServiceTestCase(RauthTestCase, RequestMixin):
    def setUp(self):
        RauthTestCase.setUp(self)

        request_token_url = 'http://example.com/request'
        access_token_url = 'http://example.com/access'
        authorize_url = 'http://example.com/authorize'
        base_url = 'http://example.com/api/'

        self.service = OAuth1Service('000',
                                     '111',
                                     name='service',
                                     request_token_url=request_token_url,
                                     access_token_url=access_token_url,
                                     authorize_url=authorize_url,
                                     base_url=base_url)<commit_msg>adding additional tests<commit_after># -*- coding: utf-8 -*-
'''
    rauth.test_service
    ------------------

    Test suite for rauth.service.
'''

from base import RauthTestCase

from rauth.service import OAuth1Service, OAuth2Service, OflyService, Service
from rauth.session import (OAUTH1_DEFAULT_TIMEOUT, OAUTH2_DEFAULT_TIMEOUT,
                           OFLY_DEFAULT_TIMEOUT, OAuth1Session, OAuth2Session,
                           OflySession)
from rauth.utils import FORM_URLENCODED

from datetime import datetime
from functools import wraps
from hashlib import sha1
from urlparse import parse_qsl

from mock import patch

import rauth

import requests

import json


class MutableDatetime(datetime):
    def __new__(cls, *args, **kwargs):
        return datetime.__new__(datetime, *args, **kwargs)


class FakeHexdigest(object):
    def __init__(self, *args):
        pass

    def hexdigest(self):
        return 'foo'


class HttpMixin(object):
    http_url = 'http://example.com/'

    def assert_ok(self, r):
        self.assertEqual(json.loads(r.content), {'status': 'ok'})

    def test_get(self):
        r = self.service.get(self.http_url)
        self.assert_ok(r)

    def test_options(self):
        r = self.service.options(self.http_url)
        self.assert_ok(r)

    def test_head(self):
        r = self.service.head(self.http_url)
        self.assert_ok(r)

    def test_post(self):
        r = self.service.post(self.http_url)
        self.assert_ok(r)

    def test_put(self):
        r = self.service.put(self.http_url)
        self.assert_ok(r)

    def test_patch(self):
        r = self.service.patch(self.http_url)
        self.assert_ok(r)

    def test_delete(self):
        r = self.service.delete(self.http_url)
        self.assert_ok(r)


class RequestMixin(HttpMixin):
    oauth_resource = 'foo'

    def test_request(self):
        r = self.service.request('GET', 'foo')
        self.assert_ok(r)

    def test_request_with_params(self):
        r = self.service.get(self.oauth_resource, params={'format': 'json'})
        self.assert_ok(r)

    def test_request_with_data(self):
        r = self.service.post(self.oauth_resource, data={'format': 'json'})
        self.assert_ok(r)

    def test_request_with_params_as_string(self):
        r = self.service.get(self.oauth_resource, params='format=json')
        self.assert_ok(r)

    def test_request_with_data_as_string(self):
        r = self.service.post(self.oauth_resource, data='format=json')
        self.assert_ok(r)

    def test_request_with_params_and_data_as_strings(self):
        r = self.service.post(self.oauth_resource,
                              params='format=json',
                              data='format=json')
        self.assert_ok(r)

    def test_request_with_params_as_unicode_string(self):
        r = self.service.get(self.oauth_resource, params=u'format=json')
        self.assert_ok(r)

    def test_request_with_data_as_unicode_string(self):
        r = self.service.post(self.oauth_resource, data=u'format=json')
        self.assert_ok(r)

    def test_request_with_params_and_data_as_unicode_strings(self):
        r = self.service.post(self.oauth_resource,
                              params=u'format=json',
                              data=u'foo=bar')
        self.assert_ok(r)

    def test_request_with_header(self):
        r = self.service.get(self.oauth_resource, headers={'x-foo-bar': 'baz'})
        self.assert_ok(r)

    def test_request_with_params_and_header(self):
        r = self.service.get(self.oauth_resource,
                             params={'format': 'json'},
                             headers={'x-foo-bar': 'baz'})
        self.assert_ok(r)

    def test_request_with_data_and_header(self):
        r = self.service.post(self.oauth_resource,
                              data={'format': 'json'},
                              headers={'x-foo-bar': 'baz'})
        self.assert_ok(r)

    def test_request_with_params_and_data_and_header(self):
        r = self.service.post(self.oauth_resource,
                              params={'format': 'json'},
                              data={'foo': 'bar'},
                              headers={'x-foo-bar': 'baz'})
        self.assert_ok(r)

    def test_request_with_params_as_string_and_header(self):
        r = self.service.get(self.oauth_resource,
                             params='format=json',
                             headers={'x-foo-bar': 'baz'})
        self.assert_ok(r)

    def test_request_with_params_as_unicode_string_and_header(self):
        r = self.service.get(self.oauth_resource,
                             params=u'format=json',
                             headers={'x-foo-bar': 'baz'})
        self.assert_ok(r)

    def test_request_with_data_as_string_and_header(self):
        r = self.service.post(self.oauth_resource,
                              data='foo=bar',
                              headers={'x-foo-bar': 'baz'})
        self.assert_ok(r)

    def test_request_with_params_and_data_as_string_and_header(self):
        r = self.service.post(self.oauth_resource,
                              params='format=json',
                              data='foo=bar',
                              headers={'x-foo-bar': 'baz'})
        self.assert_ok(r)

    def test_request_with_params_and_data_as__unicode_string_and_header(self):
        r = self.service.post(self.oauth_resource,
                              params=u'format=json',
                              data=u'foo=bar',
                              headers={'x-foo-bar': 'baz'})
        self.assert_ok(r)


class OAuth1ServiceTestCase(RauthTestCase, RequestMixin):
    def setUp(self):
        RauthTestCase.setUp(self)

        request_token_url = 'http://example.com/request'
        access_token_url = 'http://example.com/access'
        authorize_url = 'http://example.com/authorize'
        base_url = 'http://example.com/api/'

        self.service = OAuth1Service('000',
                                     '111',
                                     name='service',
                                     request_token_url=request_token_url,
                                     access_token_url=access_token_url,
                                     authorize_url=authorize_url,
                                     base_url=base_url)
{'fraction_non_alphanumeric': 0.11574201858496642, 'fraction_numerical': 0.00294415309596099, 'mean_word_length': 2.0784480317190597, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6305966', 'n_tokens_mistral': 3397, 'n_tokens_neox': 3317, 'n_words': 518}