http: fix xmlrpc request cloning

--HG--
extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%401063
This commit is contained in:
Daniel Grana 2009-04-16 18:23:12 +00:00
parent bbd41bda33
commit 821f6be3ce
2 changed files with 33 additions and 3 deletions

View File

@ -13,8 +13,10 @@ from scrapy.http.request import Request
class XmlRpcRequest(Request):
def __init__(self, *args, **kwargs):
params = kwargs.pop('params')
methodname = kwargs.pop('methodname')
if 'body' not in kwargs:
params = kwargs.pop('params')
methodname = kwargs.pop('methodname')
kwargs['body'] = xmlrpclib.dumps(params, methodname)
# spec defines that requests must use POST method
kwargs.setdefault('method', 'POST')
@ -23,5 +25,4 @@ class XmlRpcRequest(Request):
kwargs.setdefault('dont_filter', True)
Request.__init__(self, *args, **kwargs)
self.body = xmlrpclib.dumps(params, methodname)
self.headers.setdefault('Content-Type', 'text/xml')

View File

@ -259,6 +259,35 @@ class XmlRpcRequestTest(unittest.TestCase):
self.assertEqual(r.method, 'POST')
self.assertTrue(r.dont_filter, True)
def test_copy(self):
"""Test XmlRpcRequest copy"""
def somecallback():
pass
r1 = XmlRpcRequest("http://www.example.com", callback=somecallback,
methodname='login', params=('username', 'password'))
r1.meta['foo'] = 'bar'
r1.cache['lala'] = 'lolo'
r2 = r1.copy()
assert r1.cache
assert not r2.cache
assert r1.deferred is not r2.deferred
# make sure meta dict is shallow copied
assert r1.meta is not r2.meta, "meta must be a shallow copy, not identical"
self.assertEqual(r1.meta, r2.meta)
# make sure headers attribute is shallow copied
assert r1.headers is not r2.headers, "headers must be a shallow copy, not identical"
self.assertEqual(r1.headers, r2.headers)
self.assertEqual(r1.encoding, r2.encoding)
self.assertEqual(r1.dont_filter, r2.dont_filter)
self.assertEqual(r1.body, r2.body)
if __name__ == "__main__":
unittest.main()