Commit 3deb84a9dc6eb451798b8bdf6f3b3b5bfe09d536

Authored by Adhidarma Hadiwinoto
1 parent 8cadbe455d
Exists in master

exception handling on removeProduct

Showing 2 changed files with 16 additions and 7 deletions Side-by-side Diff

... ... @@ -35,13 +35,16 @@ def main():
35 35 return
36 36  
37 37 def removeProduct(products, product):
38   - products = products.upper()
39   -
40   - newProducts = products.split(',')
41   - newProducts.remove(product.upper())
42   -
43   - newProducts.sort()
44   - return ','.join(newProducts)
  38 + try:
  39 + products = products.upper()
  40 +
  41 + newProducts = products.split(',')
  42 + newProducts.remove(product.upper())
  43 +
  44 + newProducts.sort()
  45 + return ','.join(newProducts)
  46 + except:
  47 + return products
45 48  
46 49 if __name__ == '__main__':
47 50 main()
... ... @@ -19,3 +19,9 @@ def test_keyByRequestId():
19 19  
20 20 def test_keyByNominalDestination():
21 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'