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()
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()
if expect_error: if not subprocess.call(l): raise Exception('grammartest: expected error, but no error') else: if subprocess.call(l): raise Exception( 'grammartest: expected no error, but received an error') if __name__ == '__main__': pythoninterpreter = 'python2.7' botsinit.generalinit('config') utilsunit.dummylogger() utilsunit.cleanoutputdir() botssys = botsglobal.ini.get('directories', 'botssys') botsinit.connect() #************************************************************************************************************************************** #test references ********************************************************************************************************************** utilsunit.RunTestCompareResults( [pythoninterpreter, 'bots-engine.py', 'testreference'], { 'status': 0, 'lastreceived': 1, 'lasterror': 0, 'lastdone': 1, 'lastok': 0, 'lastopen': 0, 'send': 1, 'processerrors': 0, 'filesize': 262 }) ta_externout = utilsunit.getlastta(EXTERNOUT)
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()