Пример #1
0
    def test_no_subtree_propagation(self):
        portal = self.layer['portal']
        portal.invokeFactory(type_name='Folder', id='news', title="News")

        request = self.layer['request']
        request.set('ACTUAL_URL', 'http://nohost/plone/news')
        self.markRequestWithLayer()
        settings = self.getSettings()

        self.assertTrue('SITE DEFAULT ANALYTICS' in portal.news())

        record = SitePathValuePair()
        record.path = u'/news'
        record.path_snippet = u'Only for news'
        record.apply_to = u'context'
        settings.path_specific_code += (record, )

        self.assertTrue('Only for news' in portal.news())

        portal.news.invokeFactory(type_name='Folder',
                                  id='subnews',
                                  title="Subnews")
        request.set('ACTUAL_URL', 'http://nohost/plone/news/subnews')

        self.assertTrue('SITE DEFAULT ANALYTICS' in portal.news.subnews())
Пример #2
0
    def test_most_specific_path_used(self):
        portal = self.layer['portal']
        portal.invokeFactory(type_name='Folder', id='news', title="News")
        portal.news.invokeFactory(type_name='Folder',
                                  id='subnews',
                                  title="Subfolder inside news")

        request = self.layer['request']
        request.set('ACTUAL_URL', 'http://nohost/plone/news')
        self.markRequestWithLayer()
        settings = self.getSettings()

        record1 = SitePathValuePair()
        record1.path = u'/news'
        record1.path_snippet = u'You are in the News section'
        record1.apply_to = u'subtree'
        record2 = SitePathValuePair()
        record2.path = u'/news/subnews'
        record2.path_snippet = u'You are in the Subnews section'
        record2.apply_to = u'subtree'
        settings.path_specific_code += (record1, record2)

        request.set('ACTUAL_URL', 'http://nohost/plone/news')
        self.assertTrue(
            'You are in the Subnews section' in portal.news.subnews())
Пример #3
0
    def test_apply_to_folder_and_children_with_new_folderish(self):
        request = self.layer['request']
        self.markRequestWithLayer()
        settings = self.getSettings()

        portal = self.layer['portal']
        portal.invokeFactory(type_name='Folder', id='news', title="News")
        news = portal.news
        news.invokeFactory(type_name='News Item',
                           id='real_news',
                           title="A real news")
        news.invokeFactory(type_name='Document',
                           id='home',
                           title="Homepage for news section")

        record = SitePathValuePair()
        record.path = u'/news'
        record.path_snippet = u'For news and children'
        record.apply_to = u'context_and_children'
        settings.path_specific_code += (record, )
        settings.folderish_types = (u'Folder', u'News Item')

        request.set('ACTUAL_URL', 'http://nohost/plone/news')
        self.assertTrue('For news and children' in portal.news())
        request.set('ACTUAL_URL', 'http://nohost/plone/news/home')
        self.assertTrue('For news and children' in portal.news.home())
        request.set('ACTUAL_URL', 'http://nohost/plone/news/real_news')
        self.assertTrue('SITE DEFAULT ANALYTICS' in portal.news.real_news())
Пример #4
0
    def test_apply_to_folder_and_children_with_new_folderish(self):
        request = self.layer['request']
        self.markRequestWithLayer()
        settings = self.getSettings()
        settings.general_header_code = u'DEFAULT ANALYTICS IN HEADER'

        portal = self.layer['portal']
        portal.invokeFactory(type_name='Folder', id='news', title="News")
        news = portal.news
        news.invokeFactory(type_name='News Item', id='real_news', title="A real news")
        news.invokeFactory(type_name='Document', id='home', title="Homepage for news section")

        record = SitePathValuePair()
        record.path = u'/news'
        record.path_snippet = u'For news and children (footer)'
        record.apply_to = u'context_and_children'
        settings.path_specific_code += (record,)
        settings.folderish_types = (u'Folder', u'News Item')
        record = SitePathValuePair()
        record.path = u'/news'
        record.path_snippet = u'For news and children (header)'
        record.apply_to = u'context_and_children'
        record.position = u'header'
        settings.path_specific_code += (record,)
        settings.folderish_types = (u'Folder', u'News Item')

        request.set('ACTUAL_URL', 'http://nohost/plone/news')
        self.assertTrue('For news and children (footer)' in portal.news())
        self.assertTrue('For news and children (header)' in portal.news())
        request.set('ACTUAL_URL', 'http://nohost/plone/news/home')
        self.assertTrue('For news and children (footer)' in portal.news.home())
        self.assertTrue('For news and children (header)' in portal.news.home())
        request.set('ACTUAL_URL', 'http://nohost/plone/news/real_news')
        self.assertTrue('SITE DEFAULT ANALYTICS' in portal.news.real_news())
        self.assertTrue('DEFAULT ANALYTICS IN HEADER' in portal.news.real_news())
Пример #5
0
    def test_for_path(self):
        portal = self.layer['portal']
        portal.invokeFactory(type_name='Folder', id='news', title="News")
        request = self.layer['request']
        request.set('ACTUAL_URL', 'http://nohost/plone/news')
        self.markRequestWithLayer()
        settings = self.getSettings()

        record = SitePathValuePair()
        record.path = u'/news'
        record.path_snippet = u'You are in the News section (footer)'
        record.apply_to = u'subtree'
        settings.path_specific_code += (record,)

        record = SitePathValuePair()
        record.path = u'/news'
        record.path_snippet = u'You are in the News section (header)'
        record.apply_to = u'subtree'
        record.position = u'header'
        settings.path_specific_code += (record,)

        self.assertTrue('You are in the News section (footer)' in portal.news())
        self.assertTrue('You are in the News section (header)' in portal.news())
        request.set('ACTUAL_URL', 'http://nohost/plone')
        self.assertFalse('You are in the News section' in portal())
Пример #6
0
    def test_no_subtree_propagation(self):
        portal = self.layer['portal']
        portal.invokeFactory(type_name='Folder', id='news', title="News")

        request = self.layer['request']
        request.set('ACTUAL_URL', 'http://nohost/plone/news')
        self.markRequestWithLayer()
        settings = self.getSettings()
        settings.general_header_code = u'DEFAULT ANALYTICS IN HEADER'

        self.assertTrue('SITE DEFAULT ANALYTICS' in portal.news())
        self.assertTrue('DEFAULT ANALYTICS IN HEADER' in portal.news())

        record = SitePathValuePair()
        record.path = u'/news'
        record.path_snippet = u'Only for news (footer)'
        record.apply_to = u'context'
        settings.path_specific_code += (record,)
        record = SitePathValuePair()
        record.path = u'/news'
        record.path_snippet = u'Only for news (header)'
        record.apply_to = u'context'
        record.position = u'header'
        settings.path_specific_code += (record,)

        self.assertTrue('Only for news (footer)' in portal.news())
        self.assertTrue('Only for news (header)' in portal.news())
        
        portal.news.invokeFactory(type_name='Folder', id='subnews', title="Subnews")
        request.set('ACTUAL_URL', 'http://nohost/plone/news/subnews')

        self.assertTrue('SITE DEFAULT ANALYTICS' in portal.news.subnews())
        self.assertTrue('DEFAULT ANALYTICS IN HEADER' in portal.news.subnews())
Пример #7
0
    def test_hiding_code(self):
        portal = self.layer['portal']
        portal.invokeFactory(type_name='Folder', id='news', title="News")

        request = self.layer['request']
        request.set('ACTUAL_URL', 'http://nohost/plone/news')
        self.markRequestWithLayer()
        settings = self.getSettings()
        settings.general_header_code = u'DEFAULT ANALYTICS IN HEADER'

        self.assertTrue('SITE DEFAULT ANALYTICS' in portal.news())
        self.assertTrue('DEFAULT ANALYTICS IN HEADER' in portal.news())

        record = SitePathValuePair()
        record.path = u'/news'
        record.path_snippet = u''
        record.apply_to = u'subtree'
        settings.path_specific_code += (record,)
        record = SitePathValuePair()
        record.path = u'/news'
        record.path_snippet = u''
        record.apply_to = u'subtree'
        record.position = 'header'
        settings.path_specific_code += (record,)

        self.assertFalse('SITE DEFAULT ANALYTICS' in portal.news())
        self.assertFalse('DEFAULT ANALYTICS IN HEADER' in portal.news())
def migrateTo1100(context):
    setup_tool = getToolByName(context, 'portal_setup')
    registry = queryUtility(IRegistry)
    settings = registry.forInterface(IAnalyticsSettingsSchema, check=False)
    # 1. saving old data
    # 1.1. adding position field to errors analytics
    logger.info('Registering position support to error snippets')
    new_error_snippets = []
    for error_snippet in settings.error_specific_code:
        migrated = ErrorCodeValuePair(error_snippet.message, error_snippet.message_snippet, 'footer')
        new_error_snippets.append(migrated)
        logger.info('...done')
    # 1.2. adding position field to path analytics
    logger.info('Registering position support to path snippets')
    new_path_snippets = []
    for path_snippet in settings.path_specific_code:
        migrated = SitePathValuePair(path_snippet.path, path_snippet.path_snippet,
                                     path_snippet.apply_to, 'footer')
        new_path_snippets.append(migrated)
        logger.info('...done')
    # 1.3. Nullify fields
    logger.info('Cleaning old registrations')
    settings.error_specific_code = tuple()
    settings.path_specific_code = tuple()
    # 2. registering new data
    logger.info('Import new migrated data')
    setup_tool.runImportStepFromProfile(PROFILE_ID, 'plone.app.registry')
    settings.error_specific_code = tuple(new_error_snippets)
    settings.path_specific_code = tuple(new_path_snippets)
    logger.info('Migrated to version 0.4')
Пример #9
0
    def test_for_path(self):
        portal = self.layer['portal']
        portal.invokeFactory(type_name='Folder', id='news', title="News")
        request = self.layer['request']
        request.set('ACTUAL_URL', 'http://nohost/plone/news')
        self.markRequestWithLayer()
        settings = self.getSettings()

        record = SitePathValuePair()
        record.path = u'/news'
        record.path_snippet = u'You are in the News section'
        record.apply_to = u'subtree'
        settings.path_specific_code += (record, )

        self.assertTrue('You are in the News section' in portal.news())
        request.set('ACTUAL_URL', 'http://nohost/plone')
        self.assertFalse('You are in the News section' in portal())
    def test_apply_to_folder_and_children(self):
        request = self.layer['request']
        self.markRequestWithLayer()
        settings = self.getSettings()

        portal = self.layer['portal']
        portal.invokeFactory(type_name='Folder', id='news', title="News")
        news = portal.news
        news.invokeFactory(type_name='Folder', id='subnews', title="Sub news")
        news.invokeFactory(type_name='Document', id='home', title="Homepage for news section")

        record = SitePathValuePair()
        record.path = u'/news'
        record.path_snippet = u'For news and children'
        record.apply_to = u'context_and_children'
        settings.path_specific_code += (record,)

        request.set('ACTUAL_URL', 'http://nohost/plone/news')
        self.assertTrue('For news and children' in portal.news())
        request.set('ACTUAL_URL', 'http://nohost/plone/news/home')
        self.assertTrue('For news and children' in portal.news.home())
        request.set('ACTUAL_URL', 'http://nohost/plone/news/subnews')
        self.assertTrue('SITE DEFAULT ANALYTICS' in portal.news.subnews())
    def test_most_specific_path_used(self):
        portal = self.layer['portal']
        portal.invokeFactory(type_name='Folder', id='news', title="News")
        portal.news.invokeFactory(type_name='Folder', id='subnews', title="Subfolder inside news")

        request = self.layer['request']
        request.set('ACTUAL_URL', 'http://nohost/plone/news')
        self.markRequestWithLayer()
        settings = self.getSettings()

        record1 = SitePathValuePair()
        record1.path = u'/news'
        record1.path_snippet = u'You are in the News section'
        record1.apply_to_subsection = True
        record2 = SitePathValuePair()
        record2.path = u'/news/subnews'
        record2.path_snippet = u'You are in the Subnews section'
        record2.apply_to_subsection = True
        settings.path_specific_code += (record1, record2)

        request.set('ACTUAL_URL', 'http://nohost/plone/news')
        self.assertTrue('You are in the Subnews section' in portal.news.subnews())
    def test_apply_to_folder_and_children(self):
        self.markRequestWithLayer()
        settings = self.getSettings()
        settings.general_header_code = u'DEFAULT ANALYTICS IN HEADER'
        self.portal.invokeFactory(type_name='Folder', id='news', title="News")
        news = self.portal.news
        news.invokeFactory(type_name='Folder', id='subnews', title="Sub news")
        news.invokeFactory(type_name='Document',
                           id='home',
                           title="Homepage for news section")

        record = SitePathValuePair()
        record.path = u'/news'
        record.path_snippet = u'For news and children (footer)'
        record.apply_to = u'context_and_children'
        settings.path_specific_code += (record, )
        record = SitePathValuePair()
        record.path = u'/news'
        record.path_snippet = u'For news and children (header)'
        record.apply_to = u'context_and_children'
        record.position = u'header'
        settings.path_specific_code += (record, )

        self.request.set('ACTUAL_URL', 'http://nohost/plone/news')
        self.assertTrue('For news and children (footer)' in self.portal.news())
        self.assertTrue('For news and children (header)' in self.portal.news())
        self.request.set('ACTUAL_URL', 'http://nohost/plone/news/home')
        self.assertTrue(
            'For news and children (footer)' in self.portal.news.home())
        self.assertTrue(
            'For news and children (header)' in self.portal.news.home())
        self.request.set('ACTUAL_URL', 'http://nohost/plone/news/subnews')
        self.assertTrue('SITE DEFAULT ANALYTICS' in self.portal.news.subnews())
        self.assertTrue(
            'DEFAULT ANALYTICS IN HEADER' in self.portal.news.subnews())
    def test_no_subtree_propagation(self):
        self.portal.invokeFactory(type_name='Folder', id='news', title="News")

        self.request.set('ACTUAL_URL', 'http://nohost/plone/news')
        self.markRequestWithLayer()
        settings = self.getSettings()
        settings.general_header_code = u'DEFAULT ANALYTICS IN HEADER'

        self.assertTrue('SITE DEFAULT ANALYTICS' in self.portal.news())
        self.assertTrue('DEFAULT ANALYTICS IN HEADER' in self.portal.news())

        record = SitePathValuePair()
        record.path = u'/news'
        record.path_snippet = u'Only for news (footer)'
        record.apply_to = u'context'
        settings.path_specific_code += (record, )
        record = SitePathValuePair()
        record.path = u'/news'
        record.path_snippet = u'Only for news (header)'
        record.apply_to = u'context'
        record.position = u'header'
        settings.path_specific_code += (record, )

        self.assertTrue('Only for news (footer)' in self.portal.news())
        self.assertTrue('Only for news (header)' in self.portal.news())

        self.portal.news.invokeFactory(type_name='Folder',
                                       id='subnews',
                                       title="Subnews")
        self.request.set('ACTUAL_URL', 'http://nohost/plone/news/subnews')

        self.assertTrue('SITE DEFAULT ANALYTICS' in self.portal.news.subnews())
        self.assertTrue(
            'DEFAULT ANALYTICS IN HEADER' in self.portal.news.subnews())
    def test_hiding_code(self):
        self.portal.invokeFactory(type_name='Folder', id='news', title="News")

        self.request.set('ACTUAL_URL', 'http://nohost/plone/news')
        self.markRequestWithLayer()
        settings = self.getSettings()
        settings.general_header_code = u'DEFAULT ANALYTICS IN HEADER'

        self.assertTrue('SITE DEFAULT ANALYTICS' in self.portal.news())
        self.assertTrue('DEFAULT ANALYTICS IN HEADER' in self.portal.news())

        record = SitePathValuePair()
        record.path = u'/news'
        record.path_snippet = u''
        record.apply_to = u'subtree'
        settings.path_specific_code += (record, )
        record = SitePathValuePair()
        record.path = u'/news'
        record.path_snippet = u''
        record.apply_to = u'subtree'
        record.position = 'header'
        settings.path_specific_code += (record, )

        self.assertFalse('SITE DEFAULT ANALYTICS' in self.portal.news())
        self.assertFalse('DEFAULT ANALYTICS IN HEADER' in self.portal.news())