Пример #1
0
    def test_writefile_file_operations(self):

        class ITest(Interface):
            title = schema.TextLine()
            body = schema.Text()
        alsoProvides(ITest['body'], IPrimaryField)

        fti_mock = self.mocker.proxy(DexterityFTI(u'testtype'))
        self.expect(fti_mock.lookupSchema()).result(ITest).count(0, None)
        self.expect(
            fti_mock.behaviors
        ).result([ITestBehavior.__identifier__]).count(0, None)

        self.mock_utility(fti_mock, IDexterityFTI, name=u"testtype")

        item = Item('item')
        item.portal_type = 'testtype'
        item.title = u"Test title"
        item.foo = 10
        item.bar = 'xyz'
        item.body = u"<p>body</p>"

        writefile = DefaultWriteFile(item)

        body = """\
title: Test title
foo: 10
bar: xyz
Portal-Type: testtype

<p>body</p>"""

        initializeObjectFromSchemata_mock = self.mocker.replace(
            'plone.rfc822.initializeObjectFromSchemata'
        )
        self.expect(
            initializeObjectFromSchemata_mock(
                item,
                ANY,
                self.match_type(Message),
                'latin1'
            )
        )

        self.replay()

        writefile.mimeType = 'text/plain'
        self.assertEqual('text/plain', writefile.mimeType)

        writefile.encoding = 'latin1'
        self.assertEqual('latin1', writefile.encoding)

        writefile.filename = 'test.html'
        self.assertEqual('test.html', writefile.filename)

        self.assertEqual(False, writefile.closed)
        self.assertEqual(0, writefile.tell())

        writefile.writelines(['one\n', 'two'])
        self.assertEqual(7, writefile.tell())

        self.assertRaises(NotImplementedError, writefile.truncate)

        writefile.truncate(0)
        self.assertEqual(0, writefile.tell())

        self.assertRaises(NotImplementedError, writefile.seek, 10)

        writefile.write(body[:10])
        writefile.write(body[10:])
        writefile.close()

        self.assertEqual(True, writefile.closed)
        self.assertEqual(69, writefile.tell())
Пример #2
0
    def test_writefile_file_operations(self):
        class ITest(Interface):
            title = schema.TextLine()
            body = schema.Text()

        alsoProvides(ITest['body'], IPrimaryField)

        fti_mock = self.mocker.proxy(DexterityFTI(u'testtype'))
        self.expect(fti_mock.lookupSchema()).result(ITest).count(0, None)
        self.expect(fti_mock.behaviors).result([ITestBehavior.__identifier__
                                                ]).count(0, None)

        self.mock_utility(fti_mock, IDexterityFTI, name=u"testtype")

        item = Item('item')
        item.portal_type = 'testtype'
        item.title = u"Test title"
        item.foo = 10
        item.bar = 'xyz'
        item.body = u"<p>body</p>"

        writefile = DefaultWriteFile(item)

        body = """\
title: Test title
foo: 10
bar: xyz
Portal-Type: testtype

<p>body</p>"""

        initializeObjectFromSchemata_mock = self.mocker.replace(
            'plone.rfc822.initializeObjectFromSchemata')
        self.expect(
            initializeObjectFromSchemata_mock(item, ANY,
                                              self.match_type(Message),
                                              'latin1'))

        self.replay()

        writefile.mimeType = 'text/plain'
        self.assertEqual('text/plain', writefile.mimeType)

        writefile.encoding = 'latin1'
        self.assertEqual('latin1', writefile.encoding)

        writefile.filename = 'test.html'
        self.assertEqual('test.html', writefile.filename)

        self.assertEqual(False, writefile.closed)
        self.assertEqual(0, writefile.tell())

        writefile.writelines(['one\n', 'two'])
        self.assertEqual(7, writefile.tell())

        self.assertRaises(NotImplementedError, writefile.truncate)

        writefile.truncate(0)
        self.assertEqual(0, writefile.tell())

        self.assertRaises(NotImplementedError, writefile.seek, 10)

        writefile.write(body[:10])
        writefile.write(body[10:])
        writefile.close()

        self.assertEqual(True, writefile.closed)
        self.assertEqual(69, writefile.tell())
Пример #3
0
    def test_writefile_file_operations(self):

        class ITest(Interface):
            title = schema.TextLine()
            body = schema.Text()
        alsoProvides(ITest['body'], IPrimaryField)

        fti_mock = DexterityFTI(u'testtype')
        fti_mock.lookupSchema = Mock(return_value=ITest)
        fti_mock.behaviors = [ITestBehavior.__identifier__]

        self.mock_utility(fti_mock, IDexterityFTI, name=u"testtype")

        item = Item('item')
        item.portal_type = 'testtype'
        item.title = u"Test title"
        item.foo = 10
        item.bar = 'xyz'
        item.body = u"<p>body</p>"

        writefile = DefaultWriteFile(item)

        body = """\
title: Test title
foo: 10
bar: xyz
Portal-Type: testtype

<p>body</p>"""

        from plone.rfc822 import initializeObjectFromSchemata
        self.patch_global(initializeObjectFromSchemata)

        writefile.mimeType = 'text/plain'
        self.assertEqual('text/plain', writefile.mimeType)

        writefile.encoding = 'latin1'
        self.assertEqual('latin1', writefile.encoding)

        writefile.filename = 'test.html'
        self.assertEqual('test.html', writefile.filename)

        self.assertEqual(False, writefile.closed)
        self.assertEqual(0, writefile.tell())

        writefile.writelines(['one\n', 'two'])
        self.assertEqual(7, writefile.tell())

        self.assertRaises(NotImplementedError, writefile.truncate)

        writefile.truncate(0)
        self.assertEqual(0, writefile.tell())

        self.assertRaises(NotImplementedError, writefile.seek, 10)

        writefile.write(body[:10])
        writefile.write(body[10:])
        writefile.close()

        self.assertEqual(True, writefile.closed)
        self.assertEqual(69, writefile.tell())
Пример #4
0
    def test_writefile_file_operations(self):
        class ITest(Interface):
            title = schema.TextLine()
            body = schema.Text()

        alsoProvides(ITest['body'], IPrimaryField)

        fti_mock = DexterityFTI(u'testtype')
        fti_mock.lookupSchema = Mock(return_value=ITest)
        fti_mock.behaviors = [ITestBehavior.__identifier__]

        self.mock_utility(fti_mock, IDexterityFTI, name=u"testtype")

        item = Item('item')
        item.portal_type = 'testtype'
        item.title = u"Test title"
        item.foo = 10
        item.bar = 'xyz'
        item.body = u"<p>body</p>"

        writefile = DefaultWriteFile(item)

        body = """\
title: Test title
foo: 10
bar: xyz
Portal-Type: testtype

<p>body</p>"""

        from plone.rfc822 import initializeObjectFromSchemata
        self.patch_global(initializeObjectFromSchemata)

        writefile.mimeType = 'text/plain'
        self.assertEqual('text/plain', writefile.mimeType)

        writefile.encoding = 'latin1'
        self.assertEqual('latin1', writefile.encoding)

        writefile.filename = 'test.html'
        self.assertEqual('test.html', writefile.filename)

        self.assertEqual(False, writefile.closed)
        self.assertEqual(0, writefile.tell())

        writefile.writelines(['one\n', 'two'])
        self.assertEqual(7, writefile.tell())

        self.assertRaises(NotImplementedError, writefile.truncate)

        writefile.truncate(0)
        self.assertEqual(0, writefile.tell())

        self.assertRaises(NotImplementedError, writefile.seek, 10)

        writefile.write(body[:10])
        writefile.write(body[10:])
        writefile.close()

        self.assertEqual(True, writefile.closed)
        self.assertEqual(69, writefile.tell())