testOOoBatchMode.py 6.91 KB
Newer Older
1
# -*- coding: utf-8 -*-
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
##############################################################################
#
# Copyright (c) 2004, 2005, 2006 Nexedi SARL and Contributors. 
# All Rights Reserved.
##
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################

import os
31
import unittest
32 33 34 35 36 37 38 39 40 41 42 43 44 45
from AccessControl.SecurityManagement import newSecurityManager
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5.Document.Document import ConversionError

class TestOoodResponse(ERP5TypeTestCase):

  manager_username = 'rie'
  manager_password = 'rie'
  quiet = 1
  run_all_test = 1  

  def getTitle(self):
    return "TestOOoBatchMode"

46
  def login(self):
47 48 49 50 51 52
    uf = self.getPortal().acl_users
    uf._doAddUser(self.manager_username, self.manager_password, ['Manager'], [])
    user = uf.getUserById(self.manager_username).__of__(uf)
    newSecurityManager(None, user)

  def getBusinessTemplateList(self):
53
    return ('erp5_base',)
54 55 56 57

  def afterSetUp(self):
    self.login()
    portal_skins = self.getSkinsTool()
58
    import_file_path = os.path.join(os.path.dirname(__file__),
59
                                    'test_document',
60 61
                                    'REF-en-001.odt')# Any text document will
                                                     # feet our needs
62
    import_file = open(import_file_path, 'rb')
63 64 65 66 67
    custom = portal_skins.custom
    addStyleSheet = custom.manage_addProduct['OFSP'].manage_addFile
    addStyleSheet(id='Base_getODTStyleSheet', file=import_file, title='',
      precondition='', content_type='application/vnd.oasis.opendocument.text')
    addOOoTemplate = custom.manage_addProduct['ERP5OOo'].addOOoTemplate
68 69 70 71
    addOOoTemplate(id='ERP5Site_viewNothingAsOdt', title='')
    portal_skins.changeSkin(skinname=None)
    ERP5Site_viewNothingAsOdt = self.getPortal().ERP5Site_viewNothingAsOdt
    text = "<office:document-content xmlns:draw='urn:oasis:names:tc:opendocument:xmlns:drawing:1.0' xmlns:office='urn:oasis:names:tc:opendocument:xmlns:office:1.0' xmlns:text='urn:oasis:names:tc:opendocument:xmlns:text:1.0' xmlns:ooo='http://openoffice.org/2004/office' xmlns:number='urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:meta='urn:oasis:names:tc:opendocument:xmlns:meta:1.0' xmlns:table='urn:oasis:names:tc:opendocument:xmlns:table:1.0' xmlns:dr3d='urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0' xmlns:fo='urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0' xmlns:style='urn:oasis:names:tc:opendocument:xmlns:style:1.0' xmlns:xforms='http://www.w3.org/2002/xforms' xmlns:form='urn:oasis:names:tc:opendocument:xmlns:form:1.0' xmlns:script='urn:oasis:names:tc:opendocument:xmlns:script:1.0' xmlns:ooow='http://openoffice.org/2004/writer' xmlns:svg='urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0' xmlns:chart='urn:oasis:names:tc:opendocument:xmlns:chart:1.0' xmlns:dom='http://www.w3.org/2001/xml-events' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:oooc='http://openoffice.org/2004/calc' xmlns:math='http://www.w3.org/1998/Math/MathML'  xmlns:tal='http://xml.zope.org/namespaces/tal'></office:document-content>"
72
    content_type = 'text/xml'
73 74 75
    ERP5Site_viewNothingAsOdt.pt_edit(text, content_type)

  def test_01_noExcNoFormatNoBatchMode(self):
76 77
    request = self.portal.REQUEST
    request.RESPONSE.setHeader('content-type', 'text/html')
78 79
    ERP5Site_viewNothingAsOdt = self.getPortal().ERP5Site_viewNothingAsOdt
    ERP5Site_viewNothingAsOdt(batch_mode=0)
80 81
    self.assertEqual('application/vnd.oasis.opendocument.text',
        request.RESPONSE.getHeader('content-type').split(';')[0])
82
    self.assertEqual('attachment; filename="ERP5Site_viewNothingAsOdt.odt"',
83
        request.RESPONSE.getHeader('content-disposition'))
84 85 86 87 88 89 90 91

  def test_01b_noExcEmptyFormatNoBatchMode(self):
    request = self.portal.REQUEST
    request.RESPONSE.setHeader('content-type', 'text/html')
    ERP5Site_viewNothingAsOdt = self.getPortal().ERP5Site_viewNothingAsOdt
    ERP5Site_viewNothingAsOdt(format='', batch_mode=0)
    self.assertEqual('application/vnd.oasis.opendocument.text',
        request.RESPONSE.getHeader('content-type').split(';')[0])
92
    self.assertEqual('attachment; filename="ERP5Site_viewNothingAsOdt.odt"',
93
        request.RESPONSE.getHeader('content-disposition'))
94 95
    
  def test_02_noExcNoFormatBatchMode(self):
96 97
    request = self.portal.REQUEST
    request.RESPONSE.setHeader('content-type', 'text/html')
98 99
    ERP5Site_viewNothingAsOdt = self.getPortal().ERP5Site_viewNothingAsOdt
    ERP5Site_viewNothingAsOdt(batch_mode=1)
100 101
    self.assertEqual('text/html',
        request.RESPONSE.getHeader('content-type').split(';')[0])
102 103
    
  def test_03_excPdfFormatNoBatchMode(self):
104 105
    request = self.portal.REQUEST
    request.RESPONSE.setHeader('content-type', 'text/html')
106
    ERP5Site_viewNothingAsOdt = self.getPortal().ERP5Site_viewNothingAsOdt
107 108
    # This assumes that a conversion error is raised because oood coordinates
    # are not defined in preferences.
109 110 111 112
    self.assertRaises(ConversionError, ERP5Site_viewNothingAsOdt,
                      batch_mode=0, format='pdf')
    self.assertEqual('text/html',
        request.RESPONSE.getHeader('content-type').split(';')[0])
113 114

  def test_04_excPdfFormatBatchMode(self):
115 116
    request = self.portal.REQUEST
    request.RESPONSE.setHeader('content-type', 'text/html')
117
    ERP5Site_viewNothingAsOdt = self.getPortal().ERP5Site_viewNothingAsOdt
118 119
    # This assumes that a conversion error is raised because oood coordinates
    # are not defined in preferences.
120 121 122
    self.assertRaises(ConversionError, ERP5Site_viewNothingAsOdt,
                         batch_mode=1, format='pdf')
    self.assertEqual('text/html', request.RESPONSE.getHeader('content-type').split(';')[0])
123

124 125 126 127
def test_suite():
  suite = unittest.TestSuite()
  suite.addTest(unittest.makeSuite(TestOoodResponse))
  return suite
128