404 during functional test for Archetype in Plone 5

Hi folks!

I'm still stuck getting a 10k line Plone 4 project moved to Plone 5, and at this rate I probably should've just rewritten everything to use Dexterity :smile:

In any case, I'm at the point where, through the web, I can create Archetypes-based types using the "Add new…" menu. But I'd also like to get the functional tests to work, and that's where things get wonky. My README.rst looks something like this:

>>> browser.open(portal_url)
>>> link = browser.getLink(id='my-type')
>>> 'createObject?type_name=My+Type' in link.url
True
>>> link.click()

It's at the link.click() that the 404 suddenly occurs.

Now I assume the setup of the functional test requires some extra "gymnastics" in Plone 5. The question is: what?

So far, testing.py does:

class MyAddOn(PloneSandboxLayer):
    defaultBases = (PLONE_FIXTURE,)
    def setUpZope(self, app, configurationContext):
        import my.addon
        self.loadZCML(package=my.addon)
        z2.installProduct(app, 'my.addon')
    def setUpPloneSite(self, portal):
        self.applyProfile(portal, 'my.addon:default')
    def tearDownZope(self, app):
        z2.uninstallProduct(app, 'my.addon')

MY_ADDON_FIXTURE = MyAddOn()
MY_ADDON_FIXTURE_FUNCTIONAL_TESTING = FunctionalTesting(
    bases = (MY_ADDON_FIXTURE,),
    name = 'MyAddOn:Functional'
)

And test_doctest.py does the usual as well:

optionFlags = (
    doctest.ELLIPSIS |
    doctest.NORMALIZE_WHITESPACE |
    doctest.REPORT_ONLY_FIRST_FAILURE
)

def test_suite():
    return unittest.TestSuite([
        layered(doctest.DocFileSuite('README.rst',
                package='my.addon',
                optionflags=optionFlags),
            LAYER),
    ])

if __name__ == '__main__':
    unittest.main(defaultTest='test_suite')

Finally, the preamble to README.rst:

app = layer['app']
from plone.testing.z2 import Browser
from plone.app.testing import SITE_OWNER_NAME, SITE_OWNER_PASSWORD
browser = Browser(app)
browser.handleErrors = False
browser.addHeader('Authorization', 'Basic %s:%s' % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD))
portal = layer['portal']    
portal_url = portal.absolute_url()

Leading ultimately to:

>>> browser.open(portal_url)
>>> link = browser.getLink(id='my-type')
>>> 'createObject?type_name=My+Type' in link.url
True
>>> link.click()

And the 404 at the link.click(). Any hints?

Again it works fine operationally. But my management is in love with Jenkins. Seriously. In love. It's not healthy.

Maybe you need to explicitly install Archetypes? Like this:

z2.installProduct(app, 'Products.Archetypes')

You could open the Add-ons page (or maybe manage_main) in the test and inspect the contents:

browser.open(portal_url + '/@@installer')
open('/tmp/test.html', 'w').write(browser.contents)

If portal_url has a port number (instead of the usual http://nohost), you could maybe even use a real browser and look around as admin. That may depend on the used layer.

In the past I have sometimes manually started a ZServer in the tests, in a pdb, and then used a real browser to look around in the printed url:

from Testing.ZopeTestCase.utils import startZServer
print('http://%s:%s/plone' % startZServer())

When I try this now in a random test in CMFPlone in 5.1, I get some html but see a blank page. So not sure if that will get you anywhere.

1 Like

A valiant effort, but alas, this dragon refused to fall.

But I did convince management to bite the bullet and formally move to Dexterity. :sweat_smile: