Esempio n. 1
0
    def test_add_asset(self):
        with SimpleTransaction():
            factory = self.root.manage_addProduct['Silva']
            factory.manage_addFile('examples_txt', 'Examples')

        request = TestRequest()
        invalidation = Invalidation(request)
        self.assertEqual(request.cookies, {})
        self.assertEqual(
            list(invalidation.get_changes()),
            [{'action': 'add',
              'interface': 'assets',
              'listing': 'assets',
              'container': self.get_id(self.root),
              'content': self.get_id(self.root.examples_txt),
              'position': -1},
             {'action': 'update',
              'interface': 'containers',
              'listing': 'publishables',
              'container': self.get_id(aq_parent(self.root)),
              'content': self.get_id(self.root),
              'position': -1}])
        # A cookie is set
        self.assertEqual(
            request.response.cookies,
            {'silva.listing.invalidation': {'path': '/root', 'value': '2'}})

        # Now if we ask the next changes, there are none
        request = TestRequest()
        request.cookies = {'silva.listing.invalidation': '2'}
        invalidation = Invalidation(request)
        self.assertEqual(list(invalidation.get_changes()), [])
    def test_root_not_applied(self):
        """Rewriting is not applied if the header is not present.
        """
        request = TestRequest(
            application=self.root,
            url='http://localhost/docs')
        plugin = request.query_plugin(request.application, IVirtualHosting)
        root, method, path = plugin(request.method, request.path)
        self.assertEqual(root, request.application)
        self.assertEqual(method, 'index_html')
        self.assertEqual(path, ['docs'])
        self.assertEqual('http://localhost/docs', request['ACTUAL_URL'])

        url = getMultiAdapter((self.root, request), IContentURL)
        self.assertTrue(verifyObject(IContentURL, url))

        self.assertEqual(
            str(url),
            'http://localhost/root')
        self.assertEqual(
            url.url(),
            'http://localhost/root')
        self.assertEqual(
            url.url(relative=True),
            '/root')
        self.assertEqual(
            url.url(relative=True, preview=True),
            '/root/++preview++')
        self.assertEqual(
            url.url(preview=True),
            'http://localhost/root/++preview++')
        self.assertEqual(
            url.preview(),
            'http://localhost/root/++preview++')
    def test_rewrite_url_change_path_multiple_to_one(self):
        """Test cases where rewritting a URL should change its URL path.
        """
        request = TestRequest(
            application=self.root,
            url='http://localhost/man/edit',
            headers=[('X-VHM-Url', 'http://localhost')])
        plugin = request.query_plugin(request.application, IVirtualHosting)
        root, method, path = plugin(request.method, request.path)

        self.assertEqual(
            plugin.rewrite_url(
                'https://localhost',
                'http://localhost/man/edit'),
            'https://localhost/docs/dev/man/edit')
        self.assertEqual(
            plugin.rewrite_url(
                'https://localhost',
                'http://localhost/admin/edit'),
            'https://localhost/docs/admin/edit')
        self.assertEqual(
            plugin.rewrite_url(
                'https://localhost',
                'http://localhost/site/docs/users/edit'),
            'https://localhost/docs/users/edit')
    def test_virtual_site_top_level_is_not_unique(self):
        """Test cases where the Silva root is the highest URL you can
        get.
        """
        # Sub case 1
        request = TestRequest(
            application=self.root,
            url='https://complicated/admin/edit',
            headers=[('X-VHM-Url', 'https://complicated')])
        plugin = request.query_plugin(request.application, IVirtualHosting)
        root, method, path = plugin(request.method, request.path)

        site = IVirtualSite(request)
        self.assertTrue(verifyObject(IVirtualSite, site))
        self.assertEqual(site.get_root_url(), 'https://complicated/admin')
        self.assertEqual(site.get_root_path(), '/admin')
        self.assertEqual(site.get_top_level_url(), 'https://complicated/admin')
        self.assertEqual(site.get_top_level_path(), '/admin')

        # Sub case 2
        request = TestRequest(
            application=self.root,
            url='https://complicated/site/edit',
            headers=[('X-VHM-Url', 'https://complicated')])
        plugin = request.query_plugin(request.application, IVirtualHosting)
        root, method, path = plugin(request.method, request.path)

        site = IVirtualSite(request)
        self.assertTrue(verifyObject(IVirtualSite, site))
        self.assertEqual(site.get_root_url(), 'https://complicated/site')
        self.assertEqual(site.get_root_path(), '/site')
        self.assertEqual(site.get_top_level_url(), 'https://complicated/site')
        self.assertEqual(site.get_top_level_path(), '/site')
    def test_activated_default(self):
        request = TestRequest(
            application=self.root,
            url='http://localhost')
        plugin = request.query_plugin(request.application, IVirtualHosting)
        root, method, path = plugin(request.method, request.path)
        self.assertEqual(root, request.application)
        self.assertEqual(method, 'index_html')
        self.assertEqual(path, request.path)

        url = getMultiAdapter((self.root, request), IContentURL)
        self.assertTrue(verifyObject(IContentURL, url))

        self.assertEqual(
            str(url),
            'http://localhost/root')
        self.assertEqual(
            url.url(),
            'http://localhost/root')
        self.assertEqual(
            url.url(relative=True),
            '/root')
        self.assertEqual(
            url.url(relative=True, preview=True),
            '/root/++preview++')
        self.assertEqual(
            url.url(preview=True),
            'http://localhost/root/++preview++')
        self.assertEqual(
            url.preview(),
            'http://localhost/root/++preview++')
    def test_root(self):
        """If the header is present, rewriting is applied.
        """
        request = TestRequest(
            application=self.root,
            url='http://localhost/docs',
            headers=[('X-VHM-Url', 'http://localhost')])
        plugin = request.query_plugin(request.application, IVirtualHosting)
        root, method, path = plugin(request.method, request.path)
        self.assertEqual(root, self.root)
        self.assertEqual(method, 'index_html')
        self.assertEqual(path, ['docs'])

        url = getMultiAdapter((self.root, request), IContentURL)
        self.assertTrue(verifyObject(IContentURL, url))

        self.assertEqual(
            str(url),
            'http://localhost')
        self.assertEqual(
            url.url(),
            'http://localhost')
        self.assertEqual(
            url.url(relative=True),
            '/')
        self.assertEqual(
            url.url(relative=True, preview=True),
            '/++preview++')
        self.assertEqual(
            url.url(preview=True),
            'http://localhost/++preview++')
        self.assertEqual(
            url.preview(),
            'http://localhost/++preview++')
    def test_round_trip(self):
        """Make a trip:
        1. Create items.
        2. Export them.
        3. Import them.
        4. Export them.
        5. Check that export created at 2. and 4. are identical.
        """
        # 1. create content
        # 2. export
        exporter1 = getAdapter(self.root.publication,
                               interfaces.IContentExporter,
                               name='zip')
        self.assertTrue(verifyObject(interfaces.IContentExporter, exporter1))

        export1 = exporter1.export(TestRequest())

        # 3. import
        factory = self.root.manage_addProduct['Silva']
        factory.manage_addFolder('folder', 'Import Folder')
        importer = getAdapter(self.root.folder, interfaces.IZipFileImporter)
        self.assertTrue(verifyObject(interfaces.IZipFileImporter, importer))

        clearEvents()
        importer.importFromZip(StringIO(export1), TestRequest())

        self.assertEventsAre([
            'ContentImported for /root/folder/publication',
            'ContentImported for /root/folder/publication/assets',
            'ContentImported for /root/folder/publication/infrae',
            'ContentImported for /root/folder/publication/nice',
            'ContentImported for /root/folder/publication/pictures',
            'ContentImported for /root/folder/publication/pictures/tobesorted',
            'ContentImported for /root/folder/publication/pictures/torvald',
            'ContentImported for /root/folder/publication/pictures/unknown',
            'ContentImported for /root/folder/publication/trash'
        ], IContentImported)

        imported_ghost = self.root.folder.publication.nice
        imported_link = self.root.folder.publication.infrae
        self.assertEqual(imported_ghost.get_editable().get_haunted(),
                         imported_link)

        # 4. export
        exporter2 = getAdapter(self.root.folder.publication,
                               interfaces.IContentExporter,
                               name='zip')

        export2 = exporter2.export(TestRequest())

        # 5. compare the two exports
        zip_export1 = ZipFile(StringIO(export1))
        zip_export2 = ZipFile(StringIO(export2))

        self.failUnless('silva.xml' in zip_export1.namelist())
        self.assertItemsEqual(zip_export1.namelist(), zip_export2.namelist())
        silva_export1 = zip_export1.read('silva.xml')
        silva_export2 = zip_export2.read('silva.xml')

        self.assertXMLEqual(silva_export1, silva_export2)
    def test_activated_default(self):
        request = TestRequest(
            application=self.root,
            url='http://localhost')
        plugin = request.query_plugin(request.application, IVirtualHosting)
        root, method, path = plugin(request.method, request.path)
        self.assertEqual(root, request.application)
        self.assertEqual(method, 'index_html')
        self.assertEqual(path, [])

        url = getMultiAdapter((self.root, request), IContentURL)
        self.assertEqual(
            url.breadcrumbs(),
            ({'name': u'root',
              'url': 'http://localhost/root'},))

        url = getMultiAdapter((self.root.docs.dev, request), IContentURL)
        self.assertEqual(
            url.breadcrumbs(),
            ({'name': u'root',
              'url': 'http://localhost/root', },
             {'name': u'Documentation',
              'url': 'http://localhost/root/docs'},
             {'name': u'Developer',
              'url': 'http://localhost/root/docs/dev'}))
    def test_rewrite_url_no_change(self):
        """Test simple cases where rewritting a URL should not changes
        its URL path.
        """
        request = TestRequest(
            application=self.root,
            url='http://localhost/man/edit',
            headers=[('X-VHM-Url', 'http://localhost')])
        plugin = request.query_plugin(request.application, IVirtualHosting)
        root, method, path = plugin(request.method, request.path)

        self.assertIsNot(
            plugin.host,
            None)
        self.assertEqual(
            plugin.rewrite_url(None, 'http://localhost/man/edit'),
            '/man/edit')
        self.assertEqual(
            plugin.rewrite_url(
                'http://localhost',
                'http://localhost/man/edit'),
            'http://localhost/man/edit')
        self.assertEqual(
            plugin.rewrite_url(
                'http://localhost',
                'http://localhost/site/docs/users/edit'),
            'http://localhost/site/docs/users/edit')
Esempio n. 10
0
    def test_archive(self):
        """Test you can move the source in a folder. The rendering in
        the document will be broken after, and you will have a
        message, only in preview.
        """
        factory = self.root.manage_addProduct['OFSP']
        factory.manage_addFolder('folder', 'Folder')
        self.assertFalse(IFolder.providedBy(self.root.folder))
        self.assertNotIn('codesource', self.root.folder.objectIds())
        self.assertIn('codesource', self.root.objectIds())

        token = self.root.manage_cutObjects(['codesource'])
        self.root.folder.manage_pasteObjects(token)
        self.assertIn('codesource', self.root.folder.objectIds())
        self.assertNotIn('codesource', self.root.objectIds())

        controller = self.get_controller()
        self.assertTrue(verifyObject(IExternalSourceController, controller))
        with self.assertRaises(SourceMissingError) as error:
            controller.render()

        message = silvaviews.render(error.exception, TestRequest())
        self.assertEqual(message.strip(), '')
        message = silvaviews.render(error.exception,
                                    TestRequest(),
                                    preview=True)
        self.assertEqual(message.strip(),
                         '<p>External Source unknow is not available.</p>')

        # The source is no longer available
        self.assertItemsEqual([
            name_candidate3 for name_candidate3 in availableSources(self.root)
            if name_candidate3[0] == 'codesource'
        ], [])
 def test_skin_not_activated(self):
     request = TestRequest(
         application=self.root,
         url='http://localhost')
     plugin = request.query_plugin(request.application, IVirtualHosting)
     root, method, path = plugin(request.method, request.path)
     self.assertEqual(root, request.application)
     self.assertEqual(method, 'index_html')
     self.assertEqual(path, [])
     self.assertFalse(IMultiflexSkin.providedBy(request))
 def test_backend_alias(self):
     request = TestRequest(
         application=self.root,
         url='http://admin.localhost/docs/admin',
         headers=[('X-VHM-Url', 'http://backend.localhost')])
     plugin = request.query_plugin(request.application, IVirtualHosting)
     root, method, path = plugin(request.method, request.path)
     self.assertEqual(root, self.root)
     self.assertEqual(method, 'index_html')
     self.assertEqual(path, ['admin', 'docs'])
Esempio n. 13
0
    def test_remove(self):
        """Remove a broken source, this should work.
        """
        controller = self.sources(TestRequest(), instance=self.identifier)
        controller.remove()

        self.assertEqual(len(self.sources.all()), 0)
        with self.assertRaises(errors.ParametersMissingError):
            self.sources.get_parameters(instance=self.identifier)
        with self.assertRaises(errors.ParametersMissingError):
            self.sources(TestRequest(), instance=self.identifier)
 def test_skin_folder_not_enforced(self):
     request = TestRequest(
         application=self.root,
         url='http://localhost/user/information',
         headers=[('X-VHM-Url', 'http://localhost')])
     plugin = request.query_plugin(request.application, IVirtualHosting)
     root, method, path = plugin(request.method, request.path)
     self.assertEqual(root, self.root.docs.user)
     self.assertEqual(method, 'index_html')
     self.assertEqual(path, ['information'])
     self.assertTrue(IMultiflexSkin.providedBy(request))
     self.assertFalse(IStandardIssueSkin.providedBy(request))
     self.assertTrue(request.get(SET_SKIN_ALLOWED_FLAG, True))
    def test_vhm(self):
        """Test IContentURL url computation while a VHM is used. Zope
        object doesn't support the preview mode.
        """
        request = TestRequest(
            application=self.root,
            url='http://localhost/service_extension',
            headers=[('X-VHM-Url', 'http://infrae.com'),
                     ('X-VHM-Path', '/root')])
        plugin = request.query_plugin(request.application, IVirtualHosting)
        root, method, path = plugin(request.method, request.path)
        self.assertEqual(root, self.root)
        self.assertEqual(method, 'index_html')
        self.assertEqual(path, ['service_extension'])

        url = component.getMultiAdapter(
            (self.root.service_extensions, request), IContentURL)
        self.assertTrue(verifyObject(IContentURL, url))
        self.assertTrue(IContentURL.extends(IAbsoluteURL))

        self.assertEqual(
            str(url),
            'http://infrae.com/service_extensions')
        self.assertEqual(
            url(),
            'http://infrae.com/service_extensions')
        self.assertEqual(
            url.url(relative=True),
            '/service_extensions')
        self.assertEqual(
            url.url(relative=True, preview=True),
            '/service_extensions')
        self.assertEqual(
            url.preview(),
            'http://infrae.com/service_extensions')
        self.assertEqual(
            url.url(host='http://silvacms.org'),
            'http://silvacms.org/service_extensions')
        self.assertEqual(
            url.url(host='http://silvacms.org', preview=True),
            'http://silvacms.org/service_extensions')

        alsoProvides(request, IPreviewLayer)
        self.assertEqual(
            str(url),
            'http://infrae.com/service_extensions')
        self.assertEqual(
            url(),
            'http://infrae.com/service_extensions')
    def test_virtual_site_simple(self):
        """Test simple cases nothing special is set or done.
        """
        request = TestRequest(
            application=self.root,
            url='http://localhost/man/edit',
            headers=[('X-VHM-Url', 'http://localhost')])
        plugin = request.query_plugin(request.application, IVirtualHosting)
        root, method, path = plugin(request.method, request.path)

        site = IVirtualSite(request)
        self.assertTrue(verifyObject(IVirtualSite, site))
        self.assertEqual(site.get_root_url(), 'http://localhost')
        self.assertEqual(site.get_root_path(), '/')
        self.assertEqual(site.get_top_level_url(), 'http://localhost')
        self.assertEqual(site.get_top_level_path(), '/')
Esempio n. 17
0
    def test_render(self):
        """Render a defined source.
        """
        controller = self.sources(TestRequest(), instance=self.identifier)
        self.assertXMLEqual(
            controller.render(), """
<div class="citation">
 je bent een klootzak
 <div class="author">jou</div>
 <div class="source">wikipedia</div>
</div>
""")

        # If you set a source template, it is used around the output
        parameters, _ = self.sources.get_parameters(instance=self.identifier)
        parameters.set_source_template("""<div class="portlet">
   <!-- source output -->
   <div class="portlet-footer" />
</div>
""")
        self.assertXMLEqual(
            controller.render(), """
<div class="portlet">
 <div class="citation">
   je bent een klootzak
   <div class="author">jou</div>
   <div class="source">wikipedia</div>
 </div>
 <div class="portlet-footer" />
</div>
""")
Esempio n. 18
0
    def test_save_unicode(self):
        """Updating source parameters, with unicode values.
        """
        request = TestRequest(
            form={
                'field_citation': u'Cela est éternel'.encode('utf-8'),
                'field_author': 'moi',
                'marker_field_citation': '1',
                'marker_field_author': '1',
                'marker_field_source': '1'
            })
        controller = self.sources(request, instance=self.identifier)
        controller.save()

        parameters, source = self.sources.get_parameters(
            instance=self.identifier)

        self.assertEqual(parameters.get_source_identifier(), 'cs_citation')
        self.assertEqual(parameters.citation, u'Cela est éternel')
        self.assertEqual(parameters.author, u'moi')
        self.assertEqual(parameters.source, u'')
        self.assertXMLEqual(
            controller.render(), u"""
<div class="citation">
 Cela est éternel
 <div class="author">
  moi
 </div>
 <div class="source">
 </div>
</div>
""")
Esempio n. 19
0
    def test_save(self):
        """Updating source parameters.
        """
        request = TestRequest(
            form={
                'field_citation': 'il fait soleil',
                'field_author': 'moi',
                'marker_field_citation': '1',
                'marker_field_author': '1',
                'marker_field_source': '1'
            })
        controller = self.sources(request, instance=self.identifier)
        controller.save()

        parameters, source = self.sources.get_parameters(
            instance=self.identifier)

        self.assertEqual(parameters.get_source_identifier(), 'cs_citation')
        self.assertEqual(parameters.citation, u'il fait soleil')
        self.assertEqual(parameters.author, u'moi')
        self.assertEqual(parameters.source, u'')
        self.assertXMLEqual(
            controller.render(), """
<div class="citation">
 il fait soleil
 <div class="author">moi</div>
 <div class="source"></div>
</div>
""")
 def setUp(self):
     self.root = self.layer.get_application()
     self.layer.login('author')
     factory = self.root.manage_addProduct['SilvaDocument']
     factory.manage_addDocument('document', 'Document')
     self.request = TestRequest()
     self.version = self.root.document.get_editable()
    def test_rewritten_short_activated(self):
        request = TestRequest(
            application=self.root,
            url='http://localhost/admin/manual',
            headers=[('X-VHM-Url', 'http://localhost')])
        plugin = request.query_plugin(request.application, IVirtualHosting)
        root, method, path = plugin(request.method, request.path)
        self.assertEqual(root, self.root.docs.admin)
        self.assertEqual(method, 'index_html')
        self.assertEqual(path, ['manual'])

        url = getMultiAdapter((self.root.docs.admin, request), IContentURL)
        self.assertEqual(
            url.breadcrumbs(),
            ({'name': u'Administrator',
              'url': 'http://localhost/admin'},))
Esempio n. 22
0
    def setUp(self):
        self.root = self.layer.get_application()
        self.layer.login('manager')

        # Create a test document.
        factory = self.root.manage_addProduct['silva.app.document']
        factory.manage_addDocument('example', 'Example')

        # Create a test code source.
        factory = self.root.manage_addProduct['SilvaExternalSources']
        factory.manage_addCodeSource('codesource', 'Test Source', 'script')
        source = self.root._getOb('codesource', None)

        # Add the rendering script
        factory = source.manage_addProduct['PythonScripts']
        factory.manage_addPythonScript('script')
        script = source._getOb('script')
        script.write("""
##parameters=model,version,REQUEST

return "Render source"
""")

        # Create an instance of the code source
        version = self.root.example.get_editable()
        sources = getWrapper(version, IExternalSourceManager)
        controller = sources(TestRequest(), name='codesource')
        controller.create()
        self._instance = controller.getId()
    def test_display_source_with_default_alignement(self):
        """If you render without any layer, you will see the code
        source rendered.
        """
        version = self.root.document.get_editable()
        factory = getMultiAdapter((version, TestRequest()),
                                  ITransformerFactory)
        transformer = factory(
            'body', version.body, """
<div class="external-source default" data-source-instance="%s">
</div>
""" % self.instance_key, IDisplayFilter)
        tests.assertXMLEqual(
            unicode(transformer), """
<div class="citation">
 Don't trust citations on the Internet
 <div class="author">
  Charlemagne
 </div>
 <div class="source">
  The Internet
 </div>
</div>
""")
        sources = getWrapper(version, IExternalSourceManager)
        self.assertEqual(len(sources.all()), 1)
Esempio n. 24
0
    def test_zip_export(self):
        """Import/export a Zip file.
        """
        # XXX This test needs improvement.
        with Transaction():
            with self.layer.open_fixture('test1.zip') as zip_import:
                importer = interfaces.IArchiveFileImporter(self.root.folder)
                succeeded, failed = importer.importArchive(zip_import)

        self.assertItemsEqual(succeeded, [
            'testzip/Clock.swf', 'testzip/bar/image2.jpg',
            'testzip/foo/bar/baz/image5.jpg', 'testzip/foo/bar/image4.jpg',
            'testzip/foo/image3.jpg', 'testzip/image1.jpg',
            'testzip/sound1.mp3'
        ])
        self.assertItemsEqual(failed, [])

        exporter = getAdapter(self.root.folder,
                              interfaces.IContentExporter,
                              name='zip')
        export = exporter.export(TestRequest(), stream=io.BytesIO())
        export.seek(0)

        zip_export = ZipFile(export, 'r')
        self.assertItemsEqual([
            'assets/1.jpg', 'assets/2.jpg', 'assets/3.jpg', 'assets/4.jpg',
            'assets/5.swf', 'assets/6.jpg', 'assets/7.mp3', 'silva.xml'
        ], zip_export.namelist())
        zip_export.close()
Esempio n. 25
0
    def test_create_transform(self):
        """Create a new source instance, of an existing code source.
        """
        request = TestRequest()
        version = self.root.example.get_editable()
        version.body.save(version, request, HTML_WORKING_SOURCE)

        # This gives access to all the sources
        sources = getWrapper(version, IExternalSourceManager)
        self.assertTrue(verifyObject(IExternalSourceManager, sources))
        self.assertEqual(len(sources.all()), 1)
        instance_key = list(sources.all())[0]

        parameters, source = sources.get_parameters(instance=instance_key)
        self.assertTrue(verifyObject(IExternalSourceInstance, parameters))

        # A parameters store data
        self.assertEqual(parameters.get_source_identifier(), 'cs_citation')
        self.assertEqual(parameters.get_parameter_identifier(), instance_key)
        self.assertEqual(source.id, 'cs_citation')
        self.assertEqual(parameters.citation, u'je bent een klootzak')
        self.assertEqual(parameters.author, u'jou')
        self.assertEqual(parameters.source, u'wikipedia')

        # You can bind parameters to a content and a request
        controller = sources(request, instance=instance_key)
        self.assertTrue(verifyObject(IExternalSourceController, controller))
Esempio n. 26
0
    def test_icon_tag(self):
        """Test usefull function used to access icon tags.
        """
        resolver = queryAdapter(TestRequest(), IIconResolver)
        self.assertTrue(verifyObject(IIconResolver, resolver))

        self.assertEqual(
            resolver.get_tag(self.root),
            '<img height="16" width="16" src="http://localhost/root/++resource++icon-Silva-Root.png" alt="Silva Root" />'
        )
        self.assertEqual(
            resolver.get_tag(content=self.root),
            '<img height="16" width="16" src="http://localhost/root/++resource++icon-Silva-Root.png" alt="Silva Root" />'
        )
        self.assertEqual(
            resolver.get_tag(identifier='Silva Root'),
            '<img height="16" width="16" src="http://localhost/root/++resource++icon-Silva-Root.png" alt="Silva Root" />'
        )
        self.assertEqual(
            resolver.get_tag(identifier='default'),
            '<img height="16" width="16" src="http://localhost/root/++static++/silva.icons/generic.png" alt="default" />'
        )
        self.assertEqual(
            resolver.get_tag(),
            '<img height="16" width="16" src="http://localhost/root/++static++/silva.icons/missing.png" alt="Missing" />'
        )
    def test_virtual_site_top_level_is_not_root_at_top_level(self):
        """Test cases where the Silva root is not the highest URL you
        can get.
        """
        request = TestRequest(
            application=self.root,
            url='http://localhost/man/edit',
            headers=[('X-VHM-Url', 'http://localhost')])
        plugin = request.query_plugin(request.application, IVirtualHosting)
        root, method, path = plugin(request.method, request.path)

        site = IVirtualSite(request)
        self.assertTrue(verifyObject(IVirtualSite, site))
        self.assertEqual(site.get_root_url(), 'http://localhost')
        self.assertEqual(site.get_root_path(), '/')
        self.assertEqual(site.get_top_level_url(), 'http://localhost')
        self.assertEqual(site.get_top_level_path(), '/')
    def test_unicode_form_save_problems(self):
        view = getMultiAdapter(
            (self.root.forum.topic, TestRequest()),
            name='content.html')

        view.request.form['title'] = 'F\u00fb'.encode('UTF-8')
        view.request.form['text'] = 'b\u00e4r'.encode('UTF-8')

        view.update()
Esempio n. 29
0
 def assertExportFail(self,
                      content,
                      error=ExternalReferenceError,
                      options={}):
     #transaction.commit()
     exporter = Exporter(content, TestRequest(), options.copy())
     with self.assertRaises(error):
         exporter.getString()
     return exporter
    def test_format_text(self):
        view = getMultiAdapter(
            (self.root.forum.topic.com, TestRequest()),
            name='content.html')
        view.update()

        self.assertEqual('foo bar', view.format_text('foo bar'))
        self.assertEqual('foo<br />bar', view.format_text('foo\nbar'))
        self.assertEquals('foo&lt;bar', view.format_text('foo<bar'))
Esempio n. 31
0
    def test_install_documentation(self):
        """Test documentation installation. That should not make any
        error at all.
        """
        self.assertFalse('docs' in self.root.objectIds())

        install_documentation(self.root, TestRequest())
        self.assertTrue('docs' in self.root.objectIds())
        self.assertTrue(verifyObject(IPublication, self.root._getOb('docs')))
 def transform(self, text, filter, version, public=True):
     """Helper to call transform.
     """
     layers = []
     if not public:
         layers = [IPreviewLayer]
     request = TestRequest(layers=layers)
     factory = getMultiAdapter((version, request), ITransformerFactory)
     transformer = factory('body', version.body, text, filter)
     return unicode(transformer)
Esempio n. 33
0
    def setUp(self):
        self.root = self.layer.get_application()
        self.layer.login('manager')
        factory = self.root.manage_addProduct['silva.app.document']
        factory.manage_addDocument('example', 'Example')

        version = self.root.example.get_editable()
        version.body.save(version, TestRequest(), HTML_WORKING_SOURCE)
        self.sources = getWrapper(version, IExternalSourceManager)
        self.identifier = list(self.sources.all())[0]
    def test_root_brain(self):
        """If the header is present, rewriting is applied. You can
        compute the URL of a brain inside the same virtual host.
        """
        request = TestRequest(
            application=self.root,
            url='http://localhost/docs/user',
            headers=[('X-VHM-Url', 'http://localhost')])
        plugin = request.query_plugin(request.application, IVirtualHosting)
        root, method, path = plugin(request.method, request.path)
        self.assertEqual(root, self.root)
        self.assertEqual(method, 'index_html')
        self.assertEqual(path, ['user', 'docs'])

        catalog = root.service_catalog
        brains = catalog(meta_type='Silva Root', path='/root')
        self.assertEqual(len(brains), 1)
        brain = brains[0]

        url = getMultiAdapter((brain, request), IContentURL)
        self.assertTrue(verifyObject(IContentURL, url))

        self.assertEqual(
            brain.getURL(),
            'http://localhost')
        self.assertEqual(
            str(url),
            'http://localhost')
        self.assertEqual(
            url.url(),
            'http://localhost')
        self.assertEqual(
            url.url(relative=True),
            '/')
        self.assertEqual(
            url.url(relative=True, preview=True),
            '/')
        self.assertEqual(
            url.url(preview=True),
            'http://localhost')
        self.assertEqual(
            url.preview(),
            'http://localhost')
Esempio n. 35
0
 def test_save(self):
     """You cannot save values into a broken source.
     """
     request = TestRequest(form={
         'field_citation': 'il fait soleil',
         'field_author': 'moi'
     })
     controller = self.sources(request, instance=self.identifier)
     with self.assertRaises(errors.SourceMissingError):
         controller.save()
    def test_rewritten_short_long(self):
        request = TestRequest(
            application=self.root,
            url='http://localhost/hidden/docs/resources/api',
            headers=[('X-VHM-Url', 'http://localhost')])
        plugin = request.query_plugin(request.application, IVirtualHosting)
        root, method, path = plugin(request.method, request.path)
        self.assertEqual(root, self.root.docs.dev)
        self.assertEqual(method, 'index_html')
        self.assertEqual(path, ['api', 'resources'])

        url = getMultiAdapter(
            (self.root.docs.dev.resources, request),
            IContentURL)
        self.assertEqual(
            url.breadcrumbs(),
            ({'name': u'Developer',
              'url': 'http://localhost/hidden/docs'},
             {'name': u'Resources',
              'url': 'http://localhost/hidden/docs/resources'},))
    def test_render(self):
        """Test rendering the CSV source.
        """
        source = self.root._getOb('csv_data', None)
        version = self.root.example.get_editable()
        with self.layer.open_fixture('informations.csv') as data:
            source.set_file(data)

        rendered = source.to_html(version, TestRequest())
        self.assertNotEqual(rendered, '')
        self.assertIn('Update CSV tests', rendered)
Esempio n. 38
0
    def test_create_transform_broken_failover(self):
        """Create a source that doesn't exists with failover. No
        source is created, but no error is yielded.
        """
        request = TestRequest()
        version = self.root.example.get_editable()
        version.body.save(version, request, HTML_BROKEN_SOURCE)

        # This gives access to all the sources
        sources = getWrapper(version, IExternalSourceManager)
        self.assertTrue(verifyObject(IExternalSourceManager, sources))
        self.assertEqual(len(sources.all()), 0)
Esempio n. 39
0
 def assertExportEqual(self, content, filename, options={}):
     """Verify that the xml result of an export is the same than
     the one contained in a test file.
     """
     #transaction.commit()
     exporter = Exporter(content, TestRequest(), options.copy())
     with self.layer.open_fixture(filename) as xml_file:
         expected_xml = xml_file.read().format(
             namespaces=self.getNamespaces(), version=self.getVersion())
         actual_xml = self.genericize(exporter.getString())
         self.assertXMLEqual(expected_xml, actual_xml)
     return exporter
    def test_delete_source(self):
        """If you save again without provided the html for the source,
        it is removed.
        """
        version = self.root.document.get_editable()
        factory = getMultiAdapter((version, TestRequest()),
                                  ITransformerFactory)
        transformer = factory('body', version.body, "", ISaveEditorFilter)
        tests.assertXMLEqual(unicode(transformer), "")

        sources = getWrapper(version, IExternalSourceManager)
        self.assertEqual(len(sources.all()), 0)
    def setUp(self):
        self.root = self.layer.get_application()
        self.layer.login('editor')
        factory = self.root.manage_addProduct['SilvaDocument']
        factory.manage_addDocument('document', 'Document')
        factory = self.root.manage_addProduct['Silva']
        factory.manage_addFolder('folder', 'Folder')
        with self.layer.open_fixture('chocobo.jpg') as image:
            factory.manage_addImage('chocobo', 'Chocobo', image)

        self.transformer = Transformer.EditorTransformer(editor='kupu')
        self.context = Context(
            self.root.document.get_editable(), TestRequest())
Esempio n. 42
0
    def test_render(self):
        """Test rendering of the sql source.
        """
        factory = self.root.manage_addProduct['SilvaExternalSources']
        factory.manage_addSQLSource('sql_data', 'SQL Data')

        source = self.root._getOb('sql_data', None)
        source._set_connection_id('dummy')
        version = self.root.example.get_editable()

        # The dummy connector is not connected
        with self.assertRaises(DatabaseError):
            source.to_html(version, TestRequest())
Esempio n. 43
0
    def test_controller(self):
        """Test the controller API.
        """
        controller = self.sources(TestRequest(), instance=self.identifier)
        _, source = self.sources.get_parameters(instance=self.identifier)
        self.assertTrue(verifyObject(IExternalSourceController, controller))

        self.assertEqual(controller.getId(), self.identifier)
        self.assertEqual(controller.getSourceId(), 'cs_citation')
        self.assertEqual(controller.editable(),
                         True)  # The source have fields.
        self.assertEqual(controller.label, source.get_title())
        self.assertEqual(controller.description, source.get_description())
Esempio n. 44
0
 def setUp(self):
     self.root = self.layer.get_application()
     with Transaction():
         self.layer.login('author')
         # You have to install the source as manager
         factory = self.root.manage_addProduct['Silva']
         factory.manage_addFolder('folder', 'Folder')
         factory = self.root.folder.manage_addProduct['silva.app.document']
         factory.manage_addDocument('example', 'Example')
         version = self.root.folder.example.get_editable()
         html = HTML_TOC_CODE_SOURCE.format(
             getUtility(IIntIds).register(self.root.folder))
         version.body.save(version, TestRequest(), html)
Esempio n. 45
0
    def test_date(self):
        result = schema.DateResultField('date', 'Publication Date')
        self.assertTrue(verifyObject(IResultField, result))
        self.assertEqual(result.getName(), 'publicationdate')
        self.assertEqual(result.getId(), 'date')
        self.assertEqual(result.getTitle(), 'Publication Date')
        self.assertEqual(result.getDescription(), '')

        view = queryMultiAdapter((result, self.root.search, TestRequest()),
                                 IResultView)
        self.assertTrue(verifyObject(IResultView, view))
        view.update(self.documents)
        # XXX difficult to test, contain a date
        self.assertNotEqual(view.render(self.documents[0]), '')
    def test_broken_render_source_asset(self):
        """Test a source that renders a source with a broken render
        script.
        """
        factory = self.root.manage_addProduct['SilvaExternalSources']
        factory.manage_addSourceAsset('asset', 'Test Asset')
        asset = self.root._getOb('asset', None)
        version = asset.get_editable()

        # Create a test code source
        factory = self.root.manage_addProduct['SilvaExternalSources']
        factory.manage_addCodeSource('brokensource', 'Broken Source', 'script')
        source = self.root._getOb('brokensource', None)

        # Add the rendering script
        factory = source.manage_addProduct['PythonScripts']
        factory.manage_addPythonScript('script')
        script = source._getOb('script')
        script.write("""
##parameters=model,version,REQUEST
I am broken
return "Render source"
""")

        # Create a source with the new test source
        sources = getWrapper(version, IExternalSourceManager)
        controller = sources(TestRequest(), name='brokensource')
        controller.create()
        version.set_parameters_identifier(controller.getId())

        # You can preview it, but it will fail with a nice message
        with self.layer.get_browser(public_settings) as browser:
            browser.login('editor')
            self.assertEqual(browser.open('/root/++preview++/asset'), 200)
            self.assertEqual(browser.inspect.title, [])
            self.assertEqual(
                browser.inspect.content,
                ['Error while rendering Broken Source\n  '
                 'A programmation error happened while rendering the source.'])

        IPublicationWorkflow(asset).publish()
        # We published the asset we still a nice error message instead
        # of a failure message.
        with self.layer.get_browser(public_settings) as browser:
            browser.options.handle_errors = False
            self.assertEqual(browser.open('/root/asset'), 200)
            self.assertEqual(browser.inspect.title, [])
            self.assertEqual(
                browser.inspect.content,
                ['Sorry, this Silva Source Asset is not viewable.'])
    def test_display_broken_xml_source_public(self):
        """Test a source that have an invalid or missing
        data-source-instance.
        """
        version = self.root.document.get_editable()
        factory = getMultiAdapter((version, TestRequest()),
                                  ITransformerFactory)
        transformer = factory('body', version.body,
                              '<div class="external-source"></div>',
                              IDisplayFilter)

        tests.assertXMLEqual(unicode(transformer), """
<div class="external-source">
</div>
""")
    def test_root_different_host(self):
        """Rewriting is applied even if the URL have not the same
        domain, but the header is present.
        """
        request = TestRequest(
            application=self.root,
            url='http://development.server.corp/docs',
            headers=[('X-VHM-Url', 'http://localhost')])
        plugin = request.query_plugin(request.application, IVirtualHosting)
        root, method, path = plugin(request.method, request.path)
        self.assertEqual(root, self.root)
        self.assertEqual(method, 'index_html')
        self.assertEqual(path, ['docs'])
        self.assertEqual('http://localhost/docs', request['ACTUAL_URL'])

        url = getMultiAdapter((self.root, request), IContentURL)
        self.assertTrue(verifyObject(IContentURL, url))

        self.assertEqual(
            str(url),
            'http://localhost')
        self.assertEqual(
            url.url(),
            'http://localhost')
        self.assertEqual(
            url.url(relative=True),
            '/')
        self.assertEqual(
            url.url(relative=True, preview=True),
            '/++preview++')
        self.assertEqual(
            url.url(preview=True),
            'http://localhost/++preview++')
        self.assertEqual(
            url.preview(),
            'http://localhost/++preview++')
    def test_folder_rewritten_long(self):
        """If the header is present, rewriting is applied.
        """
        request = TestRequest(
            application=self.root,
            url='http://localhost/hidden/docs/resources',
            headers=[('X-VHM-Url', 'http://localhost')])
        plugin = request.query_plugin(request.application, IVirtualHosting)
        root, method, path = plugin(request.method, request.path)
        self.assertEqual(root, self.root.docs.dev)
        self.assertEqual(method, 'index_html')
        self.assertEqual(path, ['resources'])

        url = getMultiAdapter((self.root.docs.admin, request), IContentURL)
        self.assertTrue(verifyObject(IContentURL, url))

        self.assertEqual(
            str(url),
            'http://localhost/admin')
        self.assertEqual(
            url.url(),
            'http://localhost/admin')
        self.assertEqual(
            url.url(relative=True),
            '/admin')
        self.assertEqual(
            url.url(relative=True, preview=True),
            '/admin/++preview++')
        self.assertEqual(
            url.url(preview=True),
            'http://localhost/admin/++preview++')
        self.assertEqual(
            url.preview(),
            'http://localhost/admin/++preview++')

        # Get the URL of a different folder
        url = getMultiAdapter((root.resources, request), IContentURL)
        self.assertTrue(verifyObject(IContentURL, url))

        self.assertEqual(
            str(url),
            'http://localhost/hidden/docs/resources')
        self.assertEqual(
            url.url(),
            'http://localhost/hidden/docs/resources')
        self.assertEqual(
            url.url(relative=True),
            '/hidden/docs/resources')
        self.assertEqual(
            url.url(relative=True, preview=True),
            '/hidden/docs/++preview++/resources')
        self.assertEqual(
            url.url(preview=True),
            'http://localhost/hidden/docs/++preview++/resources')
        self.assertEqual(
            url.preview(),
            'http://localhost/hidden/docs/++preview++/resources')

        # Get the URL of a different publication
        url = getMultiAdapter((self.root.docs, request), IContentURL)
        self.assertTrue(verifyObject(IContentURL, url))

        self.assertEqual(
            str(url),
            'http://localhost/docs')
        self.assertEqual(
            url.url(),
            'http://localhost/docs')
        self.assertEqual(
            url.url(relative=True),
            '/docs')
        self.assertEqual(
            url.url(relative=True, preview=True),
            '/++preview++/docs')
        self.assertEqual(
            url.url(preview=True),
            'http://localhost/++preview++/docs')
        self.assertEqual(
            url.preview(),
            'http://localhost/++preview++/docs')
    def test_frontend_alias(self):
        request = TestRequest(
            application=self.root,
            url='http://frontend.localhost/info',
            headers=[('X-VHM-Url', 'http://frontend.localhost')])
        plugin = request.query_plugin(request.application, IVirtualHosting)
        root, method, path = plugin(request.method, request.path)
        self.assertEqual(root, self.root)
        self.assertEqual(method, 'index_html')
        self.assertEqual(path, [])

        catalog = root.service_catalog
        brains = catalog(meta_type='Silva Folder', path='/root/docs/admin')
        self.assertEqual(len(brains), 1)
        brain = brains[0]

        url = getMultiAdapter((brain, request), IContentURL)
        self.assertTrue(verifyObject(IContentURL, url))

        self.assertEqual(
            brain.getURL(),
            'http://frontend.localhost')
        self.assertEqual(
            str(url),
            'http://frontend.localhost')
        self.assertEqual(
            url.url(),
            'http://frontend.localhost')
        self.assertEqual(
            url.url(relative=True),
            '/')
        self.assertEqual(
            url.url(relative=True, preview=True),
            '/')
        self.assertEqual(
            url.url(preview=True),
            'http://frontend.localhost')
        self.assertEqual(
            url.preview(),
            'http://frontend.localhost')

        catalog = root.service_catalog
        brains = catalog(meta_type='Silva Root', path='/root')
        self.assertEqual(len(brains), 1)
        brain = brains[0]

        url = getMultiAdapter((brain, request), IContentURL)
        self.assertTrue(verifyObject(IContentURL, url))

        self.assertEqual(
            brain.getURL(),
            'http://frontend.localhost/info')
        self.assertEqual(
            str(url),
            'http://frontend.localhost/info')
        self.assertEqual(
            url.url(),
            'http://frontend.localhost/info')
        self.assertEqual(
            url.url(relative=True),
            '/info')
        self.assertEqual(
            url.url(relative=True, preview=True),
            '/info')
        self.assertEqual(
            url.url(preview=True),
            'http://frontend.localhost/info')
        self.assertEqual(
            url.preview(),
            'http://frontend.localhost/info')
    def test_folder_brain_rewritten_long(self):
        """If the header is present, rewriting is applied.
        """
        request = TestRequest(
            application=self.root,
            url='http://localhost/hidden/docs/resources',
            headers=[('X-VHM-Url', 'http://localhost')])
        plugin = request.query_plugin(request.application, IVirtualHosting)
        root, method, path = plugin(request.method, request.path)
        self.assertEqual(root, self.root.docs.dev)
        self.assertEqual(method, 'index_html')
        self.assertEqual(path, ['resources'])

        catalog = root.service_catalog
        brains = catalog(meta_type='Silva Folder', path='/root/docs/admin')
        self.assertEqual(len(brains), 1)
        brain = brains[0]

        url = getMultiAdapter((brain, request), IContentURL)
        self.assertTrue(verifyObject(IContentURL, url))

        self.assertEqual(
            brain.getURL(),
            'http://localhost/admin')
        self.assertEqual(
            str(url),
            'http://localhost/admin')
        self.assertEqual(
            url.url(),
            'http://localhost/admin')
        self.assertEqual(
            url.url(relative=True),
            '/admin')
        self.assertEqual(
            url.url(relative=True, preview=True),
            '/admin')
        self.assertEqual(
            url.url(preview=True),
            'http://localhost/admin')
        self.assertEqual(
            url.preview(),
            'http://localhost/admin')

        # Get the URL of a different brain
        catalog = root.service_catalog
        brains = catalog(
            meta_type='Silva Folder',
            path='/root/docs/dev/resources')
        self.assertEqual(len(brains), 1)
        brain = brains[0]

        url = getMultiAdapter((brain, request), IContentURL)
        self.assertTrue(verifyObject(IContentURL, url))

        self.assertEqual(
            brain.getURL(),
            'http://localhost/hidden/docs/resources')
        self.assertEqual(
            str(url),
            'http://localhost/hidden/docs/resources')
        self.assertEqual(
            url.url(),
            'http://localhost/hidden/docs/resources')
        self.assertEqual(
            url.url(relative=True),
            '/hidden/docs/resources')
        self.assertEqual(
            url.url(relative=True, preview=True),
            '/hidden/docs/resources')
        self.assertEqual(
            url.url(preview=True),
            'http://localhost/hidden/docs/resources')
        self.assertEqual(
            url.preview(),
            'http://localhost/hidden/docs/resources')

        # Get the URL of a different brain
        catalog = root.service_catalog
        brains = catalog(
            meta_type='Silva Publication',
            path='/root/docs')
        self.assertEqual(len(brains), 1)
        brain = brains[0]

        url = getMultiAdapter((brain, request), IContentURL)
        self.assertTrue(verifyObject(IContentURL, url))

        self.assertEqual(
            brain.getURL(),
            'http://localhost/docs')
        self.assertEqual(
            str(url),
            'http://localhost/docs')
        self.assertEqual(
            url.url(),
            'http://localhost/docs')
        self.assertEqual(
            url.url(relative=True),
            '/docs')
        self.assertEqual(
            url.url(relative=True, preview=True),
            '/docs')
        self.assertEqual(
            url.url(preview=True),
            'http://localhost/docs')
        self.assertEqual(
            url.preview(),
            'http://localhost/docs')
    def test_frontend(self):
        request = TestRequest(
            application=self.root,
            url='http://localhost',
            headers=[('X-VHM-Url', 'http://localhost')])
        plugin = request.query_plugin(request.application, IVirtualHosting)
        root, method, path = plugin(request.method, request.path)
        self.assertEqual(root, self.root.docs.admin)
        self.assertEqual(method, 'index_html')
        self.assertEqual(path, [])

        url = getMultiAdapter((self.root.docs.admin, request), IContentURL)
        self.assertTrue(verifyObject(IContentURL, url))

        self.assertEqual(
            str(url),
            'http://localhost')
        self.assertEqual(
            url.url(),
            'http://localhost')
        self.assertEqual(
            url.url(relative=True),
            '/')
        self.assertEqual(
            url.url(relative=True, preview=True),
            '/++preview++')
        self.assertEqual(
            url.url(preview=True),
            'http://localhost/++preview++')
        self.assertEqual(
            url.preview(),
            'http://localhost/++preview++')

        url = getMultiAdapter((self.root.docs, request), IContentURL)
        self.assertTrue(verifyObject(IContentURL, url))

        self.assertEqual(
            str(url),
            'http://localhost/manual')
        self.assertEqual(
            url.url(),
            'http://localhost/manual')
        self.assertEqual(
            url.url(relative=True),
            '/manual')
        self.assertEqual(
            url.url(relative=True, preview=True),
            '/manual/++preview++')
        self.assertEqual(
            url.url(preview=True),
            'http://localhost/manual/++preview++')
        self.assertEqual(
            url.url(preview=True, host='http://frontend.localhost'),
            'http://frontend.localhost/manual/++preview++')
        self.assertEqual(
            url.url(preview=True, host='http://admin.localhost'),
            'http://admin.localhost/++preview++/docs')
        self.assertEqual(
            url.preview(),
            'http://localhost/manual/++preview++')

        url = getMultiAdapter((self.root, request), IContentURL)
        self.assertTrue(verifyObject(IContentURL, url))

        self.assertEqual(
            str(url),
            'http://localhost/info')
        self.assertEqual(
            url.url(),
            'http://localhost/info')
        self.assertEqual(
            url.url(relative=True),
            '/info')
        self.assertEqual(
            url.url(relative=True, preview=True),
            '/info/++preview++')
        self.assertEqual(
            url.url(preview=True),
            'http://localhost/info/++preview++')
        self.assertEqual(
            url.preview(),
            'http://localhost/info/++preview++')