コード例 #1
0
ファイル: test_file.py プロジェクト: silvacms/Products.Silva
    def test_modify_file(self):
        """Test uploading a file with a new one. The new content type
        and content encoding should have been detected.
        """
        content = self.create_test_file()
        self.assertTrue(verifyObject(interfaces.IAsset, content))
        self.assertTrue(verifyObject(interfaces.IFile, content))

        # We have an image.
        self.assertEqual(content.get_content_type(), 'image/tiff')
        self.assertEqual(content.get_content_encoding(), None)
        self.assertEqual(content.get_filename(), 'photo.tif')
        self.assertEqual(content.get_mime_type(), 'image/tiff')

        # Now we upload a text file.
        with self.layer.open_fixture('test_document.xml') as stream:
            with tests.assertTriggersEvents('ObjectModifiedEvent'):
                content.set_file(stream)

        # We didn't specify any content_type of encoding, they should
        # have been detected.
        self.assertEqual(content.get_content_type(), 'application/xml')
        self.assertEqual(content.get_content_encoding(), None)
        self.assertEqual(content.get_filename(), 'photo.xml')
        self.assertEqual(content.get_mime_type(), 'application/xml')
コード例 #2
0
ファイル: test_file.py プロジェクト: silvacms/Products.Silva
    def test_modify_file_and_content_type(self):
        """Test uploading a file with a new one. The content type
        given as option should be used, and no content type or content
        encoding should be detected.
        """
        content = self.create_test_file()
        self.assertTrue(verifyObject(interfaces.IAsset, content))
        self.assertTrue(verifyObject(interfaces.IFile, content))

        # We have an image.
        self.assertEqual(content.get_content_type(), 'image/tiff')
        self.assertEqual(content.get_content_encoding(), None)
        self.assertEqual(content.get_filename(), 'photo.tif')
        self.assertEqual(content.get_mime_type(), 'image/tiff')

        # Now we upload a text file.
        with self.layer.open_fixture('test_document.xml') as stream:
            with tests.assertTriggersEvents('ObjectModifiedEvent'):
                content.set_file(stream, content_type='text/html')

        # We have the new content_type and content encoding, even if
        # they don't match the file
        self.assertEqual(content.get_content_type(), 'text/html')
        self.assertEqual(content.get_content_encoding(), None)
        self.assertEqual(content.get_filename(), 'photo.html')
        self.assertEqual(content.get_mime_type(), 'text/html')
コード例 #3
0
    def test_publication(self):
        """Verify a news publication publication and its default
        metadata and contents.
        """
        with Transaction():
            factory = self.root.manage_addProduct['silva.app.news']
            with tests.assertTriggersEvents('ContentCreatedEvent'):
                factory.manage_addNewsPublication('news', 'News')

        publication = self.root._getOb('news', None)
        self.assertTrue(verifyObject(INewsPublication, publication))

        # Default settings
        get_metadata = getUtility(IMetadataService).getMetadataValue
        self.assertEqual(
            get_metadata(publication, 'silva-settings', 'hide_from_tocs'),
            'hide')
        self.assertEqual(
            get_metadata(publication, 'snn-np-settings', 'is_private'),
            'no')

        # Default content
        self.assertNotEqual(publication.get_creation_datetime(), None)
        self.assertNotEqual(publication.get_modification_datetime(), None)
        self.assertItemsEqual(publication.objectIds(), ['index', 'filter'])
        self.assertTrue(verifyObject(INewsViewer, publication.index))
        self.assertTrue(verifyObject(INewsFilter, publication.filter))
コード例 #4
0
ファイル: test_file.py プロジェクト: silvacms/Products.Silva
    def test_modify_text(self):
        """Test changing the text of a text editable file.
        """
        content = self.create_test_file('test_file_text.txt')
        self.assertTrue(verifyObject(interfaces.IAsset, content))
        self.assertTrue(verifyObject(interfaces.IFile, content))

        self.assertEqual(content.get_content_type(), 'text/plain; charset=utf-8')
        self.assertEqual(content.get_content_encoding(), None)
        self.assertEqual(content.get_file_size(), self.file_size)
        self.assertEqual(content.get_filename(), 'test_file_text.txt')
        self.assertEqual(content.get_mime_type(), 'text/plain')

        # You can edit text
        self.assertEqual(content.is_text(), True)
        self.assertEqual(content.is_text_editable(), True)

        # You can change the text of a text file.
        with tests.assertTriggersEvents('ObjectModifiedEvent'):
            content.set_text("This is the story of a kind")

        self.assertEqual(content.get_file_size(), 27)
        self.assertEqual(content.get_filename(), 'test_file_text.txt')
        self.assertEqual(content.get_content_type(), 'text/plain; charset=utf-8')
        self.assertEqual(content.get_content_encoding(), None)
        self.assertEqual(content.get_mime_type(), 'text/plain')
        self.assertEqual(content.is_text(), True)
        self.assertEqual(content.is_text_editable(), True)
コード例 #5
0
ファイル: test_file.py プロジェクト: silvacms/Products.Silva
    def test_modify_file_and_content_type(self):
        """Test uploading a file with a new one. The content type
        given as option should be used, and no content type or content
        encoding should be detected.
        """
        content = self.create_test_file()
        self.assertTrue(verifyObject(interfaces.IAsset, content))
        self.assertTrue(verifyObject(interfaces.IFile, content))

        # We have an image.
        self.assertEqual(content.get_content_type(), 'image/tiff')
        self.assertEqual(content.get_content_encoding(), None)
        self.assertEqual(content.get_filename(), 'photo.tif')
        self.assertEqual(content.get_mime_type(), 'image/tiff')

        # Now we upload a text file.
        with self.layer.open_fixture('test_document.xml') as stream:
            with tests.assertTriggersEvents('ObjectModifiedEvent'):
                content.set_file(stream, content_type='text/html')

        # We have the new content_type and content encoding, even if
        # they don't match the file
        self.assertEqual(content.get_content_type(), 'text/html')
        self.assertEqual(content.get_content_encoding(), None)
        self.assertEqual(content.get_filename(), 'photo.html')
        self.assertEqual(content.get_mime_type(), 'text/html')
コード例 #6
0
ファイル: test_file.py プロジェクト: silvacms/Products.Silva
    def test_modify_file(self):
        """Test uploading a file with a new one. The new content type
        and content encoding should have been detected.
        """
        content = self.create_test_file()
        self.assertTrue(verifyObject(interfaces.IAsset, content))
        self.assertTrue(verifyObject(interfaces.IFile, content))

        # We have an image.
        self.assertEqual(content.get_content_type(), 'image/tiff')
        self.assertEqual(content.get_content_encoding(), None)
        self.assertEqual(content.get_filename(), 'photo.tif')
        self.assertEqual(content.get_mime_type(), 'image/tiff')

        # Now we upload a text file.
        with self.layer.open_fixture('test_document.xml') as stream:
            with tests.assertTriggersEvents('ObjectModifiedEvent'):
                content.set_file(stream)

        # We didn't specify any content_type of encoding, they should
        # have been detected.
        self.assertEqual(content.get_content_type(), 'application/xml')
        self.assertEqual(content.get_content_encoding(), None)
        self.assertEqual(content.get_filename(), 'photo.xml')
        self.assertEqual(content.get_mime_type(), 'application/xml')
コード例 #7
0
ファイル: test_file.py プロジェクト: silvacms/Products.Silva
    def test_modify_text(self):
        """Test changing the text of a text editable file.
        """
        content = self.create_test_file('test_file_text.txt')
        self.assertTrue(verifyObject(interfaces.IAsset, content))
        self.assertTrue(verifyObject(interfaces.IFile, content))

        self.assertEqual(content.get_content_type(),
                         'text/plain; charset=utf-8')
        self.assertEqual(content.get_content_encoding(), None)
        self.assertEqual(content.get_file_size(), self.file_size)
        self.assertEqual(content.get_filename(), 'test_file_text.txt')
        self.assertEqual(content.get_mime_type(), 'text/plain')

        # You can edit text
        self.assertEqual(content.is_text(), True)
        self.assertEqual(content.is_text_editable(), True)

        # You can change the text of a text file.
        with tests.assertTriggersEvents('ObjectModifiedEvent'):
            content.set_text("This is the story of a kind")

        self.assertEqual(content.get_file_size(), 27)
        self.assertEqual(content.get_filename(), 'test_file_text.txt')
        self.assertEqual(content.get_content_type(),
                         'text/plain; charset=utf-8')
        self.assertEqual(content.get_content_encoding(), None)
        self.assertEqual(content.get_mime_type(), 'text/plain')
        self.assertEqual(content.is_text(), True)
        self.assertEqual(content.is_text_editable(), True)
コード例 #8
0
 def test_item(self):
     factory = self.root.manage_addProduct['silva.app.news']
     with tests.assertTriggersEvents('ContentCreatedEvent'):
         factory.manage_addNewsItem('item', 'News Item')
     item = self.root._getOb('item', None)
     self.assertTrue(verifyObject(INewsItem, item))
     version = item.get_editable()
     self.assertTrue(verifyObject(INewsItemVersion, version))
コード例 #9
0
ファイル: test_file.py プロジェクト: silvacms/Products.Silva
 def create_test_file(self, filename='photo.tif'):
     with Transaction():
         with self.layer.open_fixture(filename) as stream:
             self.file_data = stream.read()
             self.file_size = stream.tell()
             stream.seek(0)
             with tests.assertTriggersEvents(
                 'ObjectWillBeAddedEvent', 'ObjectAddedEvent',
                 'ContainerModifiedEvent', 'ObjectCreatedEvent'):
                 factory = self.root.manage_addProduct['Silva']
                 factory.manage_addFile(filename, 'Test File', stream)
     content =  self.root._getOb(filename)
     metadata = getUtility(IMetadataService).getMetadata(content)
     metadata.setValues('silva-extra', {
             'modificationtime': DateTime('2010-04-25T12:00:00Z')})
     return content
コード例 #10
0
    def test_item(self):
        factory = self.root.manage_addProduct['silva.app.news']
        with tests.assertTriggersEvents('ContentCreatedEvent'):
            factory.manage_addAgendaItem('event', 'Testing event')
        event = self.root._getOb('event', None)
        self.assertTrue(verifyObject(IAgendaItem, event))
        version = event.get_editable()
        self.assertTrue(verifyObject(IAgendaItemVersion, version))
        version.set_subjects(['invalid', 'other', 'root'])
        self.assertEqual(version.get_subjects(), set(['root']))
        version.set_target_audiences(['generic', 'root'])
        self.assertEqual(version.get_target_audiences(), set(['root']))

        service = getUtility(IServiceNews)
        service.add_subject('other', 'Other')
        service.add_target_audience('generic', 'Generic')
        self.assertEqual(version.get_subjects(), set(['other', 'root']))
        self.assertEqual(version.get_target_audiences(), set(['generic', 'root']))
コード例 #11
0
ファイル: test_file.py プロジェクト: silvacms/Products.Silva
 def create_test_file(self, filename='photo.tif'):
     with Transaction():
         with self.layer.open_fixture(filename) as stream:
             self.file_data = stream.read()
             self.file_size = stream.tell()
             stream.seek(0)
             with tests.assertTriggersEvents('ObjectWillBeAddedEvent',
                                             'ObjectAddedEvent',
                                             'ContainerModifiedEvent',
                                             'ObjectCreatedEvent'):
                 factory = self.root.manage_addProduct['Silva']
                 factory.manage_addFile(filename, 'Test File', stream)
     content = self.root._getOb(filename)
     metadata = getUtility(IMetadataService).getMetadata(content)
     metadata.setValues(
         'silva-extra',
         {'modificationtime': DateTime('2010-04-25T12:00:00Z')})
     return content
コード例 #12
0
    def test_source(self):
        """Simply add and verify a CSV Source.
        """
        source = self.root._getOb('csv_data', None)
        self.assertNotEqual(source, None)
        self.assertTrue(verifyObject(ICSVSource, source))
        self.assertTrue(ICSVSource.extends(IExternalSource))
        self.assertItemsEqual(source.objectIds(), ['layout'])
        self.assertEqual(source.is_previewable(), True)
        self.assertEqual(source.is_usable(), True)
        self.assertEqual(source.get_file_size(), 0)
        self.assertEqual(source.get_filename(), 'csv_data.csv')
        self.assertEqual(source.get_mime_type(), 'text/csv')

        with self.layer.open_fixture('informations.csv') as data:
            with tests.assertTriggersEvents('ObjectModifiedEvent'):
                source.set_file(data)

        self.assertEqual(source.get_file_size(), 281)
        self.assertEqual(source.get_filename(), 'csv_data.csv')
        self.assertEqual(source.get_mime_type(), 'text/csv')
コード例 #13
0
    def test_source(self):
        """Simply add and verify a CSV Source.
        """
        source = self.root._getOb("csv_data", None)
        self.assertNotEqual(source, None)
        self.assertTrue(verifyObject(ICSVSource, source))
        self.assertTrue(ICSVSource.extends(IExternalSource))
        self.assertItemsEqual(source.objectIds(), ["layout"])
        self.assertEqual(source.is_previewable(), True)
        self.assertEqual(source.is_usable(), True)
        self.assertEqual(source.get_file_size(), 0)
        self.assertEqual(source.get_filename(), "csv_data.csv")
        self.assertEqual(source.get_mime_type(), "text/csv")

        with self.layer.open_fixture("informations.csv") as data:
            with tests.assertTriggersEvents("ObjectModifiedEvent"):
                source.set_file(data)

        self.assertEqual(source.get_file_size(), 281)
        self.assertEqual(source.get_filename(), "csv_data.csv")
        self.assertEqual(source.get_mime_type(), "text/csv")
コード例 #14
0
 def test_filter(self):
     factory = self.root.manage_addProduct['silva.app.news']
     with tests.assertTriggersEvents('ContentCreatedEvent'):
         factory.manage_addNewsFilter('filter', 'News Filter')
     nfilter = self.root._getOb('filter', None)
     self.assertTrue(verifyObject(INewsFilter, nfilter))
コード例 #15
0
 def test_viewer(self):
     factory = self.root.manage_addProduct["silva.app.news"]
     with tests.assertTriggersEvents("ContentCreatedEvent"):
         factory.manage_addNewsViewer("viewer", "News Viewer")
     viewer = self.root._getOb("viewer", None)
     self.assertTrue(verifyObject(INewsViewer, viewer))
コード例 #16
0
 def test_viewer(self):
     factory = self.root.manage_addProduct['silva.app.news']
     with tests.assertTriggersEvents('ContentCreatedEvent'):
         factory.manage_addAgendaViewer('viewer', 'Agenda Viewer')
     viewer = self.root._getOb('viewer', None)
     self.assertTrue(verifyObject(IAgendaViewer, viewer))