[Erp5-report] r28865 - /erp5/trunk/products/ERP5OOo/tests/testOOoConversionCache.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Tue Sep 8 11:53:42 CEST 2009
Author: nicolas
Date: Tue Sep 8 11:53:42 2009
New Revision: 28865
URL: http://svn.erp5.org?rev=28865&view=rev
Log:
Test checksum in documents
Modified:
erp5/trunk/products/ERP5OOo/tests/testOOoConversionCache.py
Modified: erp5/trunk/products/ERP5OOo/tests/testOOoConversionCache.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5OOo/tests/testOOoConversionCache.py?rev=28865&r1=28864&r2=28865&view=diff
==============================================================================
--- erp5/trunk/products/ERP5OOo/tests/testOOoConversionCache.py [utf8] (original)
+++ erp5/trunk/products/ERP5OOo/tests/testOOoConversionCache.py [utf8] Tue Sep 8 11:53:42 2009
@@ -37,6 +37,7 @@
from Products.ERP5Type.tests.utils import FileUpload
from Products.ERP5Type.tests.utils import DummyLocalizer
from AccessControl.SecurityManagement import newSecurityManager
+from Products.ERP5Type.Cache import DEFAULT_CACHE_SCOPE
from zLOG import LOG
import os
@@ -282,6 +283,55 @@
self.assertTrue(document.hasConversion(format=format), 'Cache Storage failed for %s' % (format))
self.assertTrue(document.getConversionSize(format=format))
+ def test_05_checksum_conversion(self):
+ """
+ Test Conversion Cache return expected value with checksum
+ """
+ print '\nCheck checksum in Conversion'
+ filename = 'TEST-en-002.doc'
+ file = makeFileUpload(filename)
+ document = self.portal.portal_contributions.newContent(file=file)
+ transaction.commit()
+ self.tic()
+ document_url = document.getRelativeUrl()
+ document = self.portal.restrictedTraverse(document_url)
+ kw = {'format': 'html'}
+ #Generate one conversion
+ document.convert(**kw)
+ cache_id = document.generateCacheId(**kw)
+ cache_factory = document._getCacheFactory()
+ for cache_plugin in cache_factory.getCachePluginList():
+ cache_entry = cache_plugin.get(document.getPath(), DEFAULT_CACHE_SCOPE)
+ value = cache_entry.getValue()
+ md5sum, mime, data = value.get(cache_id)
+ #get data from cache
+ self.assertTrue(md5sum)
+ self.assertTrue(mime)
+ self.assertTrue(data)
+ #Change md5 manually
+ value.update({cache_id: ('Anything which is not md5', mime, data)})
+ cache_plugin.set(document.getPath(), DEFAULT_CACHE_SCOPE, value, 0, 0)
+ self.assertRaises(KeyError, document.getConversion, format='html')
+
+ def test_06_check_md5_is_updated(self):
+ """
+ Check that md5 checksum is well updated when upload a file
+ """
+ print '\nCheck checksum is updated'
+ filename = 'TEST-en-002.doc'
+ file = makeFileUpload(filename)
+ document = self.portal.portal_contributions.newContent(file=file)
+ transaction.commit()
+ self.tic()
+ document_url = document.getRelativeUrl()
+ document = self.portal.restrictedTraverse(document_url)
+ md5sum = document.getContentMd5()
+ self.assertTrue(md5sum)
+ filename2 = 'TEST-en-002.odt'
+ file2 = makeFileUpload(filename2)
+ document.edit(file=file2)
+ self.assertNotEqual(md5sum, document.getContentMd5())
+
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestDocumentConversionCache))
More information about the Erp5-report
mailing list