<commit_before>import sys

import unittest
from mock import Mock

import requests_mock

from cbas.auth_server import obtain_access_token

if sys.version_info[0] == 3:
    from urllib.parse import parse_qs
else:
    from urlparse import parse_qs


class TestObtainAccessToken(unittest.TestCase):

    @requests_mock.mock()
    def test_obtain_access_token(self, rmock):
        rmock.post(requests_mock.ANY, text='{"access_token": "ANY_TOKEN"}')
        cmock = Mock()
        cmock.username = "ANY_USERNAME"
        cmock.auth_host = "ANY_URL.example"
        result = obtain_access_token(cmock, 'ANY_PASSWORD')
        self.assertEqual('ANY_TOKEN', result)
        received_post_data = parse_qs(rmock.request_history[0].text)
        expected_post_data = {u'username': [u'ANY_USERNAME'],
                              u'password': [u'<PASSWORD>'],
                              u'client_id': [u'jumpauth'],
                              u'grant_type': [u'password']}
        self.assertEqual(received_post_data, expected_post_data)<commit_msg>add tests for get_auth_url<commit_after>import sys

import unittest
from mock import Mock

import requests_mock

from cbas.auth_server import obtain_access_token, get_auth_url

if sys.version_info[0] == 3:
    from urllib.parse import parse_qs
else:
    from urlparse import parse_qs


class TestGetAuthUrl(unittest.TestCase):

    def test_use_explicit_scheme(self):
        m = Mock(auth_host='http://ANY_HOST')
        self.assertEqual('http://ANY_HOST/oauth/token', get_auth_url(m))

    def test_prefix_https(self):
        m = Mock(auth_host='ANY_HOST')
        self.assertEqual('https://ANY_HOST/oauth/token', get_auth_url(m))


class TestObtainAccessToken(unittest.TestCase):

    @requests_mock.mock()
    def test_obtain_access_token(self, rmock):
        rmock.post(requests_mock.ANY, text='{"access_token": "ANY_TOKEN"}')
        cmock = Mock()
        cmock.username = "ANY_USERNAME"
        cmock.auth_host = "ANY_URL.example"
        result = obtain_access_token(cmock, 'ANY_PASSWORD')
        self.assertEqual('ANY_TOKEN', result)
        received_post_data = parse_qs(rmock.request_history[0].text)
        expected_post_data = {u'username': [u'ANY_USERNAME'],
                              u'password': [u'<PASSWORD>'],
                              u'client_id': [u'jumpauth'],
                              u'grant_type': [u'password']}
        self.assertEqual(received_post_data, expected_post_data)
{'fraction_non_alphanumeric': 0.1103448275862069, 'fraction_numerical': 0.002434077079107505, 'mean_word_length': 3.0693069306930694, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, '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': '3617760', 'n_tokens_mistral': 785, 'n_tokens_neox': 774, 'n_words': 135}