forked from eppye-bots/bots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unitconfirm.py
250 lines (231 loc) · 12.5 KB
/
unitconfirm.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
from __future__ import print_function
from __future__ import unicode_literals
import unittest
import filecmp
import glob
import shutil
import os
import sys
import subprocess
import logging
import utilsunit
import bots.botslib as botslib
import bots.botsinit as botsinit
import bots.botsglobal as botsglobal
from bots.botsconfig import *
if sys.version_info[0] > 2:
basestring = unicode = str
'''
plugin unitconfirm.zip
active all routes
before each run: clear transactions!
tested is:
- seperate unit tests
- total expectation of whole run
- seperate unit-tests to check confirm-rules
'''
botssys = 'bots/botssys'
class TestMain(unittest.TestCase):
def testroutetestmdn(self):
lijst = utilsunit.getdir(os.path.join(botssys,'outfile/confirm/mdn/*'))
self.failUnless(len(lijst)==0)
nr_rows = 0
for row in botslib.query(u'''SELECT idta,confirmed,confirmidta
FROM ta
WHERE status=%(status)s
AND statust=%(statust)s
AND idroute=%(idroute)s
AND confirmtype=%(confirmtype)s
AND confirmasked=%(confirmasked)s
AND frommail != ''
ORDER BY idta DESC
''',
{'status':220,'statust':DONE,'idroute':'testmdn','confirmtype':'send-email-MDN','confirmasked':True}):
nr_rows += 1
print(row[str('idta')],row[str('confirmed')],row[str('confirmidta')])
self.failUnless(row[str('confirmed')])
self.failUnless(row[str('confirmidta')]!=0)
else:
self.failUnless(nr_rows==1)
nr_rows = 0
for row in botslib.query(u'''SELECT idta,confirmed,confirmidta
FROM ta
WHERE status=%(status)s
AND statust=%(statust)s
AND idroute=%(idroute)s
AND confirmtype=%(confirmtype)s
AND confirmasked=%(confirmasked)s
AND frommail != ''
ORDER BY idta DESC
''',
{'status':500,'statust':DONE,'idroute':'testmdn','confirmtype':'ask-email-MDN','confirmasked':True}):
nr_rows += 1
self.failUnless(row[str('confirmed')])
self.failUnless(row[str('confirmidta')]!=0)
else:
self.failUnless(nr_rows==1)
def testroutetestmdn2(self):
lijst = utilsunit.getdir(os.path.join(botssys,'outfile/confirm/mdn2/*'))
self.failUnless(len(lijst)==0)
nr_rows = 0
for row in botslib.query(u'''SELECT idta,confirmed,confirmidta
FROM ta
WHERE status=%(status)s
AND statust=%(statust)s
AND idroute=%(idroute)s
AND confirmtype=%(confirmtype)s
AND confirmasked=%(confirmasked)s
AND frommail != ''
ORDER BY idta DESC
''',
{'status':500,'statust':DONE,'idroute':'testmdn2','confirmtype':'ask-email-MDN','confirmasked':True}):
nr_rows += 1
self.failUnless(not row[str('confirmed')])
self.failUnless(row[str('confirmidta')]==0)
else:
self.failUnless(nr_rows==1)
def testrouteotherx12(self):
lijst = utilsunit.getdir(os.path.join(botssys,'outfile/confirm/otherx12/*'))
self.failUnless(len(lijst)==15)
def testroutetest997(self):
'''
test997 1: pickup 850*1 ask confirm 850*2 gen & send 850*2
send confirm 850*1 gen & send 997*1
test997 2: receive 997*1 confirm 850*1 gen xml*1
receive 850*2 ask confirm 850*3 gen 850*3
send confirm 850*2 gen & send 997*2
test997 3: receive 997*2 confirm 850*2 gen & send xml (to trash)
send 850*3 (to trash)
send xml (to trash)
'''
lijst = utilsunit.getdir(os.path.join(botssys,'outfile/confirm/x12/*'))
self.failUnless(len(lijst)==0)
lijst = utilsunit.getdir(os.path.join(botssys,'outfile/confirm/trash/*'))
self.failUnless(len(lijst)==6)
counter=0
for row in botslib.query(u'''SELECT idta,confirmed,confirmidta
FROM ta
WHERE status=%(status)s
AND statust=%(statust)s
AND idroute=%(idroute)s
AND confirmtype=%(confirmtype)s
AND confirmasked=%(confirmasked)s
ORDER BY idta DESC
''',
{'status':400,'statust':DONE,'idroute':'test997','confirmtype':'ask-x12-997','confirmasked':True}):
counter += 1
if counter == 1:
self.failUnless(not row[str('confirmed')])
self.failUnless(row[str('confirmidta')]==0)
elif counter == 2:
self.failUnless(row[str('confirmed')])
self.failUnless(row[str('confirmidta')]!=0)
else:
break
else:
self.failUnless(counter!=0)
for row in botslib.query(u'''SELECT idta,confirmed,confirmidta
FROM ta
WHERE status=%(status)s
AND statust=%(statust)s
AND idroute=%(idroute)s
AND confirmtype=%(confirmtype)s
AND confirmasked=%(confirmasked)s
ORDER BY idta DESC
''',
{'status':310,'statust':DONE,'idroute':'test997','confirmtype':'send-x12-997','confirmasked':True}):
counter += 1
if counter <= 2:
self.failUnless(row[str('confirmed')])
self.failUnless(row[str('confirmidta')]!=0)
else:
break
else:
self.failUnless(counter!=0)
def testroutetestcontrl(self):
'''
test997 1: pickup ORDERS*1 ask confirm ORDERS*2 gen & send ORDERS*2
send confirm ORDERS*1 gen & send CONTRL*1
test997 2: receive CONTRL*1 confirm ORDERS*1 gen xml*1
receive ORDERS*2 ask confirm ORDERS*3 gen ORDERS*3
send confirm ORDERS*2 gen & send CONTRL*2
test997 3: receive CONTRL*2 confirm ORDERS*2 gen & send xml (to trash)
send ORDERS*3 (to trash)
send xml (to trash)
'''
lijst = utilsunit.getdir(os.path.join(botssys,'outfile/confirm/edifact/*'))
self.failUnless(len(lijst)==0)
lijst = utilsunit.getdir(os.path.join(botssys,'outfile/confirm/trash/*'))
self.failUnless(len(lijst)==6)
counter=0
for row in botslib.query(u'''SELECT idta,confirmed,confirmidta
FROM ta
WHERE status=%(status)s
AND statust=%(statust)s
AND idroute=%(idroute)s
AND confirmtype=%(confirmtype)s
AND confirmasked=%(confirmasked)s
ORDER BY idta DESC
''',
{'status':400,'statust':DONE,'idroute':'testcontrl','confirmtype':'ask-edifact-CONTRL','confirmasked':True}):
counter += 1
if counter == 1:
self.failUnless(not row[str('confirmed')])
self.failUnless(row[str('confirmidta')]==0)
elif counter == 2:
self.failUnless(row[str('confirmed')])
self.failUnless(row[str('confirmidta')]!=0)
else:
break
else:
self.failUnless(counter!=0)
for row in botslib.query(u'''SELECT idta,confirmed,confirmidta
FROM ta
WHERE status=%(status)s
AND statust=%(statust)s
AND idroute=%(idroute)s
AND confirmtype=%(confirmtype)s
AND confirmasked=%(confirmasked)s
ORDER BY idta DESC
''',
{'status':310,'statust':DONE,'idroute':'testcontrl','confirmtype':'send-edifact-CONTRL','confirmasked':True}):
counter += 1
if counter <= 2:
self.failUnless(row[str('confirmed')])
self.failUnless(row[str('confirmidta')]!=0)
else:
break
else:
self.failUnless(counter!=0)
def testconfirmrulesdirect(self):
self.failUnless(True==botslib.checkconfirmrules('send-x12-997',idroute='idroute',idchannel='tochannel',topartner='topartner',frompartner='frompartner',editype='x12',messagetype='messagetype'))
self.failUnless(True==botslib.checkconfirmrules('send-x12-997',idroute='idroute',idchannel='tochannel',topartner='topartner',frompartner='frompartner',editype='x12',messagetype='justfortes'))
self.failUnless(True==botslib.checkconfirmrules('send-x12-997',idroute='idroute',idchannel='tochannel',topartner='topartner',frompartner='frompartner',editype='x12',messagetype='justfortest2'))
self.failUnless(False==botslib.checkconfirmrules('send-x12-997',idroute='idroute',idchannel='tochannel',topartner='topartner',frompartner='frompartner',editype='x12',messagetype='justfortest'))
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()