def startmulti(grammardir): ''' specialized tool for bulk checking of grammars while developing botsgrammars grammardir: directory with gramars (eg bots/usersys/grammars/edifact) editype: eg edifact ''' configdir = 'config' botsinit.generalinit( configdir) # find locating of bots, configfiles, init paths etc. process_name = 'grammarcheck' botsglobal.logger = botsinit.initenginelogging(process_name) atexit.register(logging.shutdown) files = glob.iglob(grammardir, recursive=True) files = [f for f in files if os.path.isfile(f)] for filename in files: filename_basename = os.path.basename(filename) editype = os.path.basename(os.path.dirname(filename)) if filename_basename in ['__init__.py', '__pycache__', 'envelope.py']: continue if filename_basename.startswith( 'edifact') or filename_basename.startswith( 'records') or filename_basename.endswith('records.py'): continue if not filename_basename.endswith('py'): continue filename_noextension = os.path.splitext(filename_basename)[0] try: grammar.grammarread(editype, filename_noextension, typeofgrammarfile='grammars') except: print(botslib.txtexc(), end='\n\n') sys.exit(1) else: print('OK - no error found in grammar', filename, end='\n\n')
def read_from_file(self, path): configdir = 'config' botsinit.generalinit(configdir) process_name = 'odoo_get_edi' botsglobal.logger = botsinit.initenginelogging(process_name) atexit.register(logging.shutdown) ta_info = { 'alt': '', 'charset': '', 'command': 'new', 'editype': 'edifact', 'filename': path, 'fromchannel': '', 'frompartner': '', 'idroute': '', 'messagetype': 'edifact', 'testindicator': '', 'topartner': ''} try: edifile = inmessage.parse_edi_file(**ta_info) except Exception as e: if '[A59]' in str(e): raise exceptions.Warning( _('Edi file has codification errors.'), _('Check accents and other characters not allowed ' 'in the edi document')) raise exceptions.Warning(_( 'It has occurred following error: %s.' % e)) json_ins = outmessage.json(edifile.ta_info) struc = [{ms.root.record['BOTSID']: json_class._node2json(json_ins, ms.root)} for ms in edifile.nextmessage()] return struc
def compose_edi_invoice(self, invoice): configdir = 'config' botsinit.generalinit(configdir) process_name = 'odoo_get_edi' botsglobal.logger = botsinit.initenginelogging(process_name) una, header, footer = self.get_edi_invoice_envelops(invoice) body = self.get_edi_invoice_body(invoice) content = ''.join([una, header, body, footer]) return content
ORDER BY idta DESC ''', {'status':310,'statust':DONE,'idroute':'testcontrl','confirmtype':'send-edifact-CONTRL','confirmasked':True}): counter += 1 if counter <= 2: self.failUnless(row[1]) self.failUnless(row[2]!=0) else: break else: self.failUnless(counter!=0) if __name__ == '__main__': pythoninterpreter = 'python' newcommand = [pythoninterpreter,'bots-engine.py',] shutil.rmtree(os.path.join(botssys, 'outfile'),ignore_errors=True) #remove whole output directory subprocess.call(newcommand) botsinit.generalinit('config') botsinit.initenginelogging() botsinit.connect() print '''expect: 21 files received/processed in run. 17 files without errors, 4 files with errors, 30 files send in run. ''' unittest.main() logging.shutdown() botsglobal.db.close()
"desadv1.edi", "", ) print( "expect: <idta>.edi ", comclass.filename_formatter("{idta}.edi", ta), ) self.assertRaises(botslib.CommunicationOutError, comclass.filename_formatter, "{tada}", ta) self.assertRaises( botslib.CommunicationOutError, comclass.filename_formatter, "{infile:test}", ta, ) if count == 1: # test only 1 incoming files break if __name__ == "__main__": pythoninterpreter = "python3.4" newcommand = [pythoninterpreter, "bots-engine.py"] subprocess.call(newcommand) botsinit.generalinit("config") botsinit.initenginelogging("engine") botsinit.connect() unittest.main() logging.shutdown() botsglobal.db.close()
self.assertEqual('0',t.getcountsum({'BOTSID':'UNB'},{'BOTSID':'UNH'},{'BOTSID':'LIN'},{'BOTSID':'QTY','C186.6063':'12','C186.6060':None}),'Cmplines') self.assertEqual('0',t.getcountsum({'BOTSID':'UNB'},{'BOTSID':'UNH'},{'BOTSID':'LIN'},{'BOTSID':'MOA','C516.5025':'203','C516.5004':None}),'Cmplines') #~ def testedifact02(self): #display query correct? incluuding propagating 'down the tree'? #~ inn = inmessage.parse_edi_file(editype='edifact',messagetype='invoicwithenvelopetestquery',filename='botssys/infile/unitnode/nodetest01.edi') #~ inn.root.processqueries({},2) #~ inn.root.displayqueries() def testedifact03(self): #~ #display query correct? incluuding propagating 'down the tree'? node.Node.fetchqueries = fetchqueries inn = inmessage.parse_edi_file(editype='edifact',messagetype='edifact',filename='botssys/infile/unitnode/0T0000000015.edi') inn.root.processqueries({},2) inn.root.fetchqueries() #~ print collectqueries comparequeries = {u'UNH': {'reference': u'UNHREF', 'messagetype': u'ORDERSD96AUNEAN008', 'reference2': u'UNBREF', 'topartner': u'PARTNER2', 'alt': u'50EAB', 'alt2': u'50E9', 'frompartner': u'PARTNER1'}, u'UNB': {'topartner': u'PARTNER2', 'reference2': u'UNBREF', 'reference': u'UNBREF', 'frompartner': u'PARTNER1'}, u'UNZ': {'reference': u'UNBREF', 'reference2': u'UNBREF', 'topartner': u'PARTNER2', 'frompartner': u'PARTNER1'}} self.assertEqual(comparequeries,collectqueries) #~ inn.root.displayqueries() if __name__ == '__main__': import datetime botsinit.generalinit('config') botsglobal.logger = botsinit.initenginelogging('engine') shutil.rmtree('bots/botssys/infile/unitnode/output',ignore_errors=True) #remove whole output directory os.mkdir('bots/botssys/infile/unitnode/output') unittest.main() unittest.main() unittest.main()
field = ['S001.0001', 'M', 4.3, 'I'] fieldresult = ['S001.0001', 1, 4, 'I', True, 3, 4, 'I', 1] gramfield(field, '') self.assertEqual(field, fieldresult) field = ['S001.0001', 'M', 4.3, 'R'] fieldresult = ['S001.0001', 1, 4, 'R', True, 3, 4, 'R', 1] gramfield(field, '') self.assertEqual(field, fieldresult) field = ['S001.0001', 'C', 4.3, 'R'] fieldresult = ['S001.0001', 0, 4, 'R', True, 3, 4, 'R', 1] gramfield(field, '') self.assertEqual(field, fieldresult) field = ['S001.0001', ('C', 5), 4.3, 'R'] fieldresult = ['S001.0001', 0, 4, 'R', True, 3, 4, 'R', 5] gramfield(field, '') self.assertEqual(field, fieldresult) self.assertRaises(botslib.GrammarError, gramfield, ['S001.0001', 'M', 4, 'B'], '') if __name__ == '__main__': botsinit.generalinit('config') #~ botslib.initbotscharsets() botsglobal.logger = botsinit.initenginelogging('engine') unittest.main()
self.assertEqual('12345678901231', transform.addeancheckdigit('1234567890123'), 'EAN14') self.assertEqual('1', transform.calceancheckdigit('1234567890123'), 'EAN14') self.assertEqual(True, transform.checkean('12345678901231'), 'EAN14') self.assertEqual(False, transform.checkean('12345678901230'), 'EAN14') self.assertEqual(False, transform.checkean('12345678901236'), 'EAN14') self.assertEqual('123456789012345675', transform.addeancheckdigit('12345678901234567'), 'UPC') self.assertEqual('5', transform.calceancheckdigit('12345678901234567'), 'UPC') self.assertEqual(True, transform.checkean('123456789012345675'), 'UPC') self.assertEqual(False, transform.checkean('123456789012345670'), 'UPC') self.assertEqual(False, transform.checkean('123456789012345677'), 'UPC') if __name__ == '__main__': botsinit.generalinit('config') botsinit.initenginelogging() botsinit.connect() try: unittest.main() except: pass botsglobal.db.close()
self.failUnless(True==botslib.checkconfirmrules('send-email-MDN',idroute='idroute',idchannel='tochannel',topartner='topartner',frompartner='frompartner',editype='x12',messagetype='messagetype')) self.failUnless(False==botslib.checkconfirmrules('send-email-MDN',idroute='otherx12',idchannel='tochannel',topartner='topartner',frompartner='frompartner',editype='x12',messagetype='messagetype')) self.failUnless(False==botslib.checkconfirmrules('send-email-MDN',idroute='idroute',idchannel='mdn2_in',topartner='topartner',frompartner='frompartner',editype='x12',messagetype='messagetype')) self.failUnless(False==botslib.checkconfirmrules('send-email-MDN',idroute='idroute',idchannel='tochannel',topartner='partnerunittest',frompartner='frompartner',editype='x12',messagetype='messagetype')) self.failUnless(False==botslib.checkconfirmrules('send-email-MDN',idroute='idroute',idchannel='tochannel',topartner='topartner',frompartner='partnerunittest',editype='x12',messagetype='messagetype')) self.failUnless(False==botslib.checkconfirmrules('send-email-MDN',idroute='otherx12',idchannel='mdn2_in',topartner='partnerunittest',frompartner='partnerunittest',editype='x12',messagetype='messagetype')) self.failUnless(True==botslib.checkconfirmrules('send-email-MDN',idroute='otherx1',idchannel='mdn2_i',topartner='partnerunittes',frompartner='partnerunittes',editype='x12',messagetype='messagetype')) if __name__ == '__main__': pythoninterpreter = 'python' newcommand = [pythoninterpreter,'bots-engine.py',] shutil.rmtree(os.path.join(botssys, 'outfile'),ignore_errors=True) #remove whole output directory subprocess.call(newcommand) print '''expect: 21 files received/processed in run. 17 files without errors, 4 files with errors, 30 files send in run. ''' #connect to database etc #check nrs confirmed etc. botsinit.generalinit('config') botsinit.initenginelogging('engine') botsinit.connect() botslib.prepare_confirmrules() unittest.main() logging.shutdown() botsglobal.db.close()
def start(): try: botsinit.generalinit('config') botsinit.initenginelogging() except: print 'Error reading bots.ini (before database connection).' raise try: botsinit.connect() except: print 'Could not connect to database.' raise #*****************start test*************** domein = 'test' tests = [(u'key1',u'leftcode'), (u'key2',u'~!@#$%^&*()_+}{:";][=-/.,<>?`'), (u'key3',u'?érýúíó?ás??lzcn?'), (u'key4',u'?ë?ÿüïöä´¨???è?ùì'), (u'key5',u'òà???UIÕÃ?Ñ`~'), (u'key6',u"a\xac\u1234\u20ac\U00008000"), (u'key7',u"abc_\u03a0\u03a3\u03a9.txt"), (u'key8',u"?ÉRÝÚÍÓ?ÁS??LZCN??"), (u'key9',u"Ë?¨YܨIÏÏÖÄ???È?ÙÌÒ`À`Z?"), ] try: #clean before test botslib.change(u'''DELETE FROM ccode ''') botslib.change(u'''DELETE FROM ccodetrigger''') except: print 'Error while deleting',botslib.txtexc() raise try: botslib.change(u'''INSERT INTO ccodetrigger (ccodeid) VALUES (%(ccodeid)s)''', {'ccodeid':domein}) for key,value in tests: botslib.change(u'''INSERT INTO ccode (ccodeid_id,leftcode,rightcode,attr1,attr2,attr3,attr4,attr5,attr6,attr7,attr8) VALUES (%(ccodeid)s,%(leftcode)s,%(rightcode)s,'1','1','1','1','1','1','1','1')''', {'ccodeid':domein,'leftcode':key,'rightcode':value}) except: print 'Error while updating',botslib.txtexc() raise try: for key,value in tests: print 'key',key for row in botslib.query(u'''SELECT rightcode FROM ccode WHERE ccodeid_id = %(ccodeid)s AND leftcode = %(leftcode)s''', {'ccodeid':domein,'leftcode':key}): print ' ',key, type(row['rightcode']),type(value) if row['rightcode'] != value: print 'failure in test "%s": result "%s" is not equal to "%s"'%(key,row['rightcode'],value) else: print ' OK' break; else: print '??can not find testentry %s %s in db'%(key,value) except: print 'Error while quering db',botslib.txtexc() raise #*****************end test*************** botsglobal.db.close()
list( transform.chunk( list(transform.chunk("a nice example string", 5)), 2)), ) self.assertEqual([], list(transform.chunk(list(transform.chunk("", 5)), 2))) self.assertEqual([], list( transform.chunk(list(transform.chunk(None, 5)), 2))) def testdiacritics(self): title = "äáãàâāăąåǻȁªấặắḁÄÁÃÀÂĀĂĄÅǞǠǺȀḀ,çćĉċčÇĆĈĊČ,éëêèêēĕėęěȅềe̊ËÉẼÈÊĒĔĖĘĚȄE̊,ïíìîĩįȉÏÍĨÌÎȈ,öóõòôơỏȍÖÓÕÒÔƠȌ,üúũùûưǖǘǚǜųȕÜÚŨÙÛƯǕǗǛȔ,ḃḋďḟĝġğĞĠĜḥḤķľḷḶṁńñǹňņÑṗ̥r̥̄řŕȑȐR̥R̥̄šŞȘťṫțẘWýÿÝžźż,ðæÆÐØßø,ƎƏƐƆƇƈđłȺⱥʉ,IJij¼½⁇dz™Ⅱ⑴⑩⒜㎝㏒" self.assertEqual( "aaaaaaaaaaaaaaaaAAAAAAAAAAAAAA,cccccCCCCC,eeeeeeeeeeeeeEEEEEEEEEEEE,iiiiiiiIIIIII,ooooooooOOOOOOO,uuuuuuuuuuuuUUUUUUUUUU,bddfgggGGGhHkllLmnnnnnNprrrrRRRsSStttwWyyYzzz,,,Ii11?dTI(1(cl", transform.dropdiacritics(title), ) self.assertEqual( "äáãàâaaaåaaªaaaaÄÁÃÀÂAAAÅAAAAA,çccccÇCCCC,éëêèêeeeeeeeeËÉEÈÊEEEEEEE,ïíìîiiiÏÍIÌÎI,öóõòôoooÖÓÕÒÔOO,üúuùûuuuuuuuÜÚUÙÛUUUUU,bddfgggGGGhHkllLmnñnnnÑprrrrRRRsSStttwWýÿÝzzz,ðæÆÐØßø,,Ii¼½?dTI(1(cl", transform.dropdiacritics(title, charset="latin1"), ) if __name__ == "__main__": botsinit.generalinit("config") botsglobal.logger = botsinit.initenginelogging("engine") botsinit.connect() unittest.main() botsglobal.db.close()
self.assertEqual( comclass.filename_formatter("*_{datetime:%Y-%m-%d}.edi", ta), str(sub_unique + 5) + "_" + datetime.datetime.now().strftime("%Y-%m-%d") + ".edi", "", ) self.assertEqual( comclass.filename_formatter("*_*.edi", ta), str(sub_unique + 6) + "_" + str(sub_unique + 6) + ".edi", "" ) self.assertEqual(comclass.filename_formatter("123.edi", ta), "123.edi", "") self.assertEqual(comclass.filename_formatter("{infile}", ta), "desadv1.edi", "") self.assertEqual(comclass.filename_formatter("{infile:name}.txt", ta), "desadv1.txt", "") self.assertEqual(comclass.filename_formatter("{infile:name}.{infile:ext}", ta), "desadv1.edi", "") print("expect: <idta>.edi ", comclass.filename_formatter("{idta}.edi", ta)) self.assertRaises(botslib.CommunicationOutError, comclass.filename_formatter, "{tada}", ta) self.assertRaises(botslib.CommunicationOutError, comclass.filename_formatter, "{infile:test}", ta) if count == 1: # test only 1 incoming files break if __name__ == "__main__": pythoninterpreter = "python3.4" newcommand = [pythoninterpreter, "bots-engine.py"] subprocess.call(newcommand) botsinit.generalinit("config") botsinit.initenginelogging("engine") botsinit.connect() unittest.main() logging.shutdown() botsglobal.db.close()
def start(): try: botsinit.generalinit('config') botsinit.initenginelogging() except: print 'Error reading bots.ini (before database connection).' raise try: botsinit.connect() except: print 'Could not connect to database.' raise #*****************start test*************** domein = 'test' tests = [ (u'key1', u'leftcode'), (u'key2', u'~!@#$%^&*()_+}{:";][=-/.,<>?`'), (u'key3', u'?érýúíó?ás??lzcn?'), (u'key4', u'?ë?ÿüïöä´¨???è?ùì'), (u'key5', u'òà???UIÕÃ?Ñ`~'), (u'key6', u"a\xac\u1234\u20ac\U00008000"), (u'key7', u"abc_\u03a0\u03a3\u03a9.txt"), (u'key8', u"?ÉRÝÚÍÓ?ÁS??LZCN??"), (u'key9', u"Ë?¨YܨIÏÏÖÄ???È?ÙÌÒ`À`Z?"), ] try: #clean before test botslib.change(u'''DELETE FROM ccode ''') botslib.change(u'''DELETE FROM ccodetrigger''') except: print 'Error while deleting', botslib.txtexc() raise try: botslib.change( u'''INSERT INTO ccodetrigger (ccodeid) VALUES (%(ccodeid)s)''', {'ccodeid': domein}) for key, value in tests: botslib.change( u'''INSERT INTO ccode (ccodeid_id,leftcode,rightcode,attr1,attr2,attr3,attr4,attr5,attr6,attr7,attr8) VALUES (%(ccodeid)s,%(leftcode)s,%(rightcode)s,'1','1','1','1','1','1','1','1')''', { 'ccodeid': domein, 'leftcode': key, 'rightcode': value }) except: print 'Error while updating', botslib.txtexc() raise try: for key, value in tests: print 'key', key for row in botslib.query( u'''SELECT rightcode FROM ccode WHERE ccodeid_id = %(ccodeid)s AND leftcode = %(leftcode)s''', { 'ccodeid': domein, 'leftcode': key }): print ' ', key, type(row['rightcode']), type(value) if row['rightcode'] != value: print 'failure in test "%s": result "%s" is not equal to "%s"' % ( key, row['rightcode'], value) else: print ' OK' break else: print '??can not find testentry %s %s in db' % (key, value) except: print 'Error while quering db', botslib.txtexc() raise #*****************end test*************** botsglobal.db.close()
self.failUnless(True==botslib.checkconfirmrules('send-email-MDN',idroute='idroute',idchannel='tochannel',topartner='topartner',frompartner='frompartner',editype='x12',messagetype='messagetype')) self.failUnless(False==botslib.checkconfirmrules('send-email-MDN',idroute='otherx12',idchannel='tochannel',topartner='topartner',frompartner='frompartner',editype='x12',messagetype='messagetype')) self.failUnless(False==botslib.checkconfirmrules('send-email-MDN',idroute='idroute',idchannel='mdn2_in',topartner='topartner',frompartner='frompartner',editype='x12',messagetype='messagetype')) self.failUnless(False==botslib.checkconfirmrules('send-email-MDN',idroute='idroute',idchannel='tochannel',topartner='partnerunittest',frompartner='frompartner',editype='x12',messagetype='messagetype')) self.failUnless(False==botslib.checkconfirmrules('send-email-MDN',idroute='idroute',idchannel='tochannel',topartner='topartner',frompartner='partnerunittest',editype='x12',messagetype='messagetype')) self.failUnless(False==botslib.checkconfirmrules('send-email-MDN',idroute='otherx12',idchannel='mdn2_in',topartner='partnerunittest',frompartner='partnerunittest',editype='x12',messagetype='messagetype')) self.failUnless(True==botslib.checkconfirmrules('send-email-MDN',idroute='otherx1',idchannel='mdn2_i',topartner='partnerunittes',frompartner='partnerunittes',editype='x12',messagetype='messagetype')) if __name__ == '__main__': pythoninterpreter = 'python2.7' newcommand = [pythoninterpreter,'bots-engine.py',] shutil.rmtree(os.path.join(botssys, 'outfile'),ignore_errors=True) #remove whole output directory subprocess.call(newcommand) print('''expect: 21 files received/processed in run. 17 files without errors, 4 files with errors, 30 files send in run. ''') #connect to database etc #check nrs confirmed etc. botsinit.generalinit('config') botsinit.initenginelogging('engine') botsinit.connect() botslib.prepare_confirmrules() unittest.main() logging.shutdown() botsglobal.db.close()
def startall(): #NOTE: bots directory should always be on PYTHONPATH - otherwise it will not start. #********command line arguments************************** usage = ''' This is "%(name)s" version %(version)s, part of Bots open source edi translator (http://bots.sourceforge.net). Checks all installed bots grammars. Same checks are used as in translations with bots-engine. Usage: %(name)s -c<directory> Options: -c<directory> directory for configuration files (default: config). Examples: %(name)s -cconfig ''' % { 'name': os.path.basename(sys.argv[0]), 'version': botsglobal.version } configdir = 'config' for arg in sys.argv[1:]: if arg.startswith('-c'): configdir = arg[2:] if not configdir: print( 'Error: configuration directory indicated, but no directory name.' ) sys.exit(1) else: print(usage) sys.exit(0) #***end handling command line arguments************************** botsinit.generalinit( configdir) # find locating of bots, configfiles, init paths etc. process_name = 'grammarcheck' botsglobal.logger = botsinit.initenginelogging(process_name) atexit.register(logging.shutdown) usersysdirectory = botsglobal.ini['directories']['usersysabs'] files = glob.iglob(usersysdirectory + '/grammars/**', recursive=True) files = [f for f in files if os.path.isfile(f)] for filename in files: filename_basename = os.path.basename(filename) editype = os.path.basename(os.path.dirname(filename)) if filename_basename in ['__init__.py', '__pycache__', 'envelope.py']: continue if filename_basename.startswith( 'edifact') or filename_basename.startswith( 'records') or filename_basename.endswith('records.py'): continue if not filename_basename.endswith('py'): continue filename_noextension = os.path.splitext(filename_basename)[0] try: grammar.grammarread(editype, filename_noextension, typeofgrammarfile='grammars') except: print(botslib.txtexc(), end='\n\n') sys.exit(1) else: print('OK - no error found in grammar', filename, end='\n\n')
def start(): #NOTE: bots directory should always be on PYTHONPATH - otherwise it will not start. #********command line arguments************************** usage = ''' This is "%(name)s" version %(version)s, part of Bots open source edi translator (http://bots.sourceforge.net). Checks a Bots grammar. Same checks are used as in translations with bots-engine. Searches for grammar in regular place: bots/usersys/grammars/<editype>/<messagetype>.py (even if a path is passed). Usage: %(name)s -c<directory> <editype> <messagetype> or %(name)s -c<directory> <path to grammar> Options: -c<directory> directory for configuration files (default: config). Examples: %(name)s -cconfig edifact ORDERSD96AUNEAN008 %(name)s -cconfig C:/python27/lib/site-packages/bots/usersys/grammars/edifact/ORDERSD96AUNEAN008.py ''' % { 'name': os.path.basename(sys.argv[0]), 'version': botsglobal.version } configdir = 'config' editype = '' messagetype = '' for arg in sys.argv[1:]: if arg.startswith('-c'): configdir = arg[2:] if not configdir: print( 'Error: configuration directory indicated, but no directory name.' ) sys.exit(1) elif arg in ['?', '/?', '-h', '--help'] or arg.startswith('-'): print(usage) sys.exit(0) else: if os.path.isfile(arg): p1, p2 = os.path.split(arg) editype = os.path.basename(p1) messagetype, ext = os.path.splitext(p2) messagetype = unicode(messagetype) print('grammarcheck', editype, messagetype) elif not editype: editype = arg else: messagetype = arg if not (editype and messagetype): print( 'Error: both editype and messagetype, or a file path, are required.' ) sys.exit(1) #***end handling command line arguments************************** botsinit.generalinit( configdir) # find locating of bots, configfiles, init paths etc. process_name = 'grammarcheck' botsglobal.logger = botsinit.initenginelogging(process_name) atexit.register(logging.shutdown) try: grammar.grammarread(editype, messagetype, typeofgrammarfile='grammars') except: print('Found error in grammar: ', botslib.txtexc()) sys.exit(1) else: print('OK - no error found in grammar') sys.exit(0)