<s> '''<STR_LIT>''' <EOL> import unittest <EOL> import xmlrpclib <EOL> from expedient . common . rpc4django . jsonrpcdispatcher import json , JSONRPC_SERVICE_ERROR <EOL> from expedient . common . rpc4django import views <EOL> from expedient . common . tests . manager import SettingsTestCase <EOL> from django . core . urlresolvers import reverse <EOL> class TestRPCViews ( SettingsTestCase ) : <EOL> urls = "<STR_LIT>" <EOL> def setUp ( self ) : <EOL> self . settings_manager . set ( <EOL> INSTALLED_APPS = ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ) , <EOL> MIDDLEWARE_CLASSES = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) , <EOL> DEBUG_PROPAGATE_EXCEPTIONS = False , <EOL> ) <EOL> views . _register_rpcmethods ( <EOL> [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] , <EOL> restrict_introspection = False , <EOL> dispatchers = views . dispatchers ) <EOL> self . rpc_path = reverse ( "<STR_LIT>" ) <EOL> self . ns_rpc_path = reverse ( "<STR_LIT>" ) <EOL> def test_methodsummary ( self ) : <EOL> response = self . client . get ( self . rpc_path ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( response . template . name , '<STR_LIT>' ) <EOL> def test_xmlrequests ( self ) : <EOL> data = '<STR_LIT>' <EOL> response = self . client . post ( self . rpc_path , data , '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> xmlrpclib . loads ( response . content ) <EOL> def test_jsonrequests ( self ) : <EOL> data = '<STR_LIT>' <EOL> response = self . client . post ( self . rpc_path , data , '<STR_LIT:application/json>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> jsondict = json . loads ( response . content ) <EOL> self . assertTrue ( jsondict [ '<STR_LIT:error>' ] is None ) <EOL> self . assertEqual ( jsondict [ '<STR_LIT:id>' ] , <NUM_LIT> ) <EOL> self . assertTrue ( isinstance ( jsondict [ '<STR_LIT:result>' ] , list ) ) <EOL> data = '<STR_LIT>' <EOL> response = self . client . post ( self . rpc_path , data , '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> jsondict = json . loads ( response . content ) <EOL> self . assertTrue ( jsondict [ '<STR_LIT:error>' ] is None ) <EOL> self . assertEqual ( jsondict [ '<STR_LIT:id>' ] , <NUM_LIT> ) <EOL> self . assertTrue ( isinstance ( jsondict [ '<STR_LIT:result>' ] , dict ) ) <EOL> def test_typedetection ( self ) : <EOL> data = '<STR_LIT>' <EOL> response = self . client . post ( self . rpc_path , data , '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> jsondict = json . loads ( response . content ) <EOL> self . assertTrue ( jsondict [ '<STR_LIT:error>' ] is None ) <EOL> self . assertEqual ( jsondict [ '<STR_LIT:id>' ] , <NUM_LIT> ) <EOL> self . assertTrue ( isinstance ( jsondict [ '<STR_LIT:result>' ] , list ) ) <EOL> data = '<STR_LIT>' <EOL> response = self . client . post ( self . rpc_path , data , '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> xmlrpclib . loads ( response . content ) <EOL> data = '<STR_LIT>' <EOL> response = self . client . post ( self . rpc_path , data , '<STR_LIT:application/json>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> jsondict = json . loads ( response . content ) <EOL> self . assertTrue ( jsondict [ '<STR_LIT:result>' ] is None ) <EOL> self . assertEqual ( jsondict [ '<STR_LIT:id>' ] , '<STR_LIT>' ) <EOL> self . assertTrue ( isinstance ( jsondict [ '<STR_LIT:error>' ] , dict ) ) <EOL> data = '<STR_LIT>' <EOL> try : <EOL> response = self . client . post ( self . rpc_path , data , '<STR_LIT>' ) <EOL> except : <EOL> return <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> try : <EOL> xmlrpclib . loads ( response . content ) <EOL> self . fail ( '<STR_LIT>' ) <EOL> except xmlrpclib . Fault : <EOL> pass <EOL> def test_badrequests ( self ) : <EOL> data = '<STR_LIT>' <EOL> response = self . client . post ( self . rpc_path , data , '<STR_LIT:application/json>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> jsondict = json . loads ( response . content ) <EOL> self . assertTrue ( jsondict [ '<STR_LIT:error>' ] is not None ) <EOL> self . assertEqual ( jsondict [ '<STR_LIT:id>' ] , <NUM_LIT> ) <EOL> self . assertTrue ( jsondict [ '<STR_LIT:result>' ] is None ) <EOL> self . assertEqual ( jsondict [ '<STR_LIT:error>' ] [ '<STR_LIT:code>' ] , JSONRPC_SERVICE_ERROR ) <EOL> data = '<STR_LIT>' <EOL> response = self . client . post ( self . rpc_path , data , '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> try : <EOL> xmlrpclib . loads ( response . content ) <EOL> self . fail ( '<STR_LIT>' ) <EOL> except xmlrpclib . Fault , fault : <EOL> self . assertEqual ( fault . faultCode , <NUM_LIT:1> ) <EOL> def test_httpaccesscontrol ( self ) : <EOL> import django <EOL> t = django . VERSION <EOL> if t [ <NUM_LIT:0> ] < <NUM_LIT:1> or ( t [ <NUM_LIT:0> ] == <NUM_LIT:1> and t [ <NUM_LIT:1> ] < <NUM_LIT:1> ) : <EOL> self . fail ( '<STR_LIT>' % str ( t ) ) <EOL> response = self . client . options ( self . rpc_path , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( response [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( response [ '<STR_LIT>' ] , '<STR_LIT:0>' ) <EOL> def test_good_url_name ( self ) : <EOL> """<STR_LIT>""" <EOL> data = xmlrpclib . dumps ( ( <NUM_LIT:5> , <NUM_LIT:4> ) , "<STR_LIT>" ) <EOL> response = self . client . post ( self . rpc_path , data , '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> result , methname = xmlrpclib . loads ( response . content ) <EOL> self . assertEqual ( result , ( <NUM_LIT:1> , ) ) <EOL> self . assertEqual ( methname , None ) <EOL> data = xmlrpclib . dumps ( ( <NUM_LIT:5> , <NUM_LIT:4> ) , "<STR_LIT>" ) <EOL> response = self . client . post ( self . ns_rpc_path , data , '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> result , methname = xmlrpclib . loads ( response . content ) <EOL> self . assertEqual ( result , ( <NUM_LIT:20> , ) ) <EOL> self . assertEqual ( methname , None ) <EOL> def test_bad_url_name ( self ) : <EOL> """<STR_LIT>""" <EOL> data = xmlrpclib . dumps ( ( <NUM_LIT:5> , <NUM_LIT:4> ) , "<STR_LIT>" ) <EOL> response = self . client . post ( self . ns_rpc_path , data , '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> try : <EOL> result , methname = xmlrpclib . loads ( response . content ) <EOL> self . fail ( "<STR_LIT>" ) <EOL> except xmlrpclib . Fault as fault : <EOL> self . assertEqual ( fault . faultCode , <NUM_LIT:1> ) <EOL> self . assertTrue ( fault . faultString . endswith ( '<STR_LIT>' ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
