Ejemplo n.º 1
0
 def test_get_non_publishables(self):
     """Test get_non_publishables with content.
     """
     tests.assertContentItemsEqual(
         self.root.folder.get_non_publishables(),
         [self.root.folder['data_file.xml'],
          self.root.folder['picture.tif']])
    def test_default_installed_sources(self):
        """Verify installed sources. By default it should cs_toc and
        cs_citation.
        """
        self.assertTrue('cs_citation' in self.root.objectIds())
        self.assertTrue('cs_toc' in self.root.objectIds())

        service = queryUtility(ICodeSourceService)
        tests.assertContentItemsEqual(
            list(service.get_installed_sources()),
            [self.root.cs_toc, self.root.cs_citation])

        # We can get the installable and they will tell us the same
        candidates = list(service.get_installable_source(
                identifier='cs_citation'))
        self.assertEqual(len(candidates), 1)
        installable = candidates[0]
        self.assertTrue(installable.is_installed(self.root), True)
        self.assertEqual(
            installable.location,
            'Products.SilvaExternalSources:/Products/SilvaExternalSources/codesources/cs_citation')

        candidates = list(service.get_installable_source(
                identifier='cs_toc'))
        self.assertEqual(len(candidates), 1)
        installable = candidates[0]
        self.assertTrue(installable.is_installed(self.root), True)
        self.assertEqual(
            installable.location,
            'Products.SilvaExternalSources:/Products/SilvaExternalSources/codesources/cs_toc')
Ejemplo n.º 3
0
 def test_get_ordered_publishables(self):
     """Test get_ordered_publishables with content.
     """
     tests.assertContentItemsEqual(
         self.root.folder.get_ordered_publishables(),
         [self.root.folder['first_link'],
          self.root.folder['second_link'],
          self.root.folder['folder'],
          self.root.folder['publication']])
    def test_install_source(self):
        """Install cs_portlet_element, a default code source into a
        folder.
        """
        service = queryUtility(ICodeSourceService)
        candidates = list(service.get_installable_source(
                identifier='cs_portlet_element'))
        self.assertEqual(len(candidates), 1)
        installable = candidates[0]
        self.assertTrue(verifyObject(ICodeSourceInstaller, installable))
        self.assertEqual(
            installable.identifier,
            'cs_portlet_element')
        self.assertEqual(
            installable.location,
            'Products.SilvaExternalSources:/Products/SilvaExternalSources/codesources/cs_portlet_element')
        self.assertEqual(installable.validate(), True)

        # By default this source is not installed
        self.assertEqual(installable.is_installed(self.root), False)
        self.assertEqual(installable.is_installed(self.root.folder), False)

        # We can install it.
        installable.install(self.root.folder)

        # And it is installed
        self.assertEqual(installable.is_installed(self.root), False)
        self.assertEqual(installable.is_installed(self.root.folder), True)
        self.assertTrue('cs_portlet_element' in self.root.folder.objectIds())

        # And the location matches the one of the installer
        installed = self.root.folder.cs_portlet_element
        self.assertEqual(installable.location, installed.get_fs_location())
        self.assertItemsEqual(
            installed.objectIds(),
            ['icon.png', 'README', 'LICENSE', 'portlet_element'])
        self.assertEqual(
            installed._getOb('icon.png').meta_type,
            'Image')
        self.assertEqual(
            installed._getOb('portlet_element').meta_type,
            'Page Template')

        # The source appears in the service as well
        tests.assertContentItemsEqual(
            list(service.get_installed_sources()),
            [self.root.cs_citation, self.root.cs_toc, installed])
Ejemplo n.º 5
0
 def test_filters(self):
     """Test methods to manage filters.
     """
     self.assertTrue(self.root.viewer.has_filter())
     tests.assertContentItemsEqual(self.root.viewer.get_filters(), [self.root.private])
     self.root.viewer.add_filter(self.root.public)
     tests.assertContentItemsEqual(self.root.viewer.get_filters(), [self.root.public, self.root.private])
     self.root.manage_delObjects(["private"])
     self.assertTrue(self.root.viewer.has_filter())
     tests.assertContentItemsEqual(self.root.viewer.get_filters(), [self.root.public])
     self.root.viewer.set_filters([])
     tests.assertContentItemsEqual(self.root.viewer.get_filters(), [])
     self.assertFalse(self.root.viewer.has_filter())
Ejemplo n.º 6
0
 def test_upgrade_news_filter(self):
     """Test upgrade of a news filter.
     """
     self.root._setObject('news', NewsPublication('news'))
     self.root._setObject('events', NewsPublication('events'))
     self.root._setObject('filter', NewsFilter('filter'))
     self.assertIn('news', self.root.objectIds())
     self.assertIn('events', self.root.objectIds())
     self.assertIn('filter', self.root.objectIds())
     self.assertIn('index', self.root.objectIds())
     self.root.filter._sources = [
         '/root/news', '/root/events', '/root/index', '/root/lala',
         '/root/@@pouet'
     ]
     self.assertTrue(filter_upgrader.validate(self.root.filter))
     self.assertEqual(filter_upgrader.upgrade(self.root.filter),
                      self.root.filter)
     self.assertFalse(filter_upgrader.validate(self.root.filter))
     tests.assertContentItemsEqual(self.root.filter.get_sources(),
                                   [self.root.news, self.root.events])
Ejemplo n.º 7
0
 def test_upgrade_news_viewer(self):
     """Test upgrade of a news viewer
     """
     self.root._setObject('news', NewsFilter('news'))
     self.root._setObject('events', NewsFilter('events'))
     self.root._setObject('viewer', NewsViewer('viewer'))
     self.assertIn('news', self.root.objectIds())
     self.assertIn('events', self.root.objectIds())
     self.assertIn('viewer', self.root.objectIds())
     self.assertIn('index', self.root.objectIds())
     self.root.viewer._filters = [
         '/root/index', '/root/news', '/root/lala', '/root/@@pouet',
         '/root/events'
     ]
     self.assertTrue(viewer_upgrader.validate(self.root.viewer))
     self.assertEqual(viewer_upgrader.upgrade(self.root.viewer),
                      self.root.viewer)
     self.assertFalse(viewer_upgrader.validate(self.root.viewer))
     tests.assertContentItemsEqual(self.root.viewer.get_filters(),
                                   [self.root.news, self.root.events])
Ejemplo n.º 8
0
    def test_find_all_sources(self):
        """Find all the sources that are global.
        """
        service = getUtility(IServiceNews)
        # By default there are no sources.
        tests.assertContentItemsEqual(
            list(service.get_all_sources()),
            [])

        factory = self.root.manage_addProduct['silva.app.news']
        factory.manage_addNewsPublication('news', 'News')

        # We should now see the soure we added.
        tests.assertContentItemsEqual(
            list(service.get_all_sources()),
            [self.root.news])

        factory = self.root.manage_addProduct['Silva']
        factory.manage_addFolder('section', 'Section')
        factory = self.root.section.manage_addProduct['silva.app.news']
        factory.manage_addNewsPublication('news', 'Section News')

        # We should now see all the sources we added.
        tests.assertContentItemsEqual(
            list(service.get_all_sources()),
            [self.root.news, self.root.section.news])
Ejemplo n.º 9
0
    def test_find_all_filters(self):
        """Find all the news filters.
        """
        service = getUtility(IServiceNews)
        # By default there are no filters.
        tests.assertContentItemsEqual(
            list(service.get_all_filters()),
            [])

        factory = self.root.manage_addProduct['silva.app.news']
        factory.manage_addAgendaFilter('agenda_filter', 'Agenda Filter')
        factory.manage_addNewsFilter('news_filter', 'News Filter')

        factory = self.root.manage_addProduct['Silva']
        factory.manage_addFolder('info', 'Info')
        factory = self.root.info.manage_addProduct['silva.app.news']
        factory.manage_addAgendaFilter('agenda_filter', 'Agenda Filter')

        # We should now find all the agenda and news filters we added
        tests.assertContentItemsEqual(
            list(service.get_all_filters()),
            [self.root.news_filter, self.root.agenda_filter,
             self.root.info.agenda_filter])

        # We should now find all the agenda and news filters we added
        tests.assertContentItemsEqual(
            list(service.get_all_filters(IAgendaFilter)),
            [self.root.agenda_filter,
             self.root.info.agenda_filter])
Ejemplo n.º 10
0
    def test_news_publication(self):
        # A news pub with a viewer (index) a filter (filter) customized
        # A news item, an agenda item, agenda viewer and agenda filter.
        importer = self.assertImportFile(
            "test_import_newspublication.silvaxml",
            [
                "/root/news/index",
                "/root/news/the_empire_falls",
                "/root/news/lolcats_attacks",
                "/root/news/events",
                "/root/news/filter",
                "/root/news/filter_events",
                "/root/news",
            ],
        )

        news = self.root._getOb("news", None)
        self.assertTrue(verifyObject(interfaces.INewsPublication, news))
        self.assertEqual(
            self.root.news.objectIds(),
            ["index", "the_empire_falls", "lolcats_attacks", "events", "filter", "filter_events"],
        )
        # Verify content
        self.assertTrue(verifyObject(interfaces.INewsViewer, news.index))
        self.assertTrue(verifyObject(interfaces.INewsFilter, news.filter))
        self.assertTrue(verifyObject(interfaces.IAgendaViewer, news.events))
        self.assertTrue(verifyObject(interfaces.IAgendaFilter, news.filter_events))
        self.assertEqual(
            importer.getProblems(),
            [
                (
                    u"Broken source in import: External Source cs_you_tube is not available.",
                    news.lolcats_attacks.get_viewable(),
                )
            ],
        )

        # Verify setup
        tests.assertContentItemsEqual(news.filter.get_sources(), [news])
        tests.assertContentItemsEqual(news.index.get_filters(), [news.filter])
        tests.assertContentItemsEqual(news.filter_events.get_sources(), [news])
        tests.assertContentItemsEqual(news.events.get_filters(), [news.filter_events])
        self.assertItemsEqual(
            [b.getPath() for b in news.index.get_items()],
            ["/root/news/the_empire_falls/0", "/root/news/lolcats_attacks/0"],
        )
        self.assertItemsEqual(
            [b.getPath() for b in news.events.get_items_by_date(7, 2012)], ["/root/news/lolcats_attacks/0"]
        )
        self.assertItemsEqual([b.getPath() for b in news.events.get_items()], [])
Ejemplo n.º 11
0
    def test_find_all_sources_private(self):
        """Find all the sources, including the ones marked as private
        in a folder.
        """
        factory = self.root.manage_addProduct['silva.app.news']
        factory.manage_addNewsPublication('news', 'Global News')
        factory = self.root.manage_addProduct['Silva']
        factory.manage_addFolder('documentation', 'Documentation')
        factory.manage_addFolder('section', 'Section')
        factory = self.root.section.manage_addProduct['silva.app.news']
        factory.manage_addNewsPublication('local', 'Local News')
        factory = self.root.section.manage_addProduct['Silva']
        factory.manage_addFolder('documentation', 'Documentation')

        metadata = getUtility(IMetadataService)
        binding = metadata.getMetadata(self.root.section.local)
        binding.setValues('snn-np-settings', {'is_private': 'yes'}, reindex=1)

        # Globally, or somewhere else we should only see the global folder.
        service = getUtility(IServiceNews)
        tests.assertContentItemsEqual(
            list(service.get_all_sources()),
            [self.root.news])
        tests.assertContentItemsEqual(
            list(service.get_all_sources(self.root)),
            [self.root.news])
        tests.assertContentItemsEqual(
            list(service.get_all_sources(self.root.documentation)),
            [self.root.news])

        # Inside section, or in a sub folder of it we should see the
        # local folder.
        tests.assertContentItemsEqual(
            list(service.get_all_sources(self.root.section)),
            [self.root.news, self.root.section.local])
        tests.assertContentItemsEqual(
            list(service.get_all_sources(self.root.section.documentation)),
            [self.root.news, self.root.section.local])
Ejemplo n.º 12
0
 def test_upgrade_news_filter(self):
     """Test upgrade of a news filter.
     """
     self.root._setObject('news', NewsPublication('news'))
     self.root._setObject('events', NewsPublication('events'))
     self.root._setObject('filter', NewsFilter('filter'))
     self.assertIn('news', self.root.objectIds())
     self.assertIn('events', self.root.objectIds())
     self.assertIn('filter', self.root.objectIds())
     self.assertIn('index', self.root.objectIds())
     self.root.filter._sources = [
         '/root/news',
         '/root/events',
         '/root/index',
         '/root/lala',
         '/root/@@pouet']
     self.assertTrue(filter_upgrader.validate(self.root.filter))
     self.assertEqual(
         filter_upgrader.upgrade(self.root.filter),
         self.root.filter)
     self.assertFalse(filter_upgrader.validate(self.root.filter))
     tests.assertContentItemsEqual(
         self.root.filter.get_sources(),
         [self.root.news, self.root.events])
Ejemplo n.º 13
0
 def test_upgrade_news_viewer(self):
     """Test upgrade of a news viewer
     """
     self.root._setObject('news', NewsFilter('news'))
     self.root._setObject('events', NewsFilter('events'))
     self.root._setObject('viewer', NewsViewer('viewer'))
     self.assertIn('news', self.root.objectIds())
     self.assertIn('events', self.root.objectIds())
     self.assertIn('viewer', self.root.objectIds())
     self.assertIn('index', self.root.objectIds())
     self.root.viewer._filters = [
         '/root/index',
         '/root/news',
         '/root/lala',
         '/root/@@pouet',
         '/root/events']
     self.assertTrue(viewer_upgrader.validate(self.root.viewer))
     self.assertEqual(
         viewer_upgrader.upgrade(self.root.viewer),
         self.root.viewer)
     self.assertFalse(viewer_upgrader.validate(self.root.viewer))
     tests.assertContentItemsEqual(
         self.root.viewer.get_filters(),
         [self.root.news, self.root.events])
Ejemplo n.º 14
0
    def test_sources(self):
        """Test get_sources, set_sources and has_sources.
        """
        self.assertFalse(self.root.filter.has_sources())
        tests.assertContentItemsEqual(
            self.root.filter.get_sources(),
            [])

        self.root.filter.set_sources([self.root.news, self.root.events])
        self.assertTrue(self.root.filter.has_sources())
        tests.assertContentItemsEqual(
            self.root.filter.get_sources(),
            [self.root.news, self.root.events])

        self.root.manage_delObjects(['events'])
        self.assertTrue(self.root.filter.has_sources())
        tests.assertContentItemsEqual(
            self.root.filter.get_sources(),
            [self.root.news])
Ejemplo n.º 15
0
    def test_excluded_items(self):
        """Test methods to manage excluded items.
        """
        tests.assertContentItemsEqual(
            self.root.filter.get_excluded_items(),
            [])

        excluded = self.root.news.rain
        self.assertFalse(self.root.filter.is_excluded_item(excluded))

        # Add the element to the list of excluded items.
        self.root.filter.add_excluded_item(excluded)
        self.assertTrue(self.root.filter.is_excluded_item(excluded))
        tests.assertContentItemsEqual(
            self.root.filter.get_excluded_items(),
            [excluded])

        # Remove the element from the list of excluded items
        self.root.filter.remove_excluded_item(excluded)
        self.assertFalse(self.root.filter.is_excluded_item(excluded))
        tests.assertContentItemsEqual(
            self.root.filter.get_excluded_items(),
            [])
Ejemplo n.º 16
0
 def test_get_ordered_publishables_empty(self):
     """Test get_ordered_publishables without content.
     """
     tests.assertContentItemsEqual(
         self.root.folder.get_ordered_publishables(),
         [])