# -*- coding: utf-8 -*- import os, sys, re from os.path import join if __name__ == '__main__': execfile(os.path.join(sys.path[0], 'framework.py')) from Testing import ZopeTestCase import unittest from Products.Silva.tests import SilvaTestCase from Products.SilvaDocument.Document import manage_addDocument from Products.Silva.Ghost import manage_addGhost from Products.Silva.GhostFolder import manage_addGhostFolder from Products.Silva.silvaxml import xmlexport from Products.Silva.Link import manage_addLink from Products.ParsedXML.ParsedXML import ParsedXML from DateTime import DateTime def testopen(path, rw): directory = os.path.dirname(__file__) return open(os.path.join(directory, path), rw) class SetTestCase(SilvaTestCase.SilvaTestCase): def test_xml_document_export(self): testfolder = self.add_folder( self.root, 'testfolder', 'This is a testfolder', policy_name='Auto TOC') manage_addDocument( testfolder, 'test_document', 'This is (surprise!) a document') doc = testfolder.test_document doc_edit = doc.get_editable() doc_edit.content = ParsedXML( 'test_document', """ 承諾広告*既に、2億、3億、5億9千万円収入者が続出boo baz""") xmlexport.initializeXMLExportRegistry() # We will now do some horrible, horrible stuff to be able to test # the export, while ignoring the export date, which we can't know # about beforehand. Also I don't see how to get this within 80 # columns without a lot of pain. splittor = re.compile('[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z') settings = xmlexport.ExportSettings() exporter = xmlexport.theXMLExporter exportRoot = xmlexport.SilvaExportRoot(testfolder) part1, part2, part3, part4, part5, part6, part7, part8 = splittor.split(exporter.exportToString(exportRoot, settings)) self.assertEquals(part1, '\nThis is <boo>a</boo> testfolder' % exportRoot.getSilvaProductVersion()) self.assertEquals(part3, 'test_user_1_n/ahttp://nohost/root/testfolder') self.assertEquals(part4, 'This is <boo>a</boo> testfolder') self.assertEquals(part5, 'test_user_1_test_user_1_http://nohost/root/testfolder/index') self.assertEquals(part6, 'unapprovedThis is (surprise!) a document') self.assertEquals(part7, 'test_user_1_unknown userhttp://nohost/root/testfolder/test_document') self.assertEquals(part8, '\n \xe6\x89\xbf\xe8\xab\xbe\xe5\xba\x83\xe5\x91\x8a\xef\xbc\x8a\xe6\x97\xa2\xe3\x81\xab\xe3\x80\x81\xef\xbc\x92\xe5\x84\x84\xe3\x80\x81\xef\xbc\x93\xe5\x84\x84\xe3\x80\x81\xef\xbc\x95\xe5\x84\x84\xef\xbc\x99\xe5\x8d\x83\xe4\xb8\x87\xe5\x86\x86\xe5\x8f\x8e\xe5\x85\xa5\xe8\x80\x85\xe3\x81\x8c\xe7\xb6\x9a\xe5\x87\xbaboo\n baz') def test_xml_document_with_source_export(self): try: self.installExtension('SilvaExternalSources') except: return testfolder = self.add_folder( self.root, 'testfolder', 'This is a testfolder', policy_name='Auto TOC') source_file = testopen('data/test_csv.csv', 'r') testfolder.manage_addProduct[ 'SilvaExternalSources'].manage_addCSVSource( 'csv', 'A CSV Source', source_file ) manage_addDocument( testfolder, 'test_document', 'This is (surprise!) a document') doc = testfolder.test_document doc_edit = doc.get_editable() doc_edit.content = ParsedXML( 'test_document', """ grid 2 Shakespeare Global Theatre

This is the text of the citation. Only this text appears in the editing area, however the author and/or source will be shown in the preview and published version of the document.

""") BatchStart = {'b_start':2} Request = testfolder.csv.REQUEST Request.form.update(BatchStart) xmlexport.initializeXMLExportRegistry() settings = xmlexport.ExportSettings() settings.setExternalRendering(True) exporter = xmlexport.theXMLExporter exportRoot = xmlexport.SilvaExportRoot(testfolder) xml1, xml2 = exporter.exportToString(exportRoot, settings).split('') xml_expected = '\ngrid2
\n \n
\n\n \n \n \xc2\xab\n Previous\n 2 \n items\n \n\n\n \n \n\n \n \n \n \n 1\n \n\n \n \n [2]\n \n \n \n\n \n \n \n \n \n \n \n
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
h1h2h3h4h5h6
r3-1r3-2r3-3r3-4r3-5r3-6
r4-1r4-2r4-3r4-4r4-5r4-6
\n
\n
\n\nShakespeare\nGlobalTheatre\nThisisthetextofthecitation.Onlythis\ntextappearsintheeditingarea,howevertheauthorand/or\nsourcewillbeshowninthepreviewandpublishedversionofthe\ndocument.\n\n
' self.assertEquals(xml_expected.replace(' ',''), xml2.replace(' ','')) if __name__ == '__main__': framework() else: import unittest def test_suite(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(SetTestCase)) return suite