class clearAndSaveTest (unittest.TestCase): def setUp(self): ''' Setup the test case by loading the contant of the files to process the attended result. ''' self.__log = Log() self.__originalFile1 = Order(self.__log) self.__originalFile2 = Order(self.__log) self.__originalFile1.loadOrder(os.path.join(TEST_FILE_ROOT, 'OrderTestFile4.xls')) self.__originalFile2.loadOrder(os.path.join(TEST_FILE_ROOT, 'OrderTestFile5.xls')) self.__attendedResult2 = [] for prodOrder in self.__originalFile1.getOrderList(): self.__originalFile2.append(prodOrder) self.__originalFile2.popLeft() for prodOrder in self.__originalFile2.getOrderList(): self.__attendedResult2.append(prodOrder) def tearDown(self): ''' Deleted the new files. ''' os.remove(os.path.join(TEST_FILE_ROOT, 'OrderTestFile6.xls')) os.remove(os.path.join(TEST_FILE_ROOT, 'OrderTestFile7.xls')) def testClearAndSave(self): ''' Order must be able to clear and save (removing old order) itself. ''' order1 = Order(self.__log) order2 = Order(self.__log) order1.loadOrder(os.path.join(TEST_FILE_ROOT, 'OrderTestFile4.xls')) order2.loadOrder(os.path.join(TEST_FILE_ROOT, 'OrderTestFile5.xls')) for i in range(len(order1)): order2.append(order1.popLeft()) i = i order1.clear() order1.save(os.path.join(TEST_FILE_ROOT, 'OrderTestFile6.xls')) order2.save(os.path.join(TEST_FILE_ROOT, 'OrderTestFile7.xls')) resultOrder1 = Order(self.__log) resultOrder2 = Order(self.__log) try: resultOrder1.loadOrder(os.path.join(TEST_FILE_ROOT, 'OrderTestFile6.xls')) except: pass resultOrder2.loadOrder(os.path.join(TEST_FILE_ROOT, 'OrderTestFile7.xls')) result1 = [] result2 = [] for prodOrder in resultOrder1.getOrderList(): result1.append(prodOrder) for prodOrder in resultOrder2.getOrderList(): result2.append(prodOrder) self.assertListEqual(result1, [], 'Order failed to clear itself.') self.assertListEqual(result2, self.__attendedResult2, 'Order failed to save itself.')
def testFilterLogging(self): ''' Order must log the ProductOrder that was filtered and the reson why thy were filtered. ''' log =Log() order1 = Order(log) order2 = Order(log) order1.loadOrder(os.path.join(TEST_FILE_ROOT, 'OrderTestFile2.xls')) order2.loadOrder(os.path.join(TEST_FILE_ROOT, 'OrderTestFile3.xls')) order1.filter(order2) self.assertListEqual(log.getMsgList(), self.ATTENDED_LOG, 'Order failed to log the filtered ProductOrder.')
def testOrderLoading(self): ''' Order must be able to load its ProductOrders from an excel file, get its length and pop right its whole ProductOrder list. ''' log = Log() order = Order(log) order.loadOrder(os.path.join(TEST_FILE_ROOT, 'OrderTestFile1.xls')) result = [] for i in range(len(order)): result.append(order.popRight()) i = i self.assertListEqual(result, self.ATTENDED_RESULTS, 'Order failed to load its ProductOrder list from an excel file, get its length and popRight its whole ProductOrder list')
def testClearAndSave(self): ''' Order must be able to clear and save (removing old order) itself. ''' order1 = Order(self.__log) order2 = Order(self.__log) order1.loadOrder(os.path.join(TEST_FILE_ROOT, 'OrderTestFile4.xls')) order2.loadOrder(os.path.join(TEST_FILE_ROOT, 'OrderTestFile5.xls')) for i in range(len(order1)): order2.append(order1.popLeft()) i = i order1.clear() order1.save(os.path.join(TEST_FILE_ROOT, 'OrderTestFile6.xls')) order2.save(os.path.join(TEST_FILE_ROOT, 'OrderTestFile7.xls')) resultOrder1 = Order(self.__log) resultOrder2 = Order(self.__log) try: resultOrder1.loadOrder(os.path.join(TEST_FILE_ROOT, 'OrderTestFile6.xls')) except: pass resultOrder2.loadOrder(os.path.join(TEST_FILE_ROOT, 'OrderTestFile7.xls')) result1 = [] result2 = [] for prodOrder in resultOrder1.getOrderList(): result1.append(prodOrder) for prodOrder in resultOrder2.getOrderList(): result2.append(prodOrder) self.assertListEqual(result1, [], 'Order failed to clear itself.') self.assertListEqual(result2, self.__attendedResult2, 'Order failed to save itself.')
def testFilterOrder(self): ''' Order must be able to filter and remove the bad ProductOrder and those already ordered. The filters are: - imcomplete or incoherent ProductOrder. - Already ordered in the last 20 days ProductOrder, except if employee is the admin. ''' log =Log() order1 = Order(log) order2 = Order(log) order1.loadOrder(os.path.join(TEST_FILE_ROOT, 'OrderTestFile2.xls')) order2.loadOrder(os.path.join(TEST_FILE_ROOT, 'OrderTestFile3.xls')) order1.filter(order2) result = [] for i in range(len(order1)): result.append(order1.popLeft()) i = i self.assertListEqual(result, self.ATTENDED_RESULTS, 'Order failed to filter and remove the bad and already ordered ProductOrder.')
#notify the closing of libreOffice and kill it #a = ctypes.windll.user32.MessageBoxA(0, 'LibreOffice fermera dans 60 seconde.', # '!!!Killing Notification!!!', 0) #kill LibreOffice os.system('taskkill /f /im soffice.bin') #instanciate the log file log = Log() #load the data from the input files dailyOrder = Order(log) previousOrder = Order(log) try: dailyOrder.loadOrder(dailyOrderFile) except: #if nothing to order, simply log it and exit log.logMsg(u'Rien a commander.') log.outputLog(outputPath) sys.exit(0) try: previousOrder.loadOrder(previousOrderFile) except: pass #filter the daily order data dailyOrder.filter(previousOrder) #generate the mail if dailyOrder.getOrderList():