<commit_before>import json
from clevertimapi.session import Session, SessionError
try:
    import unittest.mock as mock
except ImportError:
    import mock
import sys
if sys.version_info[:2] < (2, 7):
    import unittest2 as unittest
else:
    import unittest


class FakeEndpoint(object):
    def __init__(self, session, key=None, lazy_load=False):
        pass


class TestSession(unittest.TestCase):

    def setUp(self):
        self.payload = {
            'id': 3434,
            'key1': 1,
            'key2': '2',
            'key3': [1, '2', [3]]
        }
        self.response = {
            'status': 'OK',
            'content': [
                self.payload
            ]
        }

    def test_get_without_register_fails(self):
        session = Session(api_key='APIKEY')
        with self.assertRaises(KeyError):
            session.get('FakeEndpoint', key=1, lazy_load=True)

    def test_enpoint_name_to_cls(self):
        Session.register_endpoint(FakeEndpoint)
        self.assertTrue(Session.enpoint_name_to_cls('FakeEndpoint') is FakeEndpoint)
        Session.deregister_endpoint(FakeEndpoint)

    def test_get_after_deregister_fails(self):
        session = Session(api_key='APIKEY')
        Session.register_endpoint(FakeEndpoint)
        Session.deregister_endpoint(FakeEndpoint)
        with self.assertRaises(KeyError):
            session.get('FakeEndpoint', key=1, lazy_load=True)

    def test_register_get(self):
        session = Session(api_key='APIKEY')
        Session.register_endpoint(FakeEndpoint)
        ret = session.get('FakeEndpoint', key=1, lazy_load=True)
        self.assertIsInstance(ret, FakeEndpoint)
        # second request hit the cache
        ret2 = session.get('FakeEndpoint', key=1, lazy_load=True)
        self.assertIsInstance(ret2, FakeEndpoint)
        self.assertTrue(ret is ret2)
        Session.deregister_endpoint(FakeEndpoint)

    def test_invalid_method_raises(self):
        session = Session(api_key='APIKEY', endpoint_url='http://localhost:8000/fake')
        with self.assertRaises(AssertionError):
            session.make_request(endpoint='/endpoint', resource_id=3434, method='INVALID')

    @mock.patch('requests.get')
    def test_make_request_get(self, mockRequestsGET):<commit_msg>test for is_registered_endpoint<commit_after>import json
from clevertimapi.session import Session, SessionError
try:
    import unittest.mock as mock
except ImportError:
    import mock
import sys
if sys.version_info[:2] < (2, 7):
    import unittest2 as unittest
else:
    import unittest


class FakeEndpoint(object):
    def __init__(self, session, key=None, lazy_load=False):
        pass


class TestSession(unittest.TestCase):

    def setUp(self):
        self.payload = {
            'id': 3434,
            'key1': 1,
            'key2': '2',
            'key3': [1, '2', [3]]
        }
        self.response = {
            'status': 'OK',
            'content': [
                self.payload
            ]
        }

    def test_get_without_register_fails(self):
        session = Session(api_key='APIKEY')
        with self.assertRaises(KeyError):
            session.get('FakeEndpoint', key=1, lazy_load=True)

    def test_enpoint_name_to_cls(self):
        Session.register_endpoint(FakeEndpoint)
        self.assertTrue(Session.enpoint_name_to_cls('FakeEndpoint') is FakeEndpoint)
        Session.deregister_endpoint(FakeEndpoint)

    def test_is_registered_endpoint(self):
        Session.register_endpoint(SessionError)
        Session.register_endpoint(FakeEndpoint)
        self.assertTrue(Session.is_registered_endpoint(FakeEndpoint))
        self.assertTrue(Session.is_registered_endpoint(SessionError))
        self.assertTrue(Session.is_registered_endpoint('FakeEndpoint'))
        self.assertTrue(Session.is_registered_endpoint('SessionError'))
        Session.deregister_endpoint(SessionError)
        Session.deregister_endpoint(FakeEndpoint)
        
    def test_get_after_deregister_fails(self):
        session = Session(api_key='APIKEY')
        Session.register_endpoint(FakeEndpoint)
        Session.deregister_endpoint(FakeEndpoint)
        with self.assertRaises(KeyError):
            session.get('FakeEndpoint', key=1, lazy_load=True)

    def test_register_get(self):
        session = Session(api_key='APIKEY')
        Session.register_endpoint(FakeEndpoint)
        ret = session.get('FakeEndpoint', key=1, lazy_load=True)
        self.assertIsInstance(ret, FakeEndpoint)
        # second request hit the cache
        ret2 = session.get('FakeEndpoint', key=1, lazy_load=True)
        self.assertIsInstance(ret2, FakeEndpoint)
        self.assertTrue(ret is ret2)
        Session.deregister_endpoint(FakeEndpoint)

    def test_invalid_method_raises(self):
        session = Session(api_key='APIKEY', endpoint_url='http://localhost:8000/fake')
        with self.assertRaises(AssertionError):
            session.make_request(endpoint='/endpoint', resource_id=3434, method='INVALID')

    @mock.patch('requests.get')
    def test_make_request_get(self, mockRequestsGET):
{'fraction_non_alphanumeric': 0.10342789598108747, 'fraction_numerical': 0.012214342001576044, 'mean_word_length': 3.0877616747181964, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5410425', 'n_tokens_mistral': 1518, 'n_tokens_neox': 1473, 'n_words': 259}