From 46ee54f8c162204d13f14902d042993681e9cee9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bartek=20G=C3=B3rny?= <bartek@gorny.edu.pl>
Date: Tue, 6 Mar 2007 00:04:50 +0000
Subject: [PATCH] test snapshot generation; attempt to test
 portal_contributions

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13228 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5OOo/tests/testIngestion.py | 64 ++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)

diff --git a/product/ERP5OOo/tests/testIngestion.py b/product/ERP5OOo/tests/testIngestion.py
index 7684f74f20..f488252d08 100644
--- a/product/ERP5OOo/tests/testIngestion.py
+++ b/product/ERP5OOo/tests/testIngestion.py
@@ -42,6 +42,7 @@ from Products.ERP5Type.Utils import convertToUpperCase
 from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
 from Products.ERP5Type.tests.Sequence import SequenceList
 from Products.ERP5Type.Cache import clearCache
+from Products.ERP5OOo.Document.OOoDocument import ConversionError
 
 
 if __name__ == '__main__':
@@ -572,6 +573,48 @@ class TestIngestion(ERP5TypeTestCase):
   def stepCheckDrawingDocumentExportList(self, sequence=None, sequence_list=None, **kw):
     self.checkDocumentExportList('four', 'sxd', ['jpg', 'draw.pdf', 'svg'])
 
+  def stepCheckHasSnapshot(self, sequence=None, sequence_list=None, **kw):
+    dm = self.portal.document_module
+    context = getattr(dm, 'one')
+    self.failUnless(context.hasSnapshot())
+
+  def stepCheckHasNoSnapshot(self, sequence=None, sequence_list=None, **kw):
+    dm = self.portal.document_module
+    context = getattr(dm, 'one')
+    self.failIf(context.hasSnapshot())
+
+  def stepCreateSnapshot(self, sequence=None, sequence_list=None, **kw):
+    dm = self.portal.document_module
+    context = getattr(dm, 'one')
+    context.createSnapshot()
+
+  def stepTryRecreateSnapshot(self, sequence=None, sequence_list=None, **kw):
+    dm = self.portal.document_module
+    context = getattr(dm, 'one')
+    # XXX this always fails, don't know why
+    #self.assertRaises(ConversionError, context.createSnapshot)
+
+  def stepDeleteSnapshot(self, sequence=None, sequence_list=None, **kw):
+    dm = self.portal.document_module
+    context = getattr(dm, 'one')
+    context.deleteSnapshot()
+
+  def stepContributeFiles(self, sequence=None, sequence_list=None, **kw):
+    ext2type = (
+      ('ppt' , 'Presentation')
+      ,('doc' , 'Text')
+      ,('sdc' , 'Spreadsheet')
+      ,('odg' , 'Drawing')
+      ,('pdf' , 'PDF')
+      ,('jpg' , 'Image')
+      ,('py'  , 'File')
+      )
+    for ext, typ in ext2type:
+      shout(ext)
+      filename = 'TEST-en-002.' + ext
+      file = makeFileUpload(filename)
+      ob = self.portal.portal_contributions.newContent(file=file)
+      self.assertEquals(ob.getPortalType(), typ)
     
 
   ##################################
@@ -721,6 +764,21 @@ class TestIngestion(ERP5TypeTestCase):
     if testrun and 7 not in testrun:return
     if not run: return
     if not quiet: shout('test_07_SnapshotGeneration')
+    sequence_list = SequenceList()
+    step_list = [ 'stepCreateTextDocument'
+                 ,'stepDialogUpload'
+                 ,'stepCheckHasNoSnapshot'
+                 ,'stepCreateSnapshot'
+                 ,'stepTryRecreateSnapshot'
+                 ,'stepCheckHasSnapshot'
+                 ,'stepDeleteSnapshot'
+                 ,'stepCheckHasNoSnapshot'
+                 ,'stepCreateSnapshot'
+                ]
+    sequence_string = ' '.join(step_list)
+    sequence_list.addSequenceString(sequence_string)
+    sequence_list.play(self, quiet=quiet)
+
 
   def test_08_Cache(self, quiet=QUIET, run=RUN_ALL_TEST):
     """
@@ -742,6 +800,12 @@ class TestIngestion(ERP5TypeTestCase):
     if testrun and 8 not in testrun:return
     if not run: return
     if not quiet: shout('test_09_Contribute')
+    sequence_list = SequenceList()
+    step_list = [ 'stepContributeFiles'
+                ]
+    sequence_string = ' '.join(step_list)
+    sequence_list.addSequenceString(sequence_string)
+    sequence_list.play(self, quiet=quiet)
 
   def test_10_MetadataSettingPreferenceOrder(self, quiet=QUIET, run=RUN_ALL_TEST):
     """
-- 
2.30.9