Commit 3deb84a9dc6eb451798b8bdf6f3b3b5bfe09d536
1 parent
8cadbe455d
Exists in
master
exception handling on removeProduct
Showing 2 changed files with 16 additions and 7 deletions Inline Diff
sate24.py
1 | def parsePullMessage(message): | 1 | def parsePullMessage(message): |
2 | task = { | 2 | task = { |
3 | 'status': 'NONE' | 3 | 'status': 'NONE' |
4 | } | 4 | } |
5 | 5 | ||
6 | if message == 'NONE': | 6 | if message == 'NONE': |
7 | return task | 7 | return task |
8 | 8 | ||
9 | values = message.split(';') | 9 | values = message.split(';') |
10 | try: | 10 | try: |
11 | 11 | ||
12 | task = { | 12 | task = { |
13 | 'status': values[0], | 13 | 'status': values[0], |
14 | 'requestId': values[1], | 14 | 'requestId': values[1], |
15 | 'timestamp': values[3], | 15 | 'timestamp': values[3], |
16 | 'destination': values[4], | 16 | 'destination': values[4], |
17 | 'member': values[5], | 17 | 'member': values[5], |
18 | 'gateway_type': values[6], | 18 | 'gateway_type': values[6], |
19 | 'product': values[7], | 19 | 'product': values[7], |
20 | 'city': values[8] | 20 | 'city': values[8] |
21 | } | 21 | } |
22 | 22 | ||
23 | except: | 23 | except: |
24 | task | 24 | task |
25 | 25 | ||
26 | return task | 26 | return task |
27 | 27 | ||
28 | def keyByRequestId(chipinfo, requestId): | 28 | def keyByRequestId(chipinfo, requestId): |
29 | return str(chipinfo) + '.trx.requestId:' + str(requestId) | 29 | return str(chipinfo) + '.trx.requestId:' + str(requestId) |
30 | 30 | ||
31 | def keyByNominalDestination(chipinfo, nominal, destination): | 31 | def keyByNominalDestination(chipinfo, nominal, destination): |
32 | return str(chipinfo) + '.trx.nominal:' + str(nominal) + '.destination:' + str(destination) | 32 | return str(chipinfo) + '.trx.nominal:' + str(nominal) + '.destination:' + str(destination) |
33 | 33 | ||
34 | def main(): | 34 | def main(): |
35 | return | 35 | return |
36 | 36 | ||
37 | def removeProduct(products, product): | 37 | def removeProduct(products, product): |
38 | products = products.upper() | 38 | try: |
39 | 39 | products = products.upper() | |
40 | newProducts = products.split(',') | 40 | |
41 | newProducts.remove(product.upper()) | 41 | newProducts = products.split(',') |
42 | 42 | newProducts.remove(product.upper()) | |
43 | newProducts.sort() | 43 | |
44 | return ','.join(newProducts) | 44 | newProducts.sort() |
45 | return ','.join(newProducts) | ||
46 | except: | ||
47 | return products | ||
45 | 48 | ||
46 | if __name__ == '__main__': | 49 | if __name__ == '__main__': |
47 | main() | 50 | main() |
48 | 51 |
test_sate24.py
1 | import sate24 | 1 | import sate24 |
2 | 2 | ||
3 | def test_parsePullMessage(): | 3 | def test_parsePullMessage(): |
4 | task = sate24.parsePullMessage('NONE') | 4 | task = sate24.parsePullMessage('NONE') |
5 | assert task['status'] == 'NONE' | 5 | assert task['status'] == 'NONE' |
6 | 6 | ||
7 | task = sate24.parsePullMessage('OK;181380;181359;20150323155308;02199994004;ADHISIMON;aaa_pull;E5;DKI_JAKARTA;0;;') | 7 | task = sate24.parsePullMessage('OK;181380;181359;20150323155308;02199994004;ADHISIMON;aaa_pull;E5;DKI_JAKARTA;0;;') |
8 | assert task['status'] == 'OK' | 8 | assert task['status'] == 'OK' |
9 | assert task['requestId'] == '181380' | 9 | assert task['requestId'] == '181380' |
10 | assert task['timestamp'] == '20150323155308' | 10 | assert task['timestamp'] == '20150323155308' |
11 | assert task['destination'] == '02199994004' | 11 | assert task['destination'] == '02199994004' |
12 | assert task['member'] == 'ADHISIMON' | 12 | assert task['member'] == 'ADHISIMON' |
13 | assert task['gateway_type'] == 'aaa_pull' | 13 | assert task['gateway_type'] == 'aaa_pull' |
14 | assert task['product'] == 'E5' | 14 | assert task['product'] == 'E5' |
15 | assert task['city'] == 'DKI_JAKARTA' | 15 | assert task['city'] == 'DKI_JAKARTA' |
16 | 16 | ||
17 | def test_keyByRequestId(): | 17 | def test_keyByRequestId(): |
18 | assert sate24.keyByRequestId('TEST', '123') == 'TEST.trx.requestId:123' | 18 | assert sate24.keyByRequestId('TEST', '123') == 'TEST.trx.requestId:123' |
19 | 19 | ||
20 | def test_keyByNominalDestination(): | 20 | def test_keyByNominalDestination(): |
21 | assert sate24.keyByNominalDestination('TEST', '5000', '08180818') == 'TEST.trx.nominal:5000.destination:08180818' | 21 | assert sate24.keyByNominalDestination('TEST', '5000', '08180818') == 'TEST.trx.nominal:5000.destination:08180818' |
22 | |||
23 | def test_removeProduct(): | ||
24 | assert sate24.removeProduct('XL5,XL10', 'XL5') == 'XL10' | ||
25 | assert sate24.removeProduct('XL5,XL10', 'XL10') == 'XL5' | ||
26 | assert sate24.removeProduct('XL10', 'XL10') == '' | ||
27 | assert sate24.removeProduct('XL5,XL10', 'XL50') == 'XL5,XL10' | ||
22 | 28 |