-
Notifications
You must be signed in to change notification settings - Fork 7
/
unitnode.py
171 lines (149 loc) · 7.88 KB
/
unitnode.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
from __future__ import print_function
from __future__ import unicode_literals
import os
import sys
import unittest
import shutil
import filecmp
import bots.inmessage as inmessage
import bots.outmessage as outmessage
import bots.botslib as botslib
import bots.node as node
import bots.botsinit as botsinit
import bots.botsglobal as botsglobal
if sys.version_info[0] > 2:
basestring = unicode = str
'''plugin unitnode.zip
not an acceptance tst
does not work with get_checklevel=2
'''
#fetchqueries is dynamically added to node, to retrieve and check
collectqueries = {}
def fetchqueries(self,level=0):
'''for debugging
usage: in mapping script: inn.root.displayqueries()
'''
if self.record:
tmp = self.queries
if tmp:
collectqueries[self.record['BOTSID']] = tmp
for childnode in self.children:
childnode.fetchqueries(level+1)
class Testnode(unittest.TestCase):
''' test node.py and message.py.
'''
def testedifact01(self):
inn = inmessage.parse_edi_file(editype='edifact',messagetype='invoicwithenvelope',filename='botssys/infile/unitnode/nodetest01.edi')
out = outmessage.outmessage_init(editype='edifact',messagetype='invoicwithenvelope',filename='botssys/infile/unitnode/output/inisout03.edi',divtext='',topartner='') #make outmessage object
out.root = inn.root
#* getloop **************************************
count = 0
for t in inn.getloop({'BOTSID':'XXX'}):
count += 1
self.assertEqual(count,0,'Cmplines')
count = 0
for t in inn.getloop({'BOTSID':'UNB'}):
count += 1
self.assertEqual(count,2,'Cmplines')
count = 0
for t in out.getloop({'BOTSID':'UNB'},{'BOTSID':'XXX'}):
count += 1
self.assertEqual(count,0,'Cmplines')
count = 0
for t in out.getloop({'BOTSID':'UNB'},{'BOTSID':'UNH'}):
count += 1
self.assertEqual(count,3,'Cmplines')
count = 0
for t in inn.getloop({'BOTSID':'UNB'},{'BOTSID':'UNH'},{'BOTSID':'XXX'}):
count += 1
self.assertEqual(count,0,'Cmplines')
count = 0
for t in inn.getloop({'BOTSID':'UNB'},{'BOTSID':'UNH'},{'BOTSID':'LIN'}):
count += 1
self.assertEqual(count,6,'Cmplines')
count = 0
for t in inn.getloop({'BOTSID':'UNB'},{'BOTSID':'XXX'},{'BOTSID':'LIN'},{'BOTSID':'QTY'}):
count += 1
self.assertEqual(count,0,'Cmplines')
count = 0
for t in inn.getloop({'BOTSID':'UNB'},{'BOTSID':'UNH'},{'BOTSID':'LIN'},{'BOTSID':'XXX'}):
count += 1
self.assertEqual(count,0,'Cmplines')
count = 0
for t in inn.getloop({'BOTSID':'UNB'},{'BOTSID':'UNH'},{'BOTSID':'LIN'},{'BOTSID':'QTY'}):
count += 1
self.assertEqual(count,6,'Cmplines')
#* getcount, getcountmpath **************************************
count = 0
countlist=[5,0,1]
nrsegmentslist=[132,10,12]
for t in out.getloop({'BOTSID':'UNB'},{'BOTSID':'UNH'}):
count2 = 0
for u in t.getloop({'BOTSID':'UNH'},{'BOTSID':'LIN'}):
count2 += 1
count3 = t.getcountoccurrences({'BOTSID':'UNH'},{'BOTSID':'LIN'})
self.assertEqual(t.getcount(),nrsegmentslist[count],'Cmplines')
self.assertEqual(count2,countlist[count],'Cmplines')
self.assertEqual(count3,countlist[count],'Cmplines')
count += 1
self.assertEqual(out.getcountoccurrences({'BOTSID':'UNB'},{'BOTSID':'UNH'}),count,'Cmplines')
self.assertEqual(inn.getcountoccurrences({'BOTSID':'UNB'},{'BOTSID':'UNH'}),count,'Cmplines')
self.assertEqual(inn.getcount(),sum(nrsegmentslist,4),'Cmplines')
self.assertEqual(out.getcount(),sum(nrsegmentslist,4),'Cmplines')
#* get, getnozero, countmpath, sort**************************************
for t in out.getloop({'BOTSID':'UNB'},{'BOTSID':'UNH'}):
self.assertRaises(botslib.MappingRootError,out.get,())
self.assertRaises(botslib.MappingRootError,out.getnozero,())
self.assertRaises(botslib.MappingRootError,out.get,0)
self.assertRaises(botslib.MappingRootError,out.getnozero,0)
t.sort({'BOTSID':'UNH'},{'BOTSID':'LIN','C212.7140':None})
start='0'
for u in t.getloop({'BOTSID':'UNH'},{'BOTSID':'LIN'}):
nextstart = u.get({'BOTSID':'LIN','C212.7140':None})
self.failUnless(start<nextstart)
start = nextstart
t.sort({'BOTSID':'UNH'},{'BOTSID':'LIN','1082':None})
start='0'
for u in t.getloop({'BOTSID':'UNH'},{'BOTSID':'LIN'}):
nextstart = u.get({'BOTSID':'LIN','1082':None})
self.failUnless(start<nextstart)
start = nextstart
self.assertRaises(botslib.MappingRootError,out.get,())
self.assertRaises(botslib.MappingRootError,out.getnozero,())
#~ # self.assertRaises(botslib.MpathError,out.get,())
first=True
for t in out.getloop({'BOTSID':'UNB'}):
if first:
self.assertEqual('15',t.getcountsum({'BOTSID':'UNB'},{'BOTSID':'UNH'},{'BOTSID':'LIN','1082':None}),'Cmplines')
self.assertEqual('8',t.getcountsum({'BOTSID':'UNB'},{'BOTSID':'UNH'},{'BOTSID':'LIN'},{'BOTSID':'QTY','C186.6063':'47','C186.6060':None}),'Cmplines')
self.assertEqual('0',t.getcountsum({'BOTSID':'UNB'},{'BOTSID':'UNH'},{'BOTSID':'LIN'},{'BOTSID':'QTY','C186.6063':'12','C186.6060':None}),'Cmplines')
self.assertEqual('54.4',t.getcountsum({'BOTSID':'UNB'},{'BOTSID':'UNH'},{'BOTSID':'LIN'},{'BOTSID':'MOA','C516.5025':'203','C516.5004':None}),'Cmplines')
first = False
else:
self.assertEqual('1',t.getcountsum({'BOTSID':'UNB'},{'BOTSID':'UNH'},{'BOTSID':'LIN'},{'BOTSID':'QTY','C186.6063':'47','C186.6060':None}),'Cmplines')
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()