Skip to content

Commit

Permalink
Fixed test_transform.py after merging the hotfix.
Browse files Browse the repository at this point in the history
Problem is that `test_transforms.setUp` sets `settings.rules` to `python://plone.app.theming/tests/rules.xml`.
The PythonResolver translates this to an absolute file system path like `/Users/maurits/.../src/plone/app/theming/tests/rules.xml`.
The rules file has `<theme href="theme.html" />`.
This becomes an absolute file system path like `/Users/maurits/.../src/plone/app/theming/tests/theme.html`.
And then the FailingFileSystemResolver of the hotfix kicks in and throws an error:

  File system access not allowed: '/Users/maurits/.../src/plone/app/theming/tests/theme.html'

At this point in the diazo code, the absolute prefix is not used, so you cannot fix it with that.

The main fix in this commit is letting `rules.xml` reference the theme as `python://plone.app.theming/tests/theme.html`.
Then it works again.

This was a problem in the tests, but it may happen for real.
But I found this hard to reproduce.
I tried using `python://plonetheme.barceloneta/theme/rules.xml` in the theming controlpanel,
but even without the hotfix this meant the theme could not be displayed.
I have not heard anyone complain that theming fails with the hotfix, so maybe no one is using the `python://` path for the rules.

This commit removes test_internal_resolver, because this did not actually test the internal resolver.
It created an XMLParser with an InternalResolver, but this was not needed:
neither the rules nor the theme contained anything that needed to be resolved internally (traversed within the Plone Site).
The internal resolver is already tested in the test_includes method.
  • Loading branch information
mauritsvanrees committed Jul 7, 2021
1 parent dcbc5dc commit f7b173b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/plone/app/theming/tests/paramrules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
xmlns:css="http://namespaces.plone.org/diazo/css"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<theme href="theme.html" />
<theme href="othertheme.html" if-path="news"/>
<theme href="python://plone.app.theming/tests/theme.html" />
<theme href="python://plone.app.theming/tests/othertheme.html" if-path="news"/>

<replace content='/html/head/title' theme='/html/head/title' />
<replace content='//h1[class=documentFirstHeading]' theme='/html/body/h1' />
Expand Down
4 changes: 2 additions & 2 deletions src/plone/app/theming/tests/rules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

<rules css:if-content="#visual-portal-wrapper">

<theme href="othertheme.html" if-path="news"/>
<theme href="theme.html" />
<theme href="python://plone.app.theming/tests/othertheme.html" if-path="news"/>
<theme href="python://plone.app.theming/tests/theme.html" />

<replace content='/html/head/title' theme='/html/head/title' />
<replace content='//h1[class=documentFirstHeading]' theme='/html/body/h1' />
Expand Down
18 changes: 4 additions & 14 deletions src/plone/app/theming/tests/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,25 +212,15 @@ def test_theme_enabled_header_off(self):
# The theme
self.assertFalse("This is the theme" in browser.contents)

def test_internal_resolver(self):
compiler_parser = etree.XMLParser()
compiler_parser.resolvers.add(InternalResolver())
# We can use a sub-package or a directory since tests is a python
# package
theme = resolvePythonURL(
u'python://plone.app.theming.tests/theme.html'
)
rules = resolvePythonURL(u'python://plone.app.theming/tests/rules.xml')
compile_theme(rules, theme, compiler_parser=compiler_parser)

def test_python_resolver(self):
compiler_parser = etree.XMLParser()
compiler_parser.resolvers.add(PythonResolver())
# The rules contain a python:// link, so we need a python resolver.
parser = etree.HTMLParser()
parser.resolvers.add(PythonResolver())
theme = resolvePythonURL(
u'python://plone.app.theming.tests/theme.html'
)
rules = resolvePythonURL(u'python://plone.app.theming/tests/rules.xml')
compile_theme(rules, theme, compiler_parser=compiler_parser)
compile_theme(rules, theme, parser=parser)

def test_theme_stored_in_plone_site(self):
app = self.layer['app']
Expand Down

0 comments on commit f7b173b

Please sign in to comment.