Skip to content

Commit

Permalink
Merge pull request #349 from zopefoundation/re-309-manage_menu-db
Browse files Browse the repository at this point in the history
Fix edge case, if no databases are available for dropdown menu.
  • Loading branch information
sallner committed Oct 4, 2018
2 parents cb86a4f + 4d97795 commit ffacbcf
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ Bugfixes
when reading request bodies not encoded as application/x-www-form-urlencoded
or multipart/form-data.

- Show navigation in ``manage_menu`` in case the databases cannot be retrieved.
(`#309 <https://github.com/zopefoundation/Zope/issues/309>`_)

- Prevent breaking page rendering when setting `default-zpublisher-encoding`
in `zope.conf` on Python 2.
(`#308 <https://github.com/zopefoundation/Zope/issue/308>`_)
Expand Down
1 change: 1 addition & 0 deletions buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ auto-checkout =
Products.TemporaryFolder
Products.SiteErrorLog
ExtensionClass
DocumentTemplate

[testenv]
PYTHONHASHSEED = random
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def _read_file(filename):
'Acquisition',
'BTrees',
'DateTime',
'DocumentTemplate',
'DocumentTemplate >= 3.0b5.dev0',
'ExtensionClass',
'MultiMapping',
'PasteDeploy',
Expand Down
12 changes: 8 additions & 4 deletions src/App/dtml/menu.dtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@

<li><a id="menu_cp" title="Control Panel"
href="/Control_Panel/manage_main" target="manage_main">Control Panel</a></li>
<dtml-in "Control_Panel.Database.getDatabaseNames(quote=True)">
<li><a title="Zope Object Database Manager" target="manage_main"
href="/Control_Panel/Database/<dtml-var "_['sequence-item']">/manage_main">ZODB <dtml-var "_['sequence-item']"></a></li>
</dtml-in>
<dtml-try>
<dtml-in "Control_Panel.Database.getDatabaseNames(quote=True)">
<li><a title="Zope Object Database Manager" target="manage_main"
href="/Control_Panel/Database/<dtml-var "_['sequence-item']">/manage_main">ZODB <dtml-var "_['sequence-item']"></a></li>
</dtml-in>
<dtml-except AttributeError>
<dtml-except NameError>
</dtml-try>
<li><a id="menu_undo"
href="/Control_Panel/Database/main/manage_UndoForm" target="manage_main">Undo</a></li>

Expand Down
45 changes: 44 additions & 1 deletion src/App/tests/test_ApplicationManager.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Testing.ZopeTestCase
import codecs
import os
import shutil
import sys
Expand Down Expand Up @@ -53,18 +55,22 @@ def pack(self, when):
class ConfigTestBase(object):

def setUp(self):
super(ConfigTestBase, self).setUp()
import App.config
self._old_config = App.config._config

def tearDown(self):
import App.config
App.config._config = self._old_config
super(ConfigTestBase, self).tearDown()

def _makeConfig(self, **kw):
import App.config

class DummyConfig(object):
pass
def __init__(self):
self.debug_mode = False

App.config._config = config = DummyConfig()
config.dbtab = DummyDBTab(kw)
return config
Expand Down Expand Up @@ -279,3 +285,40 @@ def test_db_size_gt_1_meg(self):
am = self._makeOne()
am._p_jar = self._makeJar('foo', (2048 * 1024) + 123240)
self.assertEqual(am.db_size(), '2.1M')


class MenuDtmlTests(ConfigTestBase, Testing.ZopeTestCase.FunctionalTestCase):
"""Browser testing ..dtml.menu.dtml."""

def setUp(self):
super(MenuDtmlTests, self).setUp()
uf = self.app.acl_users
uf.userFolderAddUser('manager', 'manager_pass', ['Manager'], [])
self.browser = Testing.testbrowser.Browser()
self.browser.addHeader(
'Authorization',
'basic {}'.format(codecs.encode(
b'manager:manager_pass', 'base64').decode()))

def test_menu_dtml__1(self):
"""It contains the databases in navigation."""
self._makeConfig(foo=object(), bar=object(), qux=object())
self.browser.open('http://localhost/manage_menu')
links = [
self.browser.getLink('ZODB foo'),
self.browser.getLink('ZODB bar'),
self.browser.getLink('ZODB qux'),
]
for link in links:
self.assertEqual(
link.attrs['title'], 'Zope Object Database Manager')

def test_menu_dtml__2(self):
"""It still shows the navigation in case no database is configured."""
# This effect can happen in tests, e.g. with `plone.testing`. There a
# `Control_Panel` is not configured in the standard setup, so we will
# get a `NameError` while trying to get the databases.
self.browser.open('http://localhost/manage_menu')
self.assertTrue(self.browser.isHtml)
self.assertIn('Control Panel', self.browser.contents)
self.assertNotIn('ZODB', self.browser.contents)

0 comments on commit ffacbcf

Please sign in to comment.