gforcada
(gforcada)
March 7, 2016, 9:07am
1
I'm currently finishing a rewrite of plone.namedfile (current work-in-progress branch ).
I stumbled upon this method some tests that rely on this method from ZopeTestCase:
@implementer(interfaces.IFunctional)
class Functional(sandbox.Sandboxed):
'''Derive from this class and an xTestCase to get functional
testing support::
class MyTest(Functional, ZopeTestCase):
...
'''
@savestate
def publish(self, path, basic=None, env=None, extra=None,
request_method='GET', stdin=None, handle_errors=True):
'''Publishes the object at 'path' returning a response object.'''
from io import BytesIO
from ZPublisher.HTTPRequest import WSGIRequest as Request
from ZPublisher.HTTPResponse import WSGIResponse
from ZPublisher.WSGIPublisher import publish_module
As some might be aware, thanks to @do3cc , we know that mixing plone.testing and ZopeTestCase is bad, bad, bad:
plone:master
← plone:feature/dont_play_well_with_zopetestcase
opened 08:52AM - 18 Feb 16 UTC
So I'm wondering what needs to be done to update a test that relies on this publish method... any ideas/code pointers?
do3cc
(Patrick Gerken)
March 7, 2016, 9:17am
2
This looks very much like a trick to avoid using a zope.testbrowser.
I did not look at all the tests in named file, but the ones I looked at seem to be quite straight forward replaceable with the zope.testbrowser browser.
gforcada
(gforcada)
March 8, 2016, 9:59am
3
I tried but it did not work at least for this test:
def testGetImageSize(self):
assert self.scaling.getImageSize('image') == (200, 200)
def testGetOriginalScaleTag(self):
tag = self.scaling.tag('image')
base = self.item.absolute_url()
expected = \
r'<img src="{0}/@@images/([-0-9a-f]{{36}}).(jpeg|gif|png)" ' \
r'alt="foo" title="foo" height="(\d+)" width="(\d+)" />'.format(
base,
)
self.assertTrue(re.match(expected, tag).groups())
def testScaleOnItemWithNonASCIITitle(self):
self.item.title = u'ü'
tag = self.scaling.tag('image')
base = self.item.absolute_url()
expected = \
r'<img src="{0}/@@images/([-0-9a-f]{{36}}).(jpeg|gif|png)" ' \
r'alt="\xfc" title="\xfc" height="(\d+)" width="(\d+)" />'.format(
base,
It does not matter that I leave the full URL, any attempt to render with a Browser that URL or parts of it returns a 404 Not Found.
So I guess the DummyContent being used is just too dummy? I didn't have time to dig deeper.
do3cc
(Patrick Gerken)
March 8, 2016, 12:57pm
4
The code you linked is the old ZopeTestCase Version?
If you are using testbrowser, do not forget that the testbrowser sees what was committed already.
If you create content, you must commit it, else the views the testbrowser opens can't see it.
gforcada
(gforcada)
March 8, 2016, 3:02pm
5
That's the old code.
Oh, committing, that nice trick... I will give it a try and report back. Thanks again!