<commit_before>'''
XML RPC Dispatcher Tests
-------------------------

'''

import unittest
from django.core.exceptions import ImproperlyConfigured


try:
    from rpc4django.xmlrpcdispatcher import XMLRPCDispatcher
except ImproperlyConfigured:
    # Configure Django settings if not already configured
    from django.conf import settings
    settings.configure(DEBUG=True)
    from rpc4django.xmlrpcdispatcher import XMLRPCDispatcher

try:
    from xmlrpclib import loads, dumps, Fault
except ImportError:
    from xmlrpc.client import loads, dumps, Fault


class TestXMLRPCDispatcher(unittest.TestCase):

    def setUp(self):
        def kwargstest(a, b, **kwargs):
            if kwargs.get('c', None) is not None:
                return True
            return False

        self.dispatcher = XMLRPCDispatcher()
        self.dispatcher.register_function(kwargstest, 'kwargstest')

    def test_kwargs(self):
        xml = dumps((1, 2), 'kwargstest')
        ret = self.dispatcher.dispatch(xml)
        out, name = loads(ret)
        self.assertFalse(out[0])

        ret = self.dispatcher.dispatch(xml, c=1)
        out, name = loads(ret)
        self.assertTrue(out[0])<commit_msg>Test regarding direct request handling<commit_after>'''
XML RPC Dispatcher Tests
-------------------------

'''

import unittest
from django.core.exceptions import ImproperlyConfigured


try:
    from rpc4django.xmlrpcdispatcher import XMLRPCDispatcher
except ImproperlyConfigured:
    # Configure Django settings if not already configured
    from django.conf import settings
    settings.configure(DEBUG=True)
    from rpc4django.xmlrpcdispatcher import XMLRPCDispatcher

try:
    from xmlrpclib import loads, dumps, Fault
except ImportError:
    from xmlrpc.client import loads, dumps, Fault


class TestXMLRPCDispatcher(unittest.TestCase):

    def setUp(self):
        def kwargstest(a, b, **kwargs):
            if kwargs.get('c', None) is not None:
                return True
            return False
        
        def withoutargstest():
            return True
        
        def requestargtest(request,a):
            return request

        self.dispatcher = XMLRPCDispatcher()
        self.dispatcher.register_function(kwargstest, 'kwargstest')
        self.dispatcher.register_function(requestargtest, 'requestargtest')
        self.dispatcher.register_function(withoutargstest, 'withoutargstest')

    def test_kwargs(self):
        xml = dumps((1, 2), 'kwargstest')
        ret = self.dispatcher.dispatch(xml)
        out, name = loads(ret)
        self.assertFalse(out[0])

        ret = self.dispatcher.dispatch(xml, c=1)
        out, name = loads(ret)
        self.assertTrue(out[0])
        
        xml = dumps((1,),'requestargtest')
        ret = self.dispatcher.dispatch(xml, request=True)
        out, name = loads(ret)
        self.assertTrue(out[0])
        
        xml = """<?xml version='1.0'?>
<methodCall>
<methodName>withoutargstest</methodName>
<params>
</params>
</methodCall>
        """
        ret = self.dispatcher.dispatch(xml, request='fakerequest')
        out, name = loads(ret)
        self.assertTrue(out[0])
{'fraction_non_alphanumeric': 0.11068702290076336, 'fraction_numerical': 0.006043256997455471, 'mean_word_length': 2.7351543942992875, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 1, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 19}, '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': '6621974', 'n_tokens_mistral': 932, 'n_tokens_neox': 927, 'n_words': 219}