Progress: Using zope.publisher.browser.TestRequest is probably the way to go:

    >>> request = TestRequest(data = xmlfile.read())
    >>> request.method = 'POST'

On 05/11/2012 02:58 PM, Kees Hink wrote:
The doc for zope.testbrowser suggests [1] you can generate a POST like
this:
 >>> browser.post(import_view, '<?xml version=1.0?>',
content_type='application/xml')
Is there something similar in plone.testing?

When i just use the browser.open method as described [2], i get:
"TypeError: cannot concatenate
'str' and 'dict' objects" [3]
A pdb shows that in testbrowser/testing.py", line 75, "body" is
actually a dictionary:
(Pdb) body
{'body': '<?xml version=1.0?>', 'content-type': 'application/xml'}

Can i create a post request with xml data in plone.testing?

The background is that i want to create a view that accepts HTTP
requests with XML data, from which content is to be created. Maybe
there's an easier way for that?

I'll now look into the tests for Plone's File content type, probably
that has some useful pointers as well.

Kees

[1]
http://pypi.python.org/pypi/zope.testbrowser#submitting-a-posts-body-directly


[2] Plone 4.2b2, zope.testbrowser 3.11.1, plone.testing 4.0.3,
plone.app.testing 4.0.2

[3]
Failed example:
browser.post(import_view, data)
Exception raised:
Traceback (most recent call last):
File "/usr/lib/python2.6/doctest.py", line 1253, in __run
compileflags, 1) in test.globs
File "<doctest functional_k4import.txt[21]>", line 1, in <module>
browser.post(import_view, data)
File
"/home/kees/.buildout/eggs/zope.testbrowser-3.11.1-py2.6.egg/zope/testbrowser/browser.py",
line 264, in post
return self.open(url, data)
File
"/home/kees/.buildout/eggs/zope.testbrowser-3.11.1-py2.6.egg/zope/testbrowser/browser.py",
line 240, in open
self.mech_browser.open(url, data)
File
"/home/kees/.buildout/eggs/mechanize-0.2.5-py2.6.egg/mechanize/_mechanize.py",
line 203, in open
return self._mech_open(url, data, timeout=timeout)
File
"/home/kees/.buildout/eggs/mechanize-0.2.5-py2.6.egg/mechanize/_mechanize.py",
line 230, in _mech_open
response = UserAgentBase.open(self, request, data)
File
"/home/kees/.buildout/eggs/mechanize-0.2.5-py2.6.egg/mechanize/_opener.py",
line 193, in open
response = urlopen(self, req, data)
File
"/home/kees/.buildout/eggs/mechanize-0.2.5-py2.6.egg/mechanize/_urllib2_fork.py",
line 344, in _open
'_open', req)
File
"/home/kees/.buildout/eggs/mechanize-0.2.5-py2.6.egg/mechanize/_urllib2_fork.py",
line 332, in _call_chain
result = func(*args)
File
"/home/kees/.buildout/eggs/plone.testing-4.0.3-py2.6.egg/plone/testing/_z2_testbrowser.py",
line 64, in http_open
return self.do_open(connectionFactory, req)
File "/usr/lib/python2.6/urllib2.py", line 1156, in do_open
h.request(req.get_method(), req.get_selector(), req.data, headers)
File
"/home/kees/.buildout/eggs/zope.testbrowser-3.11.1-py2.6.egg/zope/testbrowser/testing.py",
line 75, in request
+ headers + '\n' + body)
TypeError: cannot concatenate 'str' and 'dict' objects


_______________________________________________
Product-Developers mailing list
[email protected]
https://lists.plone.org/mailman/listinfo/plone-product-developers

Reply via email to