RGHummel
RGHummel

Reputation: 58

Changing the site root in plone.app.testing/Plone 4

Is there a way to change the PLONE_SITE_ID from its default at plone.app.testing.interfaces without modifying the source code?

I'm using Plone 4 with several custom products, and plone.app.testing (4.0.2) with relative success. In my custom products, there are several instances where there are hardcoded physical paths to locate objects when performing catalog searches (e.g., my site root is 'mySiteID', so several custom queries use path=/mySiteID/folder1/etc.. to do catalog searches).

The problem is that the site root in the Plone instance that plone.app.testing configures (PLONE_FIXTURE) is PLONE_SITE_ID = 'plone'. Therefore, any objects that I add in my tests always have /plone as the root rather than /mySiteID and my tests break. I can fix this problem by changing the defined value in the interface but this seems like an ugly hack.

Upvotes: 1

Views: 266

Answers (2)

tisto
tisto

Reputation: 1347

Martijn is correct. Though, his answer does not fully do the trick. You need to monkey patch multiple plone.app.testing imports to make this actually work:

[test] 
...

initialization =
    import plone.app.testing.helpers
    plone.app.testing.helpers.PLONE_SITE_ID = 'Plone'
    import plone.app.testing.interfaces
    plone.app.testing.interfaces.PLONE_SITE_ID = 'Plone'
    import plone.app.testing.layers
    plone.app.testing.layers.PLONE_SITE_ID = 'Plone'

Upvotes: 1

Martijn Pieters
Martijn Pieters

Reputation: 1121914

If you absolutely have to, you could monkeypatch the id; do so as part of the test runner part, in buildout:

[test]
# ...
initialization =
    import plone.app.testing.interfaces
    plone.app.testing.interfaces = 'mySiteID'

Upvotes: 1

Related Questions