class RegistryTest(unittest.TestCase):

    layer = GENWEBCONTROLPANEL_INTEGRATION_TESTING

    def setUp(self):
        self.portal = self.layer['portal']
        setRoles(self.portal, TEST_USER_ID, ['Manager'])
        self.registry = Registry()
        self.registry.registerInterface(IGenwebControlPanelSettings)

    def test_registry_registered(self):
        registry = queryUtility(IRegistry)
        self.assertTrue(registry.forInterface(IGenwebControlPanelSettings))

    def test_discussion_controlpanel_view(self):
        view = getMultiAdapter((self.portal, self.portal.REQUEST),
                               name="genweb-controlpanel")
        view = view.__of__(self.portal)
        self.assertTrue(view())

    def test_discussion_in_controlpanel(self):
        # Check if discussion is in the control panel
        self.controlpanel = getToolByName(self.portal, "portal_controlpanel")
        self.assertTrue('genweb' in [a.getAction(self)['id']
                            for a in self.controlpanel.listActions()])

    def test_unicode_values(self):
        registry = queryUtility(IRegistry)
        genweb_settings = registry.forInterface(IGenwebControlPanelSettings)
        genweb_settings.html_title_ca = u"àéçÀÉ"
        self.assertEqual(genweb_settings.html_title_ca, u"àéçÀÉ")
class TestSettings(unittest.TestCase):

    layer = COLLECTIVE_MOBIFYJS_INTEGRATION_TESTING

    def setUp(self):
        self.portal = self.layer['portal']
        self.registry = Registry()
        self.registry.registerInterface(ISettings)

    def test_setup(self):
        pq = getToolByName(self.portal, 'portal_quickinstaller')
        self.assertTrue(pq.isProductInstalled('collective.mobifyjs'))

    def test_registry(self):
        settings = self.registry.forInterface(ISettings)

        self.assertEquals(settings.mobify_library_url, RESIZE_URL)
        self.assertEquals(settings.mobify_resize_backend, None)

    def test_controlpanel_view(self):
        view = getMultiAdapter((self.portal, self.portal.REQUEST),
                               name="collective.mobifyjs-settings")

        self.assertEqual(view.__class__, SettingsView)
        self.failUnless(view())
class RegistryTest(ZeroCMSTestCase):


    def afterSetUp(self):
        # Set up the zerocms settings registry
        self.loginAsPortalOwner()
        self.registry = Registry()
        self.registry.registerInterface(IZeroCMSSettings)

    def test_zerocms_controlpanel_view(self):
        view = getMultiAdapter((self.portal, self.portal.REQUEST), 
                               name="zerocms-settings")
        view = view.__of__(self.portal)
        self.failUnless(view())

    def test_zerocms_controlpanel_view_protected(self):
        from AccessControl import Unauthorized
        self.logout()
        self.assertRaises(Unauthorized,
                          self.portal.restrictedTraverse,
                         '@@zerocms-settings')

    def test_record_zerocms_key(self):
        # Test that the zerocms_key record is in the control panel
        record_post_url = self.registry.records[
            'Products.zerocms.interfaces.IZeroCMSSettings.post_url']
        self.failUnless('post_url' in IZeroCMSSettings)
        self.assertEquals(record_post_url.value, u"http://localhost/ZeroCMS/api/document/add")

    def test_record_instance_url(self):
        record_instance_url = self.registry.records[
            'Products.zerocms.interfaces.IZeroCMSSettings.instance_url']        
        self.failUnless('instance_url' in IZeroCMSSettings)
        self.assertEquals(record_instance_url.value, u"http://localhost:8080/zerorally")
Beispiel #4
0
class TestQueuePurge(unittest.TestCase):

    def setUp(self):
        provideAdapter(persistentFieldAdapter)
        self.registry = Registry()
        self.registry.registerInterface(ICachePurgingSettings)
        provideUtility(self.registry, IRegistry)

        self.settings = self.registry.forInterface(ICachePurgingSettings)
        self.settings.enabled = True
        self.settings.cachingProxies = ('http://localhost:1234',)

        self.handler = Handler()
        provideHandler(self.handler.handler)

    def tearDown(self):
        zope.component.testing.tearDown()

    def test_disabled(self):
        self.settings.enabled = False

        view = QueuePurge(FauxContext(), FauxRequest())
        self.assertEqual('Caching not enabled', view())
        self.assertEqual([], self.handler.invocations)

    def test_enabled(self):
        self.settings.enabled = True

        context = FauxContext()
        view = QueuePurge(context, FauxRequest)
        self.assertEqual('Queued', view())
        self.assertEqual(1, len(self.handler.invocations))
        self.assertTrue(self.handler.invocations[0].object is context)
class TestControlpanel(base.BaseTestCase):
    """ """
    def afterSetUp(self):
        self.loginAsPortalOwner()
        self.registry = Registry()
        self.registry.registerInterface(ISocialPublishControlPanel)
        qi = self.portal.portal_quickinstaller
        qi.installProduct('collective.socialpublish')

    def test_controlpanel_view(self):
        view = getMultiAdapter((self.portal, self.portal.REQUEST),
                               name="socialpublish-settings")
        view = view.__of__(self.portal)
        self.failUnless(view())

    def test_controlpanel_view_protected(self):
        from AccessControl import Unauthorized
        self.logout()
        self.assertRaises(Unauthorized,
                          self.portal.restrictedTraverse,
                          '@@socialpublish-settings')

    def test_in_controlpanel(self):
        self.controlpanel = getToolByName(self.portal, "portal_controlpanel")
        self.failUnless('socialpublish_settings' in [a.getAction(self)['id']
                                      for a in self.controlpanel.listActions()])

    def test_record_content_types(self):
        record_content_types = self.registry.records[
            'collective.socialpublish.controlpanel.interfaces.ISocialPublishControlPanel.content_types']
        self.failUnless('content_types' in ISocialPublishControlPanel)
        self.assertEquals(record_content_types.value, set())
class RegistryTest(unittest.TestCase):

    layer = Routes_INTEGRATION_TESTING

    def setUp(self):
        self.portal = self.layer["portal"]
        setRoles(self.portal, TEST_USER_ID, ["Manager"])
        # set up settings registry
        self.registry = Registry()
        self.registry.registerInterface(IRoutesSettings)

    def test_controlpanel_view(self):
        view = getMultiAdapter((self.portal, self.portal.REQUEST), name="routes-settings")
        view = view.__of__(self.portal)
        self.failUnless(view())

    def test_controlpanel_view_is_protected(self):
        from AccessControl import Unauthorized

        logout()
        self.assertRaises(Unauthorized, self.portal.restrictedTraverse, "@@routes-settings")

    def test_action_in_controlpanel(self):
        cp = getToolByName(self.portal, "portal_controlpanel")
        actions = [a.getAction(self)["id"] for a in cp.listActions()]
        self.failUnless("routes" in actions)

    def test_routes_record(self):
        record_routes = self.registry.records[BASE_REGISTRY % "routes"]
        self.failUnless("routes" in IRoutesSettings)
        self.assertEquals(record_routes.value, set([]))
class TestMLSContactInfoControlPanel(unittest.TestCase):
    """Validate contact info control panel is available."""
    layer = INTEGRATION_TESTING

    def setUp(self):
        """Additional test setup."""
        self.portal = self.layer['portal']
        alsoProvides(self.portal.REQUEST, IPloneMLSLayer)
        setRoles(self.portal, TEST_USER_ID, ['Manager'])
        self.registry = Registry()
        self.registry.registerInterface(IMLSContactInfoSettings)

    def test_controlpanel_view(self):
        """Validate that the configuration view is available."""
        view = getMultiAdapter(
            (self.portal, self.portal.REQUEST),
            name='mls-controlpanel-contact-info',
        )
        view = view.__of__(self.portal)
        self.assertTrue(view())

    def test_controlpanel_view_protected(self):
        """Validate that the configuration view needs authentication."""
        from AccessControl import Unauthorized
        logout()
        self.assertRaises(
            Unauthorized,
            self.portal.restrictedTraverse,
            '@@mls-controlpanel-contact-info',
        )
class TestToolkitControlPanel(unittest.TestCase):
    """Control Panel Test Case for theming.toolkit.core."""
    layer = THEMING_TOOLKIT_CORE_INTEGRATION_TESTING

    def setUp(self):
        """Additional test setup."""
        self.portal = self.layer['portal']
        directlyProvides(self.portal.REQUEST, IThemingToolkitCore)
        setRoles(self.portal, TEST_USER_ID, ['Manager'])
        self.registry = Registry()
        self.registry.registerInterface(IToolkitSettings)

    def test_toolkit_controlpanel_view(self):
        """Test that the toolkit configuration view is available."""
        view = getMultiAdapter((self.portal, self.portal.REQUEST),
                               name='toolkit-controlpanel')
        view = view.__of__(self.portal)
        self.assertTrue(view())

    def test_toolkit_controlpanel_view_protected(self):
        """Test that the toolkit configuration view needs authentication."""
        from AccessControl import Unauthorized
        logout()
        self.assertRaises(Unauthorized, self.portal.restrictedTraverse,
                          '@@toolkit-controlpanel')

    def test_toolkit_in_controlpanel(self):
        """Check that there is an toolkit entry in the control panel."""
        self.controlpanel = getToolByName(self.portal, 'portal_controlpanel')
        self.assertTrue('propertyshelf_toolkit' in [a.getAction(self)['id']
            for a in self.controlpanel.listActions()])
Beispiel #9
0
    def test_request_not_annotatable(self):
        request = FauxRequest()

        registry = Registry()
        registry.registerInterface(ICachePurgingSettings)
        provideUtility(registry, IRegistry)

        settings = registry.forInterface(ICachePurgingSettings)
        settings.enabled = True
        settings.cachingProxies = ('http://localhost:1234',)

        @implementer(IPurger)
        class FauxPurger(object):

            def __init__(self):
                self.purged = []

            def purgeAsync(self, url, httpVerb='PURGE'):
                self.purged.append(url)

        purger = FauxPurger()
        provideUtility(purger)

        notify(PubSuccess(request))

        self.assertEqual([], purger.purged)
Beispiel #10
0
class TestMLSControlPanel(unittest.TestCase):
    """Control Panel Test Case for plone.mls.core."""
    layer = PLONE_MLS_CORE_INTEGRATION_TESTING

    def setUp(self):
        """Additional test setup."""
        self.portal = self.layer['portal']
        alsoProvides(self.portal.REQUEST, IMLSSpecific)
        setRoles(self.portal, TEST_USER_ID, ['Manager'])
        self.registry = Registry()
        self.registry.registerInterface(IMLSSettings)

    def test_mls_controlpanel_view(self):
        """Test that the MLS configuration view is available."""
        view = getMultiAdapter((self.portal, self.portal.REQUEST),
                               name='mls-controlpanel')
        view = view.__of__(self.portal)
        self.assertTrue(view())

    def test_mls_controlpanel_view_protected(self):
        """Test that the MLS configuration view needs authentication."""
        from AccessControl import Unauthorized
        logout()
        self.assertRaises(Unauthorized, self.portal.restrictedTraverse,
                          '@@mls-controlpanel')

    def test_mls_in_controlpanel(self):
        """Check that there is an MLS entry in the control panel."""
        controlpanel = api.portal.get_tool(name='portal_controlpanel')
        actions = [
            a.getAction(self)['id'] for a in controlpanel.listActions()
        ]
        self.assertTrue('propertyshelf_mls' in actions)
Beispiel #11
0
    def test_enabled(self):
        context = FauxContext()

        request = FauxRequest()
        alsoProvides(request, IAttributeAnnotatable)
        setRequest(request)

        registry = Registry()
        registry.registerInterface(ICachePurgingSettings)
        provideUtility(registry, IRegistry)

        settings = registry.forInterface(ICachePurgingSettings)
        settings.enabled = True
        settings.cachingProxies = ('http://localhost:1234',)

        @implementer(IPurgePaths)
        @adapter(FauxContext)
        class FauxPurgePaths(object):

            def __init__(self, context):
                self.context = context

            def getRelativePaths(self):
                return ['/foo', '/bar']

            def getAbsolutePaths(self):
                return []

        provideAdapter(FauxPurgePaths, name="test1")

        notify(Purge(context))

        self.assertEqual({'plone.cachepurging.urls': set(['/foo', '/bar'])},
                         dict(IAnnotations(request)))
Beispiel #12
0
    def test_caching_disabled(self):
        request = FauxRequest()
        alsoProvides(request, IAttributeAnnotatable)

        IAnnotations(request)["plone.cachepurging.urls"] = set(
            ["/foo", "/bar"]
        )

        registry = Registry()
        registry.registerInterface(ICachePurgingSettings)
        provideUtility(registry, IRegistry)

        settings = registry.forInterface(ICachePurgingSettings)
        settings.enabled = False
        settings.cachingProxies = ("http://localhost:1234",)

        @implementer(IPurger)
        class FauxPurger(object):
            def __init__(self):
                self.purged = []

            def purgeAsync(self, url, httpVerb="PURGE"):
                self.purged.append(url)

        purger = FauxPurger()
        provideUtility(purger)

        notify(PubSuccess(request))

        self.assertEqual([], purger.purged)
class ControlPanelTestCase(BaseTestCase):
    def afterSetUp(self):
        # Set up the iservices.controlpanel settings registry
        self.loginAsPortalOwner()
        self.registry = Registry()
        self.registry.registerInterface(ISettingsSchema)

    def test_iservices_controlpanel_view(self):
        # Test the iservices setting control panel view
        view = getMultiAdapter((self.portal, self.portal.REQUEST),
                            name="iservices-controlpanel")
        view = view.__of__(self.portal)
        self.failUnless(view())

    def test_controlpanel_view_protected(self):
        from AccessControl import Unauthorized
        self.logout()
        self.assertRaises(Unauthorized,
                        self.portal.restrictedTraverse,
                        '@@iservices-controlpanel')

    def test_controlpanel_keys(self):
        # Test that all the keys declared in the Interface are avilable
        for key_name in ISettingsSchema.names():
            rkey_name = self.registry.records[
                'iservices.controlpanel.interfaces.ISettingsSchema.%s'%key_name]
            self.assertEquals(rkey_name.value, ISettingsSchema[key_name].default)
class ControlPanelTestCase(unittest.TestCase):

    layer = INTEGRATION_TESTING

    def setUp(self):
        self.portal = self.layer['portal']
        setRoles(self.portal, TEST_USER_ID, ['Manager'])
        self.registry = Registry()
        self.registry.registerInterface(INewsFlashSettings)

    def test_controlpanel_view(self):
        view = getMultiAdapter((self.portal, self.portal.REQUEST),
                               name='newsflash-settings')
        view = view.__of__(self.portal)
        self.assertTrue(view())

    def test_controlpanel_view_is_protected(self):
        from AccessControl import Unauthorized
        logout()
        self.assertRaises(Unauthorized,
                          self.portal.restrictedTraverse,
                          '@@newsflash-settings')

    def test_action_in_controlpanel(self):
        cp = api.portal.get_tool('portal_controlpanel')
        actions = [a.getAction(self)['id'] for a in cp.listActions()]
        self.assertIn('newsflash', actions)
Beispiel #15
0
    def test_purge_no_config(self):
        request = FauxRequest()
        alsoProvides(request, IAttributeAnnotatable)

        IAnnotations(request)["plone.cachepurging.urls"] = set(["/foo", "/bar"])

        registry = Registry()
        registry.registerInterface(ICachePurgingSettings)
        provideUtility(registry, IRegistry)
        settings = registry.forInterface(ICachePurgingSettings)
        settings.enabled = True

        class FauxPurger(object):
            implements(IPurger)

            def __init__(self):
                self.purged = []

            def purgeAsync(self, url, httpVerb="PURGE"):
                self.purged.append(url)

        purger = FauxPurger()
        provideUtility(purger)

        notify(PubSuccess(request))

        self.assertEquals([], purger.purged)
Beispiel #16
0
    def test_purge(self):
        request = FauxRequest()
        alsoProvides(request, IAttributeAnnotatable)

        IAnnotations(request)['plone.cachepurging.urls'] = set(
            ['/foo', '/bar'])

        registry = Registry()
        registry.registerInterface(ICachePurgingSettings)
        provideUtility(registry, IRegistry)

        settings = registry.forInterface(ICachePurgingSettings)
        settings.enabled = True
        settings.cachingProxies = ('http://localhost:1234',)

        @implementer(IPurger)
        class FauxPurger(object):

            def __init__(self):
                self.purged = []

            def purgeAsync(self, url, httpVerb='PURGE'):
                self.purged.append(url)

        purger = FauxPurger()
        provideUtility(purger)

        notify(PubSuccess(request))

        self.assertEqual(
            ['http://localhost:1234/foo', 'http://localhost:1234/bar'],
            purger.purged
        )
Beispiel #17
0
    def test_request_not_annotatable(self):
        context = FauxContext()

        request = FauxRequest()
        setRequest(request)

        registry = Registry()
        registry.registerInterface(ICachePurgingSettings)
        provideUtility(registry, IRegistry)

        settings = registry.forInterface(ICachePurgingSettings)
        settings.enabled = True
        settings.cachingProxies = ('http://localhost:1234',)

        @implementer(IPurgePaths)
        @adapter(FauxContext)
        class FauxPurgePaths(object):

            def __init__(self, context):
                self.context = context

            def getRelativePaths(self):
                return ['/foo', '/bar']

            def getAbsolutePaths(self):
                return []

        provideAdapter(FauxPurgePaths, name="test1")

        try:
            notify(Purge(context))
        except:
            self.fail()
Beispiel #18
0
    def test_enabled(self):
        registry = Registry()
        registry.registerInterface(ICachePurgingSettings)
        provideUtility(registry, IRegistry)

        settings = registry.forInterface(ICachePurgingSettings)
        settings.enabled = True
        self.assertEqual(True, utils.isCachePurgingEnabled())
Beispiel #19
0
    def test_passed_registry(self):
        registry = Registry()
        registry.registerInterface(ICachePurgingSettings)
        settings = registry.forInterface(ICachePurgingSettings)
        settings.enabled = True

        self.assertEqual(False, utils.isCachePurgingEnabled())
        self.assertEqual(True, utils.isCachePurgingEnabled(registry))
Beispiel #20
0
    def test_passed_registry(self):
        registry = Registry()
        registry.registerInterface(ICachePurgingSettings)
        settings = registry.forInterface(ICachePurgingSettings)
        settings.enabled = True
        settings.cachingProxies = ('http://localhost:1234',)

        self.assertEqual(False, utils.isCachePurgingEnabled())
        self.assertEqual(True, utils.isCachePurgingEnabled(registry))
Beispiel #21
0
 def test_enabled(self):
     registry = Registry()
     registry.registerInterface(ICachePurgingSettings)
     provideUtility(registry, IRegistry)
     
     settings = registry.forInterface(ICachePurgingSettings)
     settings.enabled = True
     settings.cachingProxies = ('http://localhost:1234',)
     self.assertEquals(True, utils.isCachePurgingEnabled())
Beispiel #22
0
    def test_virtual_hosting_disabled(self):
        registry = Registry()
        provideUtility(registry, IRegistry)
        registry.registerInterface(ICachePurgingSettings)
        settings = registry.forInterface(ICachePurgingSettings)
        settings.virtualHosting = False

        self._prepareVHMRequest('/foo')
        self.assertEqual(['/foo'], self.rewriter('/foo'))
Beispiel #23
0
    def test_empty_request(self):
        registry = Registry()
        provideUtility(registry, IRegistry)
        registry.registerInterface(ICachePurgingSettings)
        settings = registry.forInterface(ICachePurgingSettings)
        settings.virtualHosting = True

        self.request.clear()
        self.assertEqual(['/foo'], self.rewriter('/foo'))
Beispiel #24
0
    def test_no_virtual_root_physical_path(self):
        registry = Registry()
        provideUtility(registry, IRegistry)
        registry.registerInterface(ICachePurgingSettings)
        settings = registry.forInterface(ICachePurgingSettings)
        settings.virtualHosting = True

        self._prepareVHMRequest('/foo')
        del self.request['VirtualRootPhysicalPath']
        self.assertEqual(['/foo'], self.rewriter('/foo'))
Beispiel #25
0
    def test_no_virtual_url_parts(self):
        registry = Registry()
        provideUtility(registry, IRegistry)
        registry.registerInterface(ICachePurgingSettings)
        settings = registry.forInterface(ICachePurgingSettings)
        settings.virtualHosting = True

        self._prepareVHMRequest('/foo')
        del self.request['VIRTUAL_URL_PARTS']
        self.assertEqual(['/foo'], self.rewriter('/foo'))
Beispiel #26
0
    def test_https(self):
        registry = Registry()
        provideUtility(registry, IRegistry)
        registry.registerInterface(ICachePurgingSettings)
        settings = registry.forInterface(ICachePurgingSettings)
        settings.virtualHosting = True

        self._prepareVHMRequest('/foo', domain='example.com:81', protocol='https')
        self.assertEqual(['/VirtualHostBase/https/example.com:81/plone/VirtualHostRoot/foo'],
                         self.rewriter('/foo'))
Beispiel #27
0
    def test_standard_vhm(self):
        registry = Registry()
        provideUtility(registry, IRegistry)
        registry.registerInterface(ICachePurgingSettings)
        settings = registry.forInterface(ICachePurgingSettings)
        settings.virtualHosting = True

        self._prepareVHMRequest('/foo')
        self.assertEqual(['/VirtualHostBase/http/example.com/plone/VirtualHostRoot/foo'],
                         self.rewriter('/foo'))
Beispiel #28
0
    def test_virtual_path_is_deep(self):
        registry = Registry()
        provideUtility(registry, IRegistry)
        registry.registerInterface(ICachePurgingSettings)
        settings = registry.forInterface(ICachePurgingSettings)
        settings.virtualHosting = True

        self._prepareVHMRequest('/foo/bar', root='/plone')

        self.assertEqual(['/VirtualHostBase/http/example.com/plone/VirtualHostRoot/foo/bar'],
                         self.rewriter('/foo/bar'))
 def test_inside_out_hosting(self):
     registry = Registry()
     provideUtility(registry, IRegistry)
     registry.registerInterface(ICachePurgingSettings)
     settings = registry.forInterface(ICachePurgingSettings)
     settings.virtualHosting = True
     
     self._prepareVHMRequest('/foo', root='/bar/plone', prefix='/foo/bar')
     
     self.assertEquals(['/VirtualHostBase/http/example.com/bar/plone/VirtualHostRoot/_vh_foo/_vh_bar/foo'],
                       self.rewriter('/foo'))
 def test_virtual_root_is_app_root(self):
     registry = Registry()
     provideUtility(registry, IRegistry)
     registry.registerInterface(ICachePurgingSettings)
     settings = registry.forInterface(ICachePurgingSettings)
     settings.virtualHosting = True
     
     self._prepareVHMRequest('/foo', root='/')
     
     self.assertEquals(['/VirtualHostBase/http/example.com/VirtualHostRoot/foo'],
                       self.rewriter('/foo'))
Beispiel #31
0
    def test_parent_not_content(self):
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(IPloneCacheSettings)

        ploneSettings = registry.forInterface(IPloneCacheSettings)
        ploneSettings.templateRulesetMapping = {}
        ploneSettings.contentTypeRulesetMapping = {'testtype': 'rule1'}

        published = ZopePageTemplate('defaultView').__of__(DummyNotContent())
        request = DummyRequest(published, DummyResponse())
        self.assertIsNone(ContentItemLookup(published, request)())
    def test_structure(self):
        registry = Registry()

        record = Record(field.TextLine(title="Foo Bar"), "Lorem Ipsum")
        registry.records["foo.bar"] = record

        obj = self.serialize(registry)
        item = obj["items"][0]
        self.assertEqual(set(item), {"name", "value", "schema"})
        self.assertEqual(set(item["schema"]), {"properties"})
        self.assertEqual(item["name"], "foo.bar")
        self.assertEqual(item["value"], "Lorem Ipsum")
Beispiel #33
0
    def test_lookupOption_default(self):
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)

        registry.records['plone.caching.tests.test'] = Record(
            field.TextLine(), u"default")

        result = lookupOption('plone.caching.tests',
                              'testrule',
                              'test',
                              default=_marker)
        self.assertEquals(u"default", result)
Beispiel #34
0
    def test_malformed_virtual_url_parts(self):
        registry = Registry()
        provideUtility(registry, IRegistry)
        registry.registerInterface(ICachePurgingSettings)
        settings = registry.forInterface(ICachePurgingSettings)
        settings.virtualHosting = True

        self._prepareVHMRequest('/foo')

        self.request['VIRTUAL_URL_PARTS'] = ('foo', )
        self.assertEqual(['/foo'], self.rewriter('/foo'))

        self.request['VIRTUAL_URL_PARTS'] = ()
        self.assertEqual(['/foo'], self.rewriter('/foo'))

        self.request['VIRTUAL_URL_PARTS'] = ('http://example.com', '', '/foo',
                                             'x')
        self.assertEqual(['/foo'], self.rewriter('/foo'))

        self.request['VIRTUAL_URL_PARTS'] = 'foo'
        self.assertEqual(['/foo'], self.rewriter('/foo'))
Beispiel #35
0
    def test_structure(self):
        registry = Registry()

        record = Record(field.TextLine(title=u"Foo Bar"), u"Lorem Ipsum")
        registry.records['foo.bar'] = record

        obj = self.serialize(registry)
        item = obj['items'][0]
        self.assertEqual(set(item), set(['name', 'value', 'schema']))
        self.assertEqual(set(item['schema']), set(['properties']))
        self.assertEqual(item['name'], 'foo.bar')
        self.assertEqual(item['value'], u"Lorem Ipsum")
Beispiel #36
0
    def test_no_records(self):
        provideAdapter(DefaultRulesetLookup)
        provideUtility(Registry(), IRegistry)

        view = DummyView()
        response = DummyResponse()
        request = DummyRequest(view, response)
        setRequest(request)

        modifyStreamingResponse(DummyStreamingEvent(response))

        self.assertEqual({'PUBLISHED': view}, dict(request))
        self.assertEqual({}, dict(request.response))
Beispiel #37
0
    def test_no_published_object(self):
        provideAdapter(DefaultRulesetLookup)
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(ICacheSettings)
        settings = registry.forInterface(ICacheSettings)
        settings.enabled = True

        request = DummyRequest(None, DummyResponse())

        intercept(DummyEvent(request))
        self.assertEqual({'PUBLISHED': None}, dict(request))
        self.assertEqual({}, dict(request.response))
class TestMailchimpSettingsControlPanel(unittest.TestCase):

    layer = COLLECTIVE_MAILCHIMP_INTEGRATION_TESTING

    def setUp(self):
        self.portal = self.layer['portal']
        self.request = self.layer['request']
        self.registry = Registry()
        self.registry.registerInterface(IMailchimpSettings)

    def test_mailchimp_controlpanel_view(self):
        view = getMultiAdapter((self.portal, self.portal.REQUEST),
                               name="mailchimp-settings")
        view = view.__of__(self.portal)
        self.failUnless(view())

    def test_mailchimp_controlpanel_view_protected(self):
        from AccessControl import Unauthorized
        logout()
        self.assertRaises(
            Unauthorized,
            self.portal.restrictedTraverse,
            '@@mailchimp-settings'
        )

    def test_mailchimp_in_controlpanel(self):
        self.controlpanel = getToolByName(self.portal, "portal_controlpanel")
        self.failUnless(
            'mailchimp' in [
                a.getAction(self)['id']
                for a in self.controlpanel.listActions()
            ]
        )

    def test_record_api_key(self):
        record = self.registry.records[
            'collective.mailchimp.interfaces.IMailchimpSettings.api_key']
        self.failUnless('api_key' in IMailchimpSettings)
        self.assertEquals(record.value, u"")
Beispiel #39
0
    def test_disabled(self):
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(IPloneCacheSettings)

        environ = {'SERVER_NAME': 'example.com', 'SERVER_PORT': '80'}
        response = HTTPResponse()
        request = HTTPRequest(StringIO(), environ, response)

        published = DummyPublished()
        GZipTransform(published, request).transformUnicode(u"", "utf-8")

        self.assertEqual(0, response.enableHTTPCompression(query=True))
Beispiel #40
0
class FunctionalTest(unittest.TestCase):

    layer = ADDTHIS_FUNCTIONAL_TESTING

    def setUp(self):
        self.portal = self.layer['portal']
        setRoles(self.portal, TEST_USER_ID, ['Manager'])
        self.registry = Registry()
        self.registry.registerInterface(IAddThisSettings)
        directlyProvides(self.portal.REQUEST, IAddThisBrowserLayer)

    def test_registry_event_listener(self):
        pj = getToolByName(self.portal, 'portal_javascripts')
        BASE = 'collective.addthis.interfaces.IAddThisSettings.%s'
        rec = self.registry.records
        rec[BASE % 'addthis_load_asynchronously'].value = True
        transaction.commit()
        addthis = pj.getResource('++resource++collective.addthis/addthis.js')
        self.assertTrue(addthis.getEnabled())
        rec[BASE % 'addthis_load_asynchronously'].value = False
        transaction.commit()
        self.assertFalse(addthis.getEnabled())
Beispiel #41
0
    def test_not_listed(self):
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(IPloneCacheSettings)

        ploneSettings = registry.forInterface(IPloneCacheSettings)
        ploneSettings.purgedContentTypes = (
            'File',
            'Image',
        )

        content = DummyContent()
        self.assertEqual(False, isPurged(content))
Beispiel #42
0
    def test_parent_not_IBrowserDefault_default_method(self):
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(IPloneCacheSettings)

        ploneSettings = registry.forInterface(IPloneCacheSettings)
        ploneSettings.templateRulesetMapping = {}
        ploneSettings.contentTypeRulesetMapping = {'testtype': 'rule1'}

        published = ZopePageTemplate('defaultView').__of__(
            DummyNotBrowserDefault('testtype', 'string:${object_url}/'))
        request = DummyRequest(published, DummyResponse())
        self.assertEqual('rule1', ContentItemLookup(published, request)())
class TestAuthomaticSettingsControlPanel(unittest.TestCase):

    layer = PAS_PLUGINS_Authomatic_PLONE_INTEGRATION_TESTING

    def setUp(self):
        self.portal = self.layer["portal"]
        self.request = self.layer["request"]
        self.registry = Registry()
        self.registry.registerInterface(IPasPluginsAuthomaticSettings)

    def test_authomatic_controlpanel_view(self):
        view = getMultiAdapter((self.portal, self.portal.REQUEST),
                               name="authomatic-controlpanel")
        # view = view.__of__(self.portal)
        self.assertTrue(view())

    def test_authomatic_controlpanel_view_protected(self):
        from AccessControl import Unauthorized

        logout()
        self.assertRaises(
            Unauthorized,
            self.portal.restrictedTraverse,
            "@@authomatic-controlpanel",
        )

    def test_authomatic_in_controlpanel(self):
        self.controlpanel = getToolByName(self.portal, "portal_controlpanel")
        self.assertTrue(
            "authomatic" in
            [a.getAction(self)["id"] for a in self.controlpanel.listActions()])

    def test_record_config_property(self):
        record = self.registry.records[
            "pas.plugins.authomatic.interfaces." +
            "IPasPluginsAuthomaticSettings.json_config"]
        self.assertTrue("json_config" in IPasPluginsAuthomaticSettings)
        self.assertGreater(len(record.value), 20)
Beispiel #44
0
    def test_lookupOption_override(self):
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)

        registry.records['plone.caching.tests.test'] = r = Record(
            field.TextLine(), u'default')
        registry.records['plone.caching.tests.testrule.test'] = Record(
            FieldRef(r.__name__, r.field), u'override')

        result = lookupOption('plone.caching.tests',
                              'testrule',
                              'test',
                              default=_marker)
        self.assertEqual(u'override', result)
Beispiel #45
0
    def test_contenttype_class_lookup_type_override(self):
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(IPloneCacheSettings)

        ploneSettings = registry.forInterface(IPloneCacheSettings)
        ploneSettings.templateRulesetMapping = {}
        ploneSettings.contentTypeRulesetMapping = {'testtype': 'rule2'}

        z3c.caching.registry.register(DummyContent, 'rule1')

        published = ZopePageTemplate('defaultView').__of__(DummyContent())
        request = DummyRequest(published, DummyResponse())
        self.assertEqual('rule2', ContentItemLookup(published, request)())
Beispiel #46
0
    def test_no_published_object(self):
        provideAdapter(DefaultRulesetLookup)
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(ICacheSettings)
        settings = registry.forInterface(ICacheSettings)
        settings.enabled = True

        request = DummyRequest(None, DummyResponse())

        MutatorTransform(None, request).transformUnicode(u'', 'utf-8')

        self.assertEqual({'PUBLISHED': None}, dict(request))
        self.assertEqual({}, dict(request.response))
Beispiel #47
0
    def setUp(self):
        self.context = None
        self.example_vocab = SimpleVocabulary.fromValues([1, 2, 3, 4])
        self.example_source = ExampleSource(
            [SimpleTerm(1),
             SimpleTerm(2),
             SimpleTerm(3),
             SimpleTerm(4)])

        registry = getVocabularyRegistry()
        registry.register('example-vocab', ExampleVocabFactory)

        plone_registry = Registry()
        provideUtility(plone_registry, IRegistry)
class DecoControlPanelIntegrationTest(PloneTestCase):

    layer = PLONE_APP_TILES_INTEGRATION_TESTING

    def setUp(self):
        self.portal = self.layer['portal']
        setRoles(self.portal, TEST_USER_ID, ['Manager'])
        self.registry = Registry()
        self.registry.registerInterface(IDecoSettings)

    def test_deco_registry_registered(self):
        self.assertTrue(self.registry.forInterface(IDecoSettings))

    def test_deco_controlpanel_view(self):
        view = getMultiAdapter((self.portal, self.portal.REQUEST),
                               name="deco-controlpanel")
        view = view.__of__(self.portal)
        self.assertTrue(view())
        self.assertTrue("Deco Controlpanel" in view())

    def test_akismet_controlpanel_view_protected(self):
        from AccessControl import Unauthorized
        self.logout()
        self.assertRaises(Unauthorized, self.portal.restrictedTraverse,
                          '@@deco-controlpanel')

    def test_akismet_in_controlpanel(self):
        self.controlpanel = getToolByName(self.portal, "portal_controlpanel")
        self.assertTrue(
            'deco' in
            [a.getAction(self)['id'] for a in self.controlpanel.listActions()])

    def test_available_tiles_key(self):
        record_available_tiles = self.registry.records[
            'plone.app.tiles.interfaces.IDecoSettings.available_tiles']
        self.assertTrue('available_tiles' in IDecoSettings)
        self.assertEqual(record_available_tiles.value, ())
    def setUp(self):
        self.handler = Handler()
        provideHandler(self.handler.handler)

        provideHandler(objectEventNotify)
        provideHandler(purgeOnModified)
        provideHandler(purgeOnMovedOrRemoved)

        provideAdapter(persistentFieldAdapter)
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(IPloneCacheSettings)

        ploneSettings = registry.forInterface(IPloneCacheSettings)
        ploneSettings.purgedContentTypes = ('testtype', )
Beispiel #50
0
    def test_contenttype_class_lookup_browser_view(self):
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(IPloneCacheSettings)

        ploneSettings = registry.forInterface(IPloneCacheSettings)
        ploneSettings.templateRulesetMapping = {}
        ploneSettings.contentTypeRulesetMapping = {}

        z3c.caching.registry.register(DummyContent, 'rule1')

        published = DummyView(DummyContent(), None)
        request = DummyRequest(published, DummyResponse())
        published.request = published

        self.assertEqual('rule1', ContentItemLookup(published, request)())
Beispiel #51
0
    def test_lookupOptions_no_records(self):
        provideUtility(Registry(), IRegistry)

        @provider(ICachingOperationType)
        class DummyOperation(object):

            title = u''
            description = u''
            prefix = 'plone.caching.tests'
            options = (
                'test1',
                'test2',
            )

        result = lookupOptions(DummyOperation, 'testrule', default=_marker)
        self.assertEqual({'test1': _marker, 'test2': _marker}, result)
Beispiel #52
0
    def test_no_cache_rule(self):
        provideAdapter(DefaultRulesetLookup)
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(ICacheSettings)
        settings = registry.forInterface(ICacheSettings)
        settings.enabled = True

        settings.operationMapping = {'testrule': 'dummy'}

        view = DummyView()
        request = DummyRequest(view, DummyResponse())
        intercept(DummyEvent(request))

        self.assertEqual({'PUBLISHED': view}, dict(request))
        self.assertEqual({}, dict(request.response))
Beispiel #53
0
    def test_no_cache_rule(self):
        provideAdapter(DefaultRulesetLookup)
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(ICacheSettings)
        settings = registry.forInterface(ICacheSettings)
        settings.enabled = True

        settings.operationMapping = {'testrule': 'dummy'}

        view = DummyView()
        request = DummyRequest(view, DummyResponse())

        MutatorTransform(view, request).transformUnicode(u"", "utf-8")

        self.assertEquals({'PUBLISHED': view}, dict(request))
        self.assertEquals({}, dict(request.response))
Beispiel #54
0
    def test_no_lookup_adapter(self):
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(ICacheSettings)
        settings = registry.forInterface(ICacheSettings)
        settings.enabled = True

        z3c.caching.registry.register(DummyView, 'testrule')
        settings.operationMapping = {'testrule': 'dummy'}

        view = DummyView()
        request = DummyRequest(view, DummyResponse())

        MutatorTransform(view, request).transformUnicode(u'', 'utf-8')

        self.assertEqual({'PUBLISHED': view}, dict(request))
        self.assertEqual({}, dict(request.response))
Beispiel #55
0
    def test_operation_not_found(self):
        provideAdapter(DefaultRulesetLookup)
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(ICacheSettings)
        settings = registry.forInterface(ICacheSettings)
        settings.enabled = True

        z3c.caching.registry.register(DummyView, 'testrule')
        settings.operationMapping = {'testrule': 'notfound'}

        view = DummyView()
        request = DummyRequest(view, DummyResponse())
        intercept(DummyEvent(request))

        self.assertEquals({'PUBLISHED': view}, dict(request))
        self.assertEquals({'X-Cache-Rule': ['testrule']},
                          dict(request.response))
Beispiel #56
0
    def test_no_lookup_adapter(self):
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(ICacheSettings)
        settings = registry.forInterface(ICacheSettings)
        settings.enabled = True

        z3c.caching.registry.register(DummyView, 'testrule')
        settings.operationMapping = {'testrule': 'dummy'}

        view = DummyView()
        response = DummyResponse()
        request = DummyRequest(view, response)
        setRequest(request)

        modifyStreamingResponse(DummyStreamingEvent(response))

        self.assertEqual({'PUBLISHED': view}, dict(request))
        self.assertEqual({}, dict(request.response))
Beispiel #57
0
    def test_operation_name_not_found(self):
        provideAdapter(DefaultRulesetLookup)
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(ICacheSettings)
        settings = registry.forInterface(ICacheSettings)
        settings.enabled = True

        z3c.caching.registry.register(DummyView, 'testrule')
        settings.operationMapping = {'foo': 'bar'}

        view = DummyView()
        request = DummyRequest(view, DummyResponse())

        MutatorTransform(view, request).transformUnicode(u'', 'utf-8')

        self.assertEqual({'PUBLISHED': view}, dict(request))
        self.assertEqual({'X-Cache-Rule': ['testrule']},
                         dict(request.response))
Beispiel #58
0
    def test_no_mapping(self):
        provideAdapter(DefaultRulesetLookup)
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(ICacheSettings)
        settings = registry.forInterface(ICacheSettings)
        settings.enabled = True

        z3c.caching.registry.register(DummyView, 'testrule')

        view = DummyView()
        response = DummyResponse()
        request = DummyRequest(view, response)
        setRequest(request)

        modifyStreamingResponse(DummyStreamingEvent(response))

        self.assertEquals({'PUBLISHED': view}, dict(request))
        self.assertEquals({}, dict(request.response))
Beispiel #59
0
    def test_caching_disabled(self):
        request = FauxRequest()
        alsoProvides(request, IAttributeAnnotatable)

        IAnnotations(request)['plone.cachepurging.urls'] = set(
            ['/foo', '/bar'])

        registry = Registry()
        registry.registerInterface(ICachePurgingSettings)
        registry.registerInterface(ICloudflareSettings)
        provideUtility(registry, IRegistry)

        settings = registry.forInterface(ICachePurgingSettings)
        settings.enabled = False

        settings = registry.forInterface(ICloudflareSettings)
        settings.apiKey = u'foobar'
        settings.domains = (u'www.foobar.com', )
        notify(PubSuccess(request))

        self.assertEqual([], self.purger.purged)
Beispiel #60
0
    def test_GZip_enabled(self):
        from plone.app.caching.operations.etags import GZip

        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(IPloneCacheSettings)

        ploneSettings = registry.forInterface(IPloneCacheSettings)
        ploneSettings.enableCompression = True

        environ = {'SERVER_NAME': 'example.com', 'SERVER_PORT': '80'}
        response = HTTPResponse()
        request = HTTPRequest(StringIO(), environ, response)
        published = DummyPublished(DummyContext())

        request.environ['HTTP_ACCEPT_ENCODING'] = 'deflate; gzip'

        etag = GZip(published, request)

        self.assertEqual('1', etag())