<commit_before>import pytest
import requests
import responses

import chwrapper


def test_Service_session():
    """Get a session using an api"""
    session = chwrapper.Service().get_session('pk.test')
    assert session.params.get('access_token') == '<PASSWORD>'


def test_Service_session_env():
    """Get a session using the env's token"""
    session = chwrapper.Service().get_session(
        env={'CompaniesHouseKey': 'pk.test_env'})
    assert session.params.get('access_token') == '<PASSWORD>'


def test_Service_session_os_environ(monkeypatch):
    """Get a session using os.environ's token"""
    monkeypatch.setenv('CompaniesHouseKey', 'pk.test_os_environ')
    session = chwrapper.Service().get_session()
    assert session.params.get('access_token') == '<PASSWORD>'
    monkeypatch.undo()


def test_Service_session_os_environ_caps(monkeypatch):
    """Get a session using os.environ's token"""
    monkeypatch.setenv('COMPANIES_HOUSE_KEY', 'pk.test_os_environ')
    session = chwrapper.Service().get_session()
    assert session.params.get('access_token') == '<PASSWORD>environ'
    monkeypatch.undo()


def test_product_token():
    """Get the product version"""
    assert chwrapper.Service().product_token == 'chwrapper/{0}'.format(chwrapper.__version__)


def test_user_agent():
    """Check User-agent correctly assigned"""
    session = chwrapper.Service().get_session()
    assert session.headers['User-Agent'].startswith('chwrapper')
    assert 'python-requests' in session.headers['User-Agent']

@responses.activate
def test_custom_messages():
    """Check status code error messaging"""
    fakeurl = 'https://example.com'
    responses.add(responses.GET, fakeurl, status=401)
    Service = chwrapper.Service()
    response = Service.get_session().get(fakeurl)

    assert Service.handle_http_error(response) is None

    with pytest.raises(requests.exceptions.HTTPError) as exc:
        assert Service.handle_http_error(response,
                                         custom_messages={401: "error"})
        assert exc.value.message == 'error'

    with pytest.raises(requests.exceptions.HTTPError) as exc:
        assert Service.handle_http_error(response, raise_for_status=True)
        assert "401" in exc.value.message
<commit_msg>Update Base test for raised exception<commit_after>import pytest
import requests
import responses

import chwrapper


def test_Service_session():
    """Get a session using an api"""
    session = chwrapper.Service().get_session('pk.test')
    assert session.params.get('access_token') == '<PASSWORD>'


def test_Service_session_env():
    """Get a session using the env's token"""
    session = chwrapper.Service().get_session(
        env={'CompaniesHouseKey': 'pk.test_env'})
    assert session.params.get('access_token') == '<PASSWORD>'


def test_Service_session_os_environ(monkeypatch):
    """Get a session using os.environ's token"""
    monkeypatch.setenv('CompaniesHouseKey', 'pk.test_os_environ')
    session = chwrapper.Service().get_session()
    assert session.params.get('access_token') == '<PASSWORD>'
    monkeypatch.undo()


def test_Service_session_os_environ_caps(monkeypatch):
    """Get a session using os.environ's token"""
    monkeypatch.setenv('COMPANIES_HOUSE_KEY', 'pk.test_os_environ')
    session = chwrapper.Service().get_session()
    assert session.params.get('access_token') == '<PASSWORD>'
    monkeypatch.undo()


def test_product_token():
    """Get the product version"""
    assert chwrapper.Service().product_token == 'chwrapper/{0}'.format(chwrapper.__version__)


def test_user_agent():
    """Check User-agent correctly assigned"""
    session = chwrapper.Service().get_session()
    assert session.headers['User-Agent'].startswith('chwrapper')
    assert 'python-requests' in session.headers['User-Agent']

@responses.activate
def test_custom_messages():
    """Check status code error messaging"""
    fakeurl = 'https://example.com'
    responses.add(responses.GET, fakeurl, status=401)
    Service = chwrapper.Service()
    response = Service.get_session().get(fakeurl)


    with pytest.raises(requests.exceptions.HTTPError) as exc:
        assert Service.handle_http_error(response,
                                         custom_messages={401: "error"})
        assert exc.value.message == 'error'

    with pytest.raises(requests.exceptions.HTTPError) as exc:
        assert Service.handle_http_error(response, raise_for_status=True)
        assert "401" in exc.value.message

{'fraction_non_alphanumeric': 0.12972852692478862, 'fraction_numerical': 0.004450378282153983, 'mean_word_length': 4.257309941520468, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '764411', 'n_tokens_mistral': 1351, 'n_tokens_neox': 1321, 'n_words': 271}