From 82cf9b8d41b251f3f00f460dd843274e59d10eac Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Tue, 19 Feb 2008 08:16:17 +0000
Subject: [PATCH] tests for encoding in ooo styles

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@19367 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5OOo/tests/testOOoStyle.py | 47 +++++++++++++++++++++++++--
 1 file changed, 45 insertions(+), 2 deletions(-)

diff --git a/product/ERP5OOo/tests/testOOoStyle.py b/product/ERP5OOo/tests/testOOoStyle.py
index 4ca77ea30d..8ba17f70dc 100644
--- a/product/ERP5OOo/tests/testOOoStyle.py
+++ b/product/ERP5OOo/tests/testOOoStyle.py
@@ -1,5 +1,5 @@
 ##############################################################################
-#
+# -*- coding: utf-8 -*-
 # Copyright (c) 2007 Nexedi SA and Contributors. All Rights Reserved.
 #          Jerome Perrin <jerome@nexedi.com>
 #
@@ -28,11 +28,14 @@
 
 import unittest
 from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
+from Products.ERP5Form.Selection import Selection
 from Testing import ZopeTestCase
 from Products.ERP5OOo.tests.utils import Validator
 
 HTTP_OK = 200
 
+# setting this to a true value allow the use of a debugger
+debug = 0
 
 class TestOOoStyle(ERP5TypeTestCase, ZopeTestCase.Functional):
   """Tests ODF styles for ERP5."""
@@ -52,11 +55,17 @@ class TestOOoStyle(ERP5TypeTestCase, ZopeTestCase.Functional):
       person_module.newContent(id='pers', portal_type='Person')
       get_transaction().commit()
       self.tic()
+    person_module.pers.setFirstName('Bob')
     self.portal.changeSkin(self.skin)
     self.validator = Validator()
     # make sure selections are empty
     self.portal.portal_selections.setSelectionFor(
-                        'person_module_selection', None)
+                        'person_module_selection', Selection())
+
+  if debug:
+    def publish(self, path, basic=None, **kw):
+      kw['handle_errors'] = False
+      return ZopeTestCase.Functional.publish(self, path, basic, **kw)
 
   def _validate(self, odf_file_data):
     error_list = self.validator.validate(odf_file_data)
@@ -176,6 +185,40 @@ class TestOOoStyle(ERP5TypeTestCase, ZopeTestCase.Functional):
     self.assertEquals('inline', content_disposition.split(';')[0])
     self._validate(response.getBody())
 
+  def test_form_view_encoding(self):
+    self.portal.person_module.pers.setFirstName('Jérome')
+    response = self.publish('/%s/person_module/pers/Person_view'
+                          % self.portal.getId(), basic=self.auth)
+    self.assertEquals(HTTP_OK, response.getStatus())
+    content_type = response.getHeader('content-type')
+    self.assertTrue(content_type.startswith(self.content_type), content_type)
+    content_disposition = response.getHeader('content-disposition')
+    self.assertEquals('inline', content_disposition.split(';')[0])
+    self._validate(response.getBody())
+
+  def test_report_view_encoding(self):
+    self.portal.person_module.pers.setFirstName('Jérome')
+    response = self.publish('/%s/person_module/pers/Base_viewHistory'
+                          % self.portal.getId(), basic=self.auth)
+    self.assertEquals(HTTP_OK, response.getStatus())
+    content_type = response.getHeader('content-type')
+    self.assertTrue(content_type.startswith(self.content_type), content_type)
+    content_disposition = response.getHeader('content-disposition')
+    self.assertEquals('inline', content_disposition.split(';')[0])
+    self._validate(response.getBody())
+
+  def test_form_list_encoding(self):
+    self.portal.person_module.pers.setFirstName('Jérome')
+    response = self.publish(
+       '/%s/person_module/PersonModule_viewPersonList'
+        % self.portal.getId(), basic=self.auth)
+    self.assertEquals(HTTP_OK, response.getStatus())
+    content_type = response.getHeader('content-type')
+    self.assertTrue(content_type.startswith(self.content_type), content_type)
+    content_disposition = response.getHeader('content-disposition')
+    self.assertEquals('inline', content_disposition.split(';')[0])
+    self._validate(response.getBody())
+
 
 class TestODTStyle(TestOOoStyle):
   skin = 'ODT'
-- 
2.30.9