added last movement number handling from configuration
authorMauro Scomparin <scompo@gmail.com>
Thu, 5 Jul 2018 21:31:15 +0000 (23:31 +0200)
committerMauro Scomparin <scompo@gmail.com>
Thu, 5 Jul 2018 21:31:15 +0000 (23:31 +0200)
money/money.py
money/tests/test_money.py

index ba0e08106914c26dac9124c74cca08dd40c813d5..a61dabf8a05b829ffaa5fe78c307683eec81241a 100755 (executable)
@@ -5,6 +5,7 @@ from decimal import *
 import json
 
 DATA_FILE_NAME = 'dataFile'
+LAST_MOVEMENT_NUMBER = 'latestMovementsNumber'
 CONFIG_FILE_NAME = 'money-config.json'
 CONFIG_FILE_LOCATION = expanduser('~') + CONFIG_FILE_NAME
 
@@ -124,7 +125,7 @@ def riassunto_dati():
     else:
         resulting_config = default_config
     file_dati = get_file_dati(resulting_config)
-    riassunto(file_dati)
+    riassunto(file_dati, resulting_config)
 
 
 def override_default_configuration(default_conf, other_conf):
@@ -132,6 +133,8 @@ def override_default_configuration(default_conf, other_conf):
     if other_conf:
         if DATA_FILE_NAME in other_conf:
             result_conf[DATA_FILE_NAME] = other_conf[DATA_FILE_NAME]
+        if LAST_MOVEMENT_NUMBER in other_conf:
+            result_conf[LAST_MOVEMENT_NUMBER] = other_conf[LAST_MOVEMENT_NUMBER]
     return result_conf
 
 
@@ -170,10 +173,10 @@ def ordina(dati):
 
 
 def default_configuration():
-    return {DATA_FILE_NAME: 'movimenti.dat'}
+    return {DATA_FILE_NAME: 'movimenti.dat', LAST_MOVEMENT_NUMBER: 5}
 
 
-def riassunto(file_dati):
+def riassunto(file_dati, conf):
     dati = carica_file(file_dati)
     dati_ordinati = ordina(dati)
     val_attuale = Decimal('0')
@@ -190,6 +193,6 @@ def riassunto(file_dati):
     print('guadagni complessivi:', str(guadagni_tot))
     print('spese complessive:', str(spese_tot))
     print('ultimi 5 movimenti:')
-    for i in range(5):
+    for i in range(conf[LAST_MOVEMENT_NUMBER]):
         if i < len(dati_ordinati):
             print(dati_ordinati[i])
index 30f7b10882483c2e6895e838e555ba4afba286d1..30756e678d2a3f363046d6836fa2def32d78a4ee 100644 (file)
@@ -21,6 +21,8 @@ class MoneyTest(unittest.TestCase):
         conf = money.default_configuration()
         self.assertTrue(money.DATA_FILE_NAME in conf)
         self.assertEqual(conf[money.DATA_FILE_NAME], 'movimenti.dat')
+        self.assertTrue(money.LAST_MOVEMENT_NUMBER in conf)
+        self.assertEqual(conf[money.LAST_MOVEMENT_NUMBER], 5)
 
     def test_file_exists(self):
         with tempfile.TemporaryFile() as fp:
@@ -28,10 +30,12 @@ class MoneyTest(unittest.TestCase):
 
     def test_override_default_configuration(self):
         def_conf = money.default_configuration()
-        new_conf = {money.DATA_FILE_NAME: 'new-file.dat'}
+        new_conf = {money.DATA_FILE_NAME: 'new-file.dat', money.LAST_MOVEMENT_NUMBER : 10}
         res = money.override_default_configuration(def_conf, new_conf)
         self.assertTrue(money.DATA_FILE_NAME in res)
         self.assertEqual(res[money.DATA_FILE_NAME], 'new-file.dat')
+        self.assertTrue(money.LAST_MOVEMENT_NUMBER in res)
+        self.assertEqual(res[money.LAST_MOVEMENT_NUMBER], 10)
 
     def test_ordina_ore(self):
         date = [