Products.CMFPlone/plip-1486-redirection: Add tests for batching of managing existing redirects
Stephan Klinger <jenkins-z4DKO/[email protected]>
| Newsgroups | gmane.comp.web.zope.plone.cvs |
|---|---|
| Message-ID | <[email protected]> |
Repository: Products.CMFPlone Branch: refs/heads/plip-1486-redirection Date: 2017-07-10T09:31:40+03:00 Author: Asko Soukka (datakurre) <[email protected]> Commit: https://github.com/plone/Products.CMFPlone/commit/0f14de437d2b49615bb6a045fc84ab40fc4c50e3 Add tests for batching of managing existing redirects Files changed: M Products/CMFPlone/controlpanel/browser/redirects.py M Products/CMFPlone/controlpanel/tests/test_controlpanel_browser_redirection.py diff --git a/Products/CMFPlone/controlpanel/browser/redirects.py b/Products/CMFPlone/controlpanel/browser/redirects.py index db4a6efbe..77757c6d7 100644 --- a/Products/CMFPlone/controlpanel/browser/redirects.py +++ b/Products/CMFPlone/controlpanel/browser/redirects.py @@ -119,9 +119,6 @@ def __init__(self): def __len__(self): return len(self.data) - def __iter__(self): - return iter(self.storage) - def __getitem__(self, item): redirect = self.data[item] if redirect.startswith(self.portal_path): diff --git a/Products/CMFPlone/controlpanel/tests/test_controlpanel_browser_redirection.py b/Products/CMFPlone/controlpanel/tests/test_controlpanel_browser_redirection.py index 8d2cdceda..2947c958c 100644 --- a/Products/CMFPlone/controlpanel/tests/test_controlpanel_browser_redirection.py +++ b/Products/CMFPlone/controlpanel/tests/test_controlpanel_browser_redirection.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from Products.CMFPlone.PloneBatch import Batch +from Products.CMFPlone.controlpanel.browser.redirects import RedirectionSet from plone.app.testing import SITE_OWNER_NAME, SITE_OWNER_PASSWORD from plone.app.redirector.interfaces import IRedirectionStorage from plone.testing.z2 import Browser @@ -73,4 +75,41 @@ def test_redirection_controlpanel_add_redirect(self): self.assertTrue( storage.has_path(storage_path), u'Redirection storage should have path "{0}"'.format(storage_path) - ) \ No newline at end of file + ) + + def test_redirection_controlpanel_set(self): + storage = getUtility(IRedirectionStorage) + portal_path = self.layer['portal'].absolute_url_path() + for i in range(1000): + storage.add('{0:s}/foo/{1:s}'.format(portal_path, str(i)), + '{0:s}/bar/{1:s}'.format(portal_path, str(i))) + redirects = RedirectionSet() + self.assertEqual(len(redirects), 1000) + self.assertDictEqual(redirects[0], { + 'redirect': '{0:s}/foo/0'.format(portal_path), + 'path': '/foo/0', 'redirect-to': '/bar/0' + }) + self.assertDictEqual(redirects[999], { + 'redirect': '{0:s}/foo/999'.format(portal_path), + 'path': '/foo/999', 'redirect-to': '/bar/999' + }) + self.assertEqual(len(list(iter(redirects))), 1000) + self.assertDictEqual(list(iter(redirects))[0], { + 'redirect': '{0:s}/foo/0'.format(portal_path), + 'path': '/foo/0', 'redirect-to': '/bar/0' + }) + + def test_redirection_controlpanel_batching(self): + storage = getUtility(IRedirectionStorage) + portal_path = self.layer['portal'].absolute_url_path() + for i in range(1000): + storage.add('{0:s}/foo/{1:s}'.format(portal_path, str(i)), + '{0:s}/bar/{1:s}'.format(portal_path, str(i))) + view = getMultiAdapter((self.layer['portal'], self.layer['request']), + name='redirection-controlpanel') + # Test that view/redirects returns batch + self.assertIsInstance(view.redirects(), Batch) + + # Test that view/batching returns batching with anchor in urls + batching = view.batching() + self.assertIn('?b_start:int=990#manage-existing-aliases', batching) ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot