def test_readfile_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' readfile = DefaultReadFile(item) message = Message() message['title'] = 'Test title' message['foo'] = '10' message['bar'] = 'xyz' message.set_payload('<p>body</p>') constructMessageFromSchemata_mock = self.mocker.replace( 'plone.rfc822.constructMessageFromSchemata' ) self.expect( constructMessageFromSchemata_mock(item, ANY) ).result(message) self.replay() body = """\ title: Test title foo: 10 bar: xyz Portal-Type: testtype <p>body</p>""" # iter # next self.assertEqual(body, readfile.read()) self.assertEqual(69L, readfile.size()) self.assertEqual('utf-8', readfile.encoding) self.assertEqual(None, readfile.name) self.assertEqual('text/plain', readfile.mimeType) readfile.seek(2) self.assertEqual(2, readfile.tell()) self.assertEqual('tl', readfile.read(2)) self.assertEqual(4, readfile.tell()) readfile.seek(0, 2) self.assertEqual(69, readfile.tell()) readfile.seek(0) self.assertEqual('foo: 10\n', readfile.readlines()[1]) readfile.seek(0) self.assertEqual('foo: 10\n', readfile.readlines(100)[1]) readfile.seek(0) self.assertEqual('title: Test title\n', readfile.readline()) readfile.seek(0) self.assertEqual('title: Test title\n', readfile.readline(100)) readfile.seek(0) self.assertEqual('foo: 10\n', list(iter(readfile))[1]) self.assertEqual(False, readfile.closed) readfile.close()
def test_readfile_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' readfile = DefaultReadFile(item) message = Message() message['title'] = 'Test title' message['foo'] = '10' message['bar'] = 'xyz' message.set_payload('<p>body</p>') from plone.rfc822 import constructMessageFromSchemata self.patch_global(constructMessageFromSchemata, return_value=message) body = b"""\ title: Test title foo: 10 bar: xyz Portal-Type: testtype <p>body</p>""" # iter # next self.assertEqual(body, readfile.read()) self.assertEqual(69, readfile.size()) self.assertEqual('utf-8', readfile.encoding) self.assertEqual(None, readfile.name) self.assertEqual('text/plain', readfile.mimeType) readfile.seek(2) self.assertEqual(2, readfile.tell()) self.assertEqual(b'tl', readfile.read(2)) self.assertEqual(4, readfile.tell()) readfile.seek(0, 2) self.assertEqual(69, readfile.tell()) readfile.seek(0) self.assertEqual(b'foo: 10\n', readfile.readlines()[1]) readfile.seek(0) self.assertEqual(b'foo: 10\n', readfile.readlines(100)[1]) readfile.seek(0) self.assertEqual(b'title: Test title\n', readfile.readline()) readfile.seek(0) self.assertEqual(b'title: Test title\n', readfile.readline(100)) readfile.seek(0) self.assertEqual(b'foo: 10\n', list(iter(readfile))[1]) self.assertEqual(False, readfile.closed) readfile.close()
def test_readfile_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' readfile = DefaultReadFile(item) message = Message() message['title'] = 'Test title' message['foo'] = '10' message['bar'] = 'xyz' message.set_payload('<p>body</p>') constructMessageFromSchemata_mock = self.mocker.replace( 'plone.rfc822.constructMessageFromSchemata') self.expect(constructMessageFromSchemata_mock(item, ANY)).result(message) self.replay() body = """\ title: Test title foo: 10 bar: xyz Portal-Type: testtype <p>body</p>""" # iter # next self.assertEqual(body, readfile.read()) self.assertEqual(69L, readfile.size()) self.assertEqual('utf-8', readfile.encoding) self.assertEqual(None, readfile.name) self.assertEqual('text/plain', readfile.mimeType) readfile.seek(2) self.assertEqual(2, readfile.tell()) self.assertEqual('tl', readfile.read(2)) self.assertEqual(4, readfile.tell()) readfile.seek(0, 2) self.assertEqual(69, readfile.tell()) readfile.seek(0) self.assertEqual('foo: 10\n', readfile.readlines()[1]) readfile.seek(0) self.assertEqual('foo: 10\n', readfile.readlines(100)[1]) readfile.seek(0) self.assertEqual('title: Test title\n', readfile.readline()) readfile.seek(0) self.assertEqual('title: Test title\n', readfile.readline(100)) readfile.seek(0) self.assertEqual('foo: 10\n', list(iter(readfile))[1]) self.assertEqual(False, readfile.closed) readfile.close()
def test_readfile_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" readfile = DefaultReadFile(item) message = Message() message["title"] = "Test title" message["foo"] = "10" message["bar"] = "xyz" message.set_payload("<p>body</p>") constructMessageFromSchemata_mock = self.mocker.replace("plone.rfc822.constructMessageFromSchemata") self.expect(constructMessageFromSchemata_mock(item, ANY)).result(message) self.replay() body = """\ title: Test title foo: 10 bar: xyz Portal-Type: testtype <p>body</p>""" # iter # next self.assertEqual(body, readfile.read()) self.assertEqual(69L, readfile.size()) self.assertEqual("utf-8", readfile.encoding) self.assertEqual(None, readfile.name) self.assertEqual("text/plain", readfile.mimeType) readfile.seek(2) self.assertEqual(2, readfile.tell()) self.assertEqual("tl", readfile.read(2)) self.assertEqual(4, readfile.tell()) readfile.seek(0, 2) self.assertEqual(69, readfile.tell()) readfile.seek(0) self.assertEqual("foo: 10\n", readfile.readlines()[1]) readfile.seek(0) self.assertEqual("foo: 10\n", readfile.readlines(100)[1]) readfile.seek(0) self.assertEqual("title: Test title\n", readfile.readline()) readfile.seek(0) self.assertEqual("title: Test title\n", readfile.readline(100)) readfile.seek(0) self.assertEqual("foo: 10\n", list(iter(readfile))[1]) self.assertEqual(False, readfile.closed) readfile.close()