Commit 569a5eb4 authored by Bartek Górny's avatar Bartek Górny

some basic tests ready to run; lots of cleanups;

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@9401 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 972e231e
...@@ -52,11 +52,8 @@ from AccessControl.SecurityManagement import newSecurityManager, noSecurityManag ...@@ -52,11 +52,8 @@ from AccessControl.SecurityManagement import newSecurityManager, noSecurityManag
from DateTime import DateTime from DateTime import DateTime
from Acquisition import aq_base, aq_inner from Acquisition import aq_base, aq_inner
from zLOG import LOG from zLOG import LOG
#from Products.ERP5Type.DateUtils import addToDate
#import time
import os import os
from Products.ERP5Type import product_path from Products.ERP5Type import product_path
#from DateTime import DateTime
class TestDms(ERP5TypeTestCase): class TestDms(ERP5TypeTestCase):
""" """
...@@ -64,30 +61,14 @@ class TestDms(ERP5TypeTestCase): ...@@ -64,30 +61,14 @@ class TestDms(ERP5TypeTestCase):
# Different variables used for this test # Different variables used for this test
run_all_test = 1 run_all_test = 1
#source_company_id = 'Nexedi'
#destination_company_id = 'Coramy'
#component_id = 'brick'
#sales_order_id = '1'
#quantity = 10
#base_price = 0.7832
def getTitle(self): def getTitle(self):
return "DMS" return "DMS"
#def populate(self, quiet=1, run=1):
def afterSetUp(self, quiet=1, run=1): def afterSetUp(self, quiet=1, run=1):
self.createCategories() self.createCategories()
self.login() self.login()
portal = self.getPortal() portal = self.getPortal()
#catalog_tool = self.getCatalogTool()
# XXX This does not works
#catalog_tool.reindexObject(portal)
# First reindex
#LOG('afterSetup',0,'portal.portal_categories.immediateReindexObject')
#portal.portal_categories.immediateReindexObject()
#LOG('afterSetup',0,'portal.portal_simulation.immediateReindexObject')
#portal.portal_simulation.immediateReindexObject()
def getDocumentModule(self): def getDocumentModule(self):
return getattr(self.getPortal(),'document_module') return getattr(self.getPortal(),'document_module')
...@@ -123,7 +104,6 @@ class TestDms(ERP5TypeTestCase): ...@@ -123,7 +104,6 @@ class TestDms(ERP5TypeTestCase):
newSecurityManager(None, user) newSecurityManager(None, user)
def test_01_HasEverything(self, quiet=0, run=run_all_test): def test_01_HasEverything(self, quiet=0, run=run_all_test):
# Test if portal_synchronizations was created
if not run: return if not run: return
if not quiet: if not quiet:
ZopeTestCase._print('\nTest Has Everything ') ZopeTestCase._print('\nTest Has Everything ')
...@@ -139,8 +119,6 @@ class TestDms(ERP5TypeTestCase): ...@@ -139,8 +119,6 @@ class TestDms(ERP5TypeTestCase):
role._edit(agent='person_module/1',role_name='Assignor') role._edit(agent='person_module/1',role_name='Assignor')
def printAndCheck(self,doc): def printAndCheck(self,doc):
#ZopeTestCase._print(str(doc.__ac_local_roles__.get('hq','')))
#ZopeTestCase._print(str(doc.__ac_local_roles__))
self.assert_(u'Auditor' in doc.__ac_local_roles__.get('hq',[])) self.assert_(u'Auditor' in doc.__ac_local_roles__.get('hq',[]))
def test_02_ObjectCreation(self,quiet=0,run=run_all_test): def test_02_ObjectCreation(self,quiet=0,run=run_all_test):
...@@ -166,9 +144,10 @@ class TestDms(ERP5TypeTestCase): ...@@ -166,9 +144,10 @@ class TestDms(ERP5TypeTestCase):
ZopeTestCase._print('\nTest Basic Conversion') ZopeTestCase._print('\nTest Basic Conversion')
LOG('Testing... ',0,'test_03_BasicConversion') LOG('Testing... ',0,'test_03_BasicConversion')
dm=self.getPortal().document_module dm=self.getPortal().document_module
doctext=dm.newContent(portal_type='Text')
doctext=dm.newContent(portal_type='Text',id='1')
doctext._getServerCoordinates=lambda:('127.0.0.1',8080) doctext._getServerCoordinates=lambda:('127.0.0.1',8080)
f=FileObject('/var/lib/zope/Products/ERP5/tests/test.doc') f=FileObject(os.getenv('INSTANCE_HOME')+'/../Products/ERP5OOo/tests/test.doc')
f.filename='test.doc' f.filename='test.doc'
doctext._edit(file=f) doctext._edit(file=f)
f.close() f.close()
...@@ -182,270 +161,41 @@ class TestDms(ERP5TypeTestCase): ...@@ -182,270 +161,41 @@ class TestDms(ERP5TypeTestCase):
self.assert_(doctext.hasOOfile()) self.assert_(doctext.hasOOfile())
ZopeTestCase._print('\n isFileUploaded '+str(doctext.isFileUploaded())) ZopeTestCase._print('\n isFileUploaded '+str(doctext.isFileUploaded()))
ZopeTestCase._print('\n hasOOfile '+str(doctext.hasOOfile())) ZopeTestCase._print('\n hasOOfile '+str(doctext.hasOOfile()))
ZopeTestCase._print('\n'+str(doctext.getTargetFormatItemList())) tgts=doctext.getTargetFormatItemList()
tgtext=[t[1] for t in tgts]
self.assert_('pdf' in tgtext)
########################################################## self.assertEquals('subject',doctext.getSubject())
# USEFUL EXAMPLES THAT WE DON'T RUN # self.assert_(doctext.getSearchableText().find('adadadfa'))
##########################################################
def newAlarm(self): def createTestDocument(self):
""" dm=self.getPortal().document_module
Create an empty alarm doctext=dm.newContent(portal_type='Text',id='1')
""" doctext._getServerCoordinates=lambda:('127.0.0.1',8080)
a_tool = self.getAlarmTool() f=FileObject(os.getenv('INSTANCE_HOME')+'/../Products/ERP5OOo/tests/test.doc')
return a_tool.newContent() f.filename='test.doc'
doctext._edit(file=f)
f.close()
doctext.convert()
return doctext
def _test_02_Initialization(self, quiet=0, run=run_all_test): def test_04_FileGeneration(self,quiet=0,run=run_all_test):
"""
Test some basic things right after the creation
"""
if not run: return
if not quiet:
message = 'Test Initialization'
ZopeTestCase._print('\n%s ' % message)
LOG('Testing... ',0,message)
alarm = self.newAlarm()
now = DateTime()
date = addToDate(now,day=1)
alarm.setPeriodicityStartDate(date)
self.assertEquals(alarm.getAlarmDate(),date)
alarm.setNextAlarmDate(current_date=now) # This should not do change the alarm date
self.assertEquals(alarm.getAlarmDate(),date)
def _test_03_EveryHour(self, quiet=0, run=run_all_test):
if not run: return
if not quiet:
message = 'Test Every Hour'
ZopeTestCase._print('\n%s ' % message)
LOG('Testing... ',0,message)
alarm = self.newAlarm()
now = DateTime()
date = addToDate(now,day=2)
alarm.setPeriodicityStartDate(date)
alarm.setPeriodicityHourFrequency(1)
alarm.setNextAlarmDate(current_date=now)
self.assertEquals(alarm.getAlarmDate(),date)
LOG(message + ' now :',0,now)
now = addToDate(now,day=2)
LOG(message + ' now :',0,now)
alarm.setNextAlarmDate(current_date=now)
next_date = addToDate(date,hour=1)
self.assertEquals(alarm.getAlarmDate(),next_date)
now = addToDate(now,hour=1,minute=5)
alarm.setNextAlarmDate(current_date=now)
next_date = addToDate(next_date,hour=1)
self.assertEquals(alarm.getAlarmDate(),next_date)
def _test_04_Every3Hours(self, quiet=0, run=run_all_test):
if not run: return
if not quiet: if not quiet:
message = 'Test Every 3 Hours' ZopeTestCase._print('\nTest File Generation')
ZopeTestCase._print('\n%s ' % message) LOG('Testing... ',0,'test_04_FileGeneration')
LOG('Testing... ',0,message) doctext=self.createTestDocument()
alarm = self.newAlarm() doctext.getTargetFile('pdf')
now = DateTime() self.assert_(doctext.hasFileCache('pdf'))
hour_to_remove = now.hour() % 3
now = addToDate(now,hour=-hour_to_remove) def test_05_OtherFunctions(self,quiet=0,run=run_all_test):
date = addToDate(now,day=2)
alarm.setPeriodicityStartDate(date)
alarm.setPeriodicityHourFrequency(3)
alarm.setNextAlarmDate(current_date=now)
self.assertEquals(alarm.getAlarmDate(),date)
LOG(message + ' now :',0,now)
now = addToDate(now,day=2)
LOG(message + ' now :',0,now)
alarm.setNextAlarmDate(current_date=now)
next_date = addToDate(date,hour=3)
self.assertEquals(alarm.getAlarmDate(),next_date)
now = addToDate(now,hour=3,minute=7,second=4)
alarm.setNextAlarmDate(current_date=now)
next_date = addToDate(next_date,hour=3)
self.assertEquals(alarm.getAlarmDate(),next_date)
def _test_05_SomeHours(self, quiet=0, run=run_all_test):
if not run: return
if not quiet:
message = 'Test Some Hours'
ZopeTestCase._print('\n%s ' % message)
LOG('Testing... ',0,message)
# year/month/day hour:minute:second
right_first_date = DateTime('%i/%i/%i %i:%i:%d' % (2004,10,6,15,00,00))
now = DateTime('%i/%i/%i %i:%i:%d' % (2004,10,6,15,00,00))
right_second_date = DateTime('%i/%i/%i %i:%i:%d' % (2004,10,6,21,00,00))
right_third_date = DateTime('%i/%i/%i %i:%i:%d' % (2004,10,7,06,00,00))
right_fourth_date = DateTime('%i/%i/%i %i:%i:%d' % (2004,10,7,10,00,00))
alarm = self.newAlarm()
hour_list = (6,10,15,21)
alarm.setPeriodicityStartDate(now)
alarm.setPeriodicityHourList(hour_list)
self.assertEquals(alarm.getAlarmDate(),right_first_date)
alarm.setNextAlarmDate(current_date=right_first_date)
self.assertEquals(alarm.getAlarmDate(),right_second_date)
alarm.setNextAlarmDate(current_date=right_second_date)
self.assertEquals(alarm.getAlarmDate(),right_third_date)
alarm.setNextAlarmDate(current_date=right_third_date)
self.assertEquals(alarm.getAlarmDate(),right_fourth_date)
def _test_06_EveryDayOnce(self, quiet=0, run=run_all_test):
if not run: return
if not quiet:
message = 'Every Day Once'
ZopeTestCase._print('\n%s ' % message)
LOG('Testing... ',0,message)
# year/month/day hour:minute:second
now = DateTime('%i/%i/%i %i:%i:%d' % (2004,10,6,10,00,00))
right_first_date = DateTime('%i/%i/%i %i:%i:%d' % (2004,10,6,10,00,00))
right_second_date = DateTime('%i/%i/%i %i:%i:%d' % (2004,10,7,10,00,00))
right_third_date = DateTime('%i/%i/%i %i:%i:%d' % (2004,10,8,10,00,00))
alarm = self.newAlarm()
alarm.setPeriodicityStartDate(now)
alarm.setPeriodicityDayFrequency(1)
alarm.setPeriodicityHourList((10,))
self.assertEquals(alarm.getAlarmDate(),right_first_date)
alarm.setNextAlarmDate(current_date=right_first_date)
self.assertEquals(alarm.getAlarmDate(),right_second_date)
alarm.setNextAlarmDate(current_date=right_second_date)
self.assertEquals(alarm.getAlarmDate(),right_third_date)
def _test_07_Every3DaysSomeHours(self, quiet=0, run=run_all_test):
"""- every 3 days at 14 and 15 and 17"""
if not run: return
if not quiet:
message = 'Every 3 Days Some Hours'
ZopeTestCase._print('\n%s ' % message)
LOG('Testing... ',0,message)
# year/month/day hour:minute:second
right_first_date = DateTime('%i/%i/%i %i:%i:%d' % (2004,10,6,14,00,00))
right_second_date = DateTime('%i/%i/%i %i:%i:%d' % (2004,10,6,15,00,00))
right_third_date = DateTime('%i/%i/%i %i:%i:%d' % (2004,10,6,17,00,00))
right_fourth_date = DateTime('%i/%i/%i %i:%i:%d' % (2004,10,9,14,00,00))
alarm = self.newAlarm()
alarm.setPeriodicityStartDate(right_first_date)
alarm.setPeriodicityDayFrequency(3)
alarm.setPeriodicityHourList((14,15,17))
self.assertEquals(alarm.getAlarmDate(),right_first_date)
alarm.setNextAlarmDate(current_date=right_first_date)
self.assertEquals(alarm.getAlarmDate(),right_second_date)
alarm.setNextAlarmDate(current_date=right_second_date)
self.assertEquals(alarm.getAlarmDate(),right_third_date)
alarm.setNextAlarmDate(current_date=right_third_date)
self.assertEquals(alarm.getAlarmDate(),right_fourth_date)
def _test_08_SomeWeekDaysSomeHours(self, quiet=0, run=run_all_test):
"""- every monday and friday, at 6 and 15"""
if not run: return
if not quiet:
message = 'Some Week Days Some Hours'
ZopeTestCase._print('\n%s ' % message)
LOG('Testing... ',0,message)
# year/month/day hour:minute:second
right_first_date = DateTime('%i/%i/%i %i:%i:%d' % (2004,9,27,6,00,00))
right_second_date = DateTime('%i/%i/%i %i:%i:%d' % (2004,9,27,15,00,00))
right_third_date = DateTime('%i/%i/%i %i:%i:%d' % (2004,10,1,6,00,00))
right_fourth_date = DateTime('%i/%i/%i %i:%i:%d' % (2004,10,1,15,00,00))
alarm = self.newAlarm()
alarm.setPeriodicityStartDate(right_first_date)
alarm.setPeriodicityWeekDayList(('Monday','Friday'))
alarm.setPeriodicityHourList((6,15))
self.checkDate(alarm, right_first_date, right_second_date, right_third_date, right_fourth_date)
#self.assertEquals(alarm.getAlarmDate(),right_first_date)
#alarm.setNextAlarmDate(current_date=right_first_date)
#self.assertEquals(alarm.getAlarmDate(),right_second_date)
#alarm.setNextAlarmDate(current_date=right_second_date)
#self.assertEquals(alarm.getAlarmDate(),right_third_date)
#alarm.setNextAlarmDate(current_date=right_third_date)
#self.assertEquals(alarm.getAlarmDate(),right_fourth_date)
def checkDate(self,alarm,*args):
"""
the basic test
"""
for date in args[:-1]:
LOG('checkDate, checking date...:',0,date)
self.assertEquals(alarm.getAlarmDate(),date)
alarm.setNextAlarmDate(current_date=date)
self.assertEquals(alarm.getAlarmDate(),args[-1])
def _test_09_SomeMonthDaysSomeHours(self, quiet=0, run=run_all_test):
"""- every 1st and 15th every month, at 12 and 14"""
if not run: return
if not quiet:
message = 'Some Month Days Some Hours'
ZopeTestCase._print('\n%s ' % message)
LOG('Testing... ',0,message)
# year/month/day hour:minute:second
right_first_date = DateTime('%i/%i/%i %i:%i:%d' % (2004,10,01,12,00,00))
right_second_date = DateTime('%i/%i/%i %i:%i:%d' % (2004,10,01,14,00,00))
right_third_date = DateTime('%i/%i/%i %i:%i:%d' % (2004,10,15,12,00,00))
right_fourth_date = DateTime('%i/%i/%i %i:%i:%d' % (2004,10,15,14,00,00))
alarm = self.newAlarm()
alarm.setPeriodicityStartDate(right_first_date)
alarm.setPeriodicityMonthDayList((1,15))
alarm.setPeriodicityHourList((12,14))
self.checkDate(alarm, right_first_date, right_second_date, right_third_date, right_fourth_date)
def _test_10_OnceEvery2Month(self, quiet=0, run=run_all_test):
"""- every 1st day of every 2 month, at 6"""
if not run: return
if not quiet:
message = 'Once Every 2 Month'
ZopeTestCase._print('\n%s ' % message)
LOG('Testing... ',0,message)
# year/month/day hour:minute:second
right_first_date = DateTime('%i/%i/%i %i:%i:%d' % (2004,10,01,6,00,00))
right_second_date = DateTime('%i/%i/%i %i:%i:%d' % (2004,12,01,6,00,00))
right_third_date = DateTime('%i/%i/%i %i:%i:%d' % (2005,2,01,6,00,00))
alarm = self.newAlarm()
alarm.setPeriodicityStartDate(right_first_date)
alarm.setPeriodicityMonthDayList((1,))
alarm.setPeriodicityMonthFrequency(2)
alarm.setPeriodicityHourList((6,))
self.checkDate(alarm, right_first_date, right_second_date, right_third_date)
def _test_11_EveryDayOnceWeek41And42(self, quiet=0, run=run_all_test):
if not run: return
if not quiet:
message = 'Every Day Once Week 41 And 43'
ZopeTestCase._print('\n%s ' % message)
LOG('Testing... ',0,message)
# year/month/day hour:minute:second
right_first_date = DateTime('%i/%i/%i %i:%i:%d' % (2004,10,10,6,00,00))
right_second_date = DateTime('%i/%i/%i %i:%i:%d' % (2004,10,18,6,00,00))
right_third_date = DateTime('%i/%i/%i %i:%i:%d' % (2004,10,19,6,00,00))
right_fourth_date = DateTime('%i/%i/%i %i:%i:%d' % (2004,10,20,6,00,00))
alarm = self.newAlarm()
alarm.setPeriodicityStartDate(right_first_date)
alarm.setPeriodicityHourList((6,))
alarm.setPeriodicityWeekList((41,43))
self.checkDate(alarm, right_first_date, right_second_date, right_third_date,right_fourth_date)
def _test_12_Every5Minutes(self, quiet=0, run=run_all_test):
if not run: return
if not quiet: if not quiet:
message = 'Test Every 5 Minutes' ZopeTestCase._print('\nTest Other Functions')
ZopeTestCase._print('\n%s ' % message) LOG('Testing... ',0,'test_05_OtherFunctions')
LOG('Testing... ',0,message) doctext=self.createTestDocument()
alarm = self.newAlarm() ZopeTestCase._print('\n'+doctext.getCacheInfo())
now = DateTime() mtype=doctext.guessMimeType('file.doc')
minute_to_remove = now.minute() % 5 self.assertEquals(mtype,'application/msword')
now = addToDate(now,minute=-minute_to_remove)
date = addToDate(now,day=2)
alarm.setPeriodicityStartDate(date)
alarm.setPeriodicityMinuteFrequency(5)
alarm.setNextAlarmDate(current_date=now)
self.assertEquals(alarm.getAlarmDate(),date)
LOG(message + ' now :',0,now)
now = addToDate(now,day=2)
LOG(message + ' now :',0,now)
alarm.setNextAlarmDate(current_date=now)
next_date = addToDate(date,minute=5)
self.assertEquals(alarm.getAlarmDate(),next_date)
now = addToDate(now,minute=5,second=14)
alarm.setNextAlarmDate(current_date=now)
next_date = addToDate(next_date,minute=5)
self.assertEquals(alarm.getAlarmDate(),next_date)
if __name__ == '__main__': if __name__ == '__main__':
framework() framework()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment