-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit_multi_1.py
275 lines (264 loc) · 16.4 KB
/
unit_multi_1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
from __future__ import print_function
from __future__ import unicode_literals
import filecmp
import os
import sys
import logging
import subprocess
import glob
#import bots-modules
import utilsunit
import bots.botslib as botslib
import bots.botsinit as botsinit
import bots.botsglobal as botsglobal
import bots.transform as transform
from bots.botsconfig import *
if sys.version_info[0] > 2:
basestring = unicode = str
'''
plugin 'unit_multi_1'
enable routes
not an acceptance test.
'''
def test_plugin():
for row in botslib.query(u'''SELECT COUNT(*) as count
FROM partner
WHERE isgroup = %(isgroup)s ''',
{'isgroup':False}):
if row[str('count')] != 5:
raise Exception('error partner count')
break
else:
raise Exception('no partner count?')
for row in botslib.query(u'''SELECT COUNT(*) as count
FROM partner
WHERE isgroup = %(isgroup)s ''',
{'isgroup':True}):
if row[str('count')] != 3:
raise Exception('error partner count')
break
else:
raise Exception('no partner count?')
for row in botslib.query(u'''SELECT COUNT(*) as count
FROM partnergroup
WHERE from_partner_id=%(from_partner_id)s ''',
{'from_partner_id':'plugintest1'}):
if row[str('count')] != 3:
raise Exception('error partner count')
break
else:
raise Exception('no partner count?')
for row in botslib.query(u'''SELECT to_partner_id
FROM partnergroup
WHERE from_partner_id=%(from_partner_id)s ''',
{'from_partner_id':'plugintest2'}):
if row[str('to_partner_id')] != 'plugingroup2':
raise Exception('error partner count')
for row in botslib.query(u'''SELECT COUNT(*) as count
FROM partnergroup
WHERE to_partner_id=%(to_partner_id)s ''',
{'to_partner_id':'plugingroup2'}):
if row[str('count')] != 2:
raise Exception('error partner count')
break
else:
raise Exception('no partner count?')
def test_ccode_with_unicode():
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.changeq(u'''DELETE FROM ccode ''')
botslib.changeq(u'''DELETE FROM ccodetrigger''')
except:
print('Error while deleting: ',botslib.txtexc())
raise
try:
botslib.changeq(u'''INSERT INTO ccodetrigger (ccodeid)
VALUES (%(ccodeid)s)''',
{'ccodeid':domein})
for key,value in tests:
botslib.changeq(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[str('rightcode')]),type(value))
if row[str('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
def test_unique_in_run_counter():
if 1 != int(transform.unique_runcounter('test')):
raise Exception('test_unique_in_run_counter')
if 1 != int(transform.unique_runcounter('test2')):
raise Exception('test_unique_in_run_counter')
if 2 != int(transform.unique_runcounter('test')):
raise Exception('test_unique_in_run_counter')
if 3 != int(transform.unique_runcounter('test')):
raise Exception('test_unique_in_run_counter')
if 2 != int(transform.unique_runcounter('test2')):
raise Exception('test_unique_in_run_counter')
def test_partner_lookup():
for s in [str('attr1'),str('attr2'),str('attr3'),str('attr4'),str('attr5')]:
if transform.partnerlookup('test',s) != s:
raise Exception('test_partner_lookup')
#test lookup for not existing partner
idpartner = 'partner_not_there'
if transform.partnerlookup(idpartner,'attr1',safe=True) != idpartner:
raise Exception('test_partner_lookup')
try:
transform.partnerlookup(idpartner,'attr1')
except botslib.CodeConversionError as msg:
pass
else:
raise Exception('expect exception in test_partner_lookup')
#test lookup where no value is in the database
idpartner = 'test2'
if transform.partnerlookup(idpartner,str('attr1')) != 'attr1':
raise Exception('test_partner_lookup')
try:
transform.partnerlookup(idpartner,str('attr2'))
except botslib.CodeConversionError as msg:
pass
else:
raise Exception('expect exception in test_partner_lookup')
def grammartest(l,expect_error=True):
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)
if ta_externout[str('botskey')] != 'BOTSKEY01':
raise Exception('testreference: botskey not OK')
ta_externout = utilsunit.getlastta(PARSED)
if ta_externout[str('reference')] != 'UNBREF01':
raise Exception('testreference: unb ref not OK')
ta_externout = utilsunit.getlastta(SPLITUP)
if ta_externout[str('reference')] != 'BOTSKEY01':
raise Exception('testreference: botskey not OK')
if ta_externout[str('botskey')] != 'BOTSKEY01':
raise Exception('testreference: botskey not OK')
ta_externout = utilsunit.getlastta(TRANSLATED)
if ta_externout[str('reference')] != 'BOTSKEY01':
raise Exception('testreference: botskey not OK')
if ta_externout[str('botskey')] != 'BOTSKEY01':
raise Exception('testreference: botskey not OK')
#test KECA charset **********************************************************************************************************************
utilsunit.RunTestCompareResults([pythoninterpreter,'bots-engine.py','testkeca'],
{'status':0,'lastreceived':1,'lasterror':0,'lastdone':1,'lastok':0,'lastopen':0,'send':1,'processerrors':0,'filesize':333})
utilsunit.RunTestCompareResults([pythoninterpreter,'bots-engine.py','testkeca2'],
{'status':0,'lastreceived':1,'lasterror':0,'lastdone':1,'lastok':0,'lastopen':0,'send':1,'processerrors':0,'filesize':333})
#mailbag **********************************************************************************************************************
utilsunit.RunTestCompareResults([pythoninterpreter,'bots-engine.py','mailbagtest'],
{'status':0,'lastreceived':18,'lasterror':0,'lastdone':18,'lastok':0,'lastopen':0,'send':44,'processerrors':0,'filesize':39344})
#passthroughtest **********************************************************************************************************************
utilsunit.RunTestCompareResults([pythoninterpreter,'bots-engine.py','passthroughtest'],
{'status':0,'lastreceived':4,'lasterror':0,'lastdone':4,'lastok':0,'lastopen':0,'send':4,'processerrors':0,'filesize':7346})
#botsidnr **********************************************************************************************************************
utilsunit.RunTestCompareResults([pythoninterpreter,'bots-engine.py','test_botsidnr','test_changedelete'],
{'status':0,'lastreceived':2,'lasterror':0,'lastdone':2,'lastok':0,'lastopen':0,'send':4,'processerrors':0,'filesize':5813})
infile ='infile/test_botsidnr/compare/unitnodebotsidnr1.edi'
outfile='outfile/test_botsidnr/unitnodebotsidnr1.edi'
infile2 ='infile/test_botsidnr/compare/unitnodebotsidnr2.edi'
outfile2='outfile/test_botsidnr/unitnodebotsidnr2.edi'
if not filecmp.cmp(os.path.join(botssys,infile),os.path.join(botssys,outfile)):
raise Exception('error in file compare')
if not filecmp.cmp(os.path.join(botssys,infile2),os.path.join(botssys,outfile2)):
raise Exception('error in file2 compare')
#****************************************************************************************************************************************
test_ccode_with_unicode()
#****************************************************************************************************************************************
test_unique_in_run_counter()
#****************************************************************************************************************************************
test_partner_lookup()
#****************************************************************************************************************************************
#testgrammar: tricky grammars and messages (collision tests). these test should run OK (no grammar-errors, reading & writing OK, extra checks in mappings scripts have to be OK
utilsunit.RunTestCompareResults([pythoninterpreter,'bots-engine.py','testgrammar'],
{'status':0,'lastreceived':8,'lasterror':0,'lastdone':8,'lastok':0,'lastopen':0,'send':9,'processerrors':0,'filesize':2329})
#grammar/Collision testing****************************************************************************************************************************************
grammartest([pythoninterpreter,'bots-grammarcheck.py','edifact','CONDRAD96AUNERR001'])
grammartest([pythoninterpreter,'bots-grammarcheck.py','edifact','CONDRAD96AUNERR002'])
grammartest([pythoninterpreter,'bots-grammarcheck.py','edifact','CONDRAD96AUNERR003'])
grammartest([pythoninterpreter,'bots-grammarcheck.py','edifact','CONDRAD96AUNERR004'])
grammartest([pythoninterpreter,'bots-grammarcheck.py','edifact','CONDRAD96AUNERR005'])
grammartest([pythoninterpreter,'bots-grammarcheck.py','edifact','CONDRAD96AUNERR006'])
grammartest([pythoninterpreter,'bots-grammarcheck.py','edifact','CONDRAD96AUNbackcollision2'])
grammartest([pythoninterpreter,'bots-grammarcheck.py','edifact','CONDRAD96AUNbackcollision3'])
grammartest([pythoninterpreter,'bots-grammarcheck.py','edifact','CUSCARD96AUNnestedcollision1'])
grammartest([pythoninterpreter,'bots-grammarcheck.py','edifact','CUSCARD96AUNnestedcollision2'])
grammartest([pythoninterpreter,'bots-grammarcheck.py','edifact','CUSCARD96AUNnestedcollision3'])
grammartest([pythoninterpreter,'bots-grammarcheck.py','edifact','DELFORD96AUNbackcollision'])
grammartest([pythoninterpreter,'bots-grammarcheck.py','edifact','DELJITD96AUNbackcollision'])
grammartest([pythoninterpreter,'bots-grammarcheck.py','edifact','INVRPTD96AUNnestingcollision'])
grammartest([pythoninterpreter,'bots-grammarcheck.py','edifact','CONDRAD96AUNno'],expect_error=False)
grammartest([pythoninterpreter,'bots-grammarcheck.py','edifact','CONDRAD96AUNno2'],expect_error=False)
grammartest([pythoninterpreter,'bots-grammarcheck.py','edifact','CONESTD96AUNno'],expect_error=False)
grammartest([pythoninterpreter,'bots-grammarcheck.py','edifact','CONESTD96AUNno2'],expect_error=False)
grammartest([pythoninterpreter,'bots-grammarcheck.py','edifact','CUSCARD96AUNno'],expect_error=False)
#plugin testing: check if right entries have been read (partners/patnergroups)********************************************************************
test_plugin()
#csv_orders_inputtest (csv with records too big.small.not correct ending etc)********************************************************************
utilsunit.RunTestCompareResults([pythoninterpreter,'bots-engine.py','csv_orders_inputtest'],
{'status':1,'lastreceived':5,'lasterror':2,'lastdone':3,'lastok':0,'lastopen':0,'send':3,'processerrors':0,'filesize':131})
#testextendedalt function****************************************************************************************************************************************
utilsunit.RunTestCompareResults([pythoninterpreter,'bots-engine.py','testextendedalt'],
{'status':0,'lastreceived':1,'lasterror':0,'lastdone':1,'lastok':0,'lastopen':0,'send':3,'processerrors':0,'filesize':261})
#testincomingmime ****************************************************************************************************************************************
utilsunit.RunTestCompareResults([pythoninterpreter,'bots-engine.py','testincomingmime'],
{'status':1,'lastreceived':5,'lasterror':5,'lastdone':0,'lastok':0,'lastopen':0,'send':0,'processerrors':0,'filesize':22592})
#****************************************************************************************************************************************
utilsunit.RunTestCompareResults([pythoninterpreter,'bots-engine.py','testxml_outspecials'],
{'status':0,'lastreceived':2,'lasterror':0,'lastdone':2,'lastok':0,'lastopen':0,'send':2,'processerrors':0,'filesize':1337})
cmpfile ='infile/testxml_outspecials/compare/01xml02OK.xml'
outfilepath='outfile/testxml_outspecials/*'
for filename in glob.glob(os.path.join(botssys,outfilepath)):
if not filecmp.cmp(os.path.join(botssys,cmpfile),filename):
raise Exception('error in file compare')
#****************************************************************************************************************************************
#mailbag **********************************************************************************************************************
utilsunit.RunTestCompareResults([pythoninterpreter,'bots-engine.py','maxsizeinfile'],
{'status':1,'lastreceived':1,'lasterror':1,'lastdone':0,'lastok':0,'lastopen':0,'send':0,'processerrors':0,'filesize':6702825})
#****************************************************************************************************************************************
#****************************************************************************************************************************************
logging.shutdown()
botsglobal.db.close
print('Tests OK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' )