gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-bank] branch master updated: tolerating fraction-les


From: gnunet
Subject: [GNUnet-SVN] [taler-bank] branch master updated: tolerating fraction-less amount strings
Date: Mon, 11 Dec 2017 15:28:16 +0100

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository bank.

The following commit(s) were added to refs/heads/master by this push:
     new a7ec665  tolerating fraction-less amount strings
a7ec665 is described below

commit a7ec665872f45acd6821d0f24575f1cd9fb88736
Author: Marcello Stanisci <address@hidden>
AuthorDate: Mon Dec 11 15:27:39 2017 +0100

    tolerating fraction-less amount strings
---
 setup.py                | 3 ++-
 talerbank/app/amount.py | 4 ++--
 talerbank/app/tests.py  | 4 ++++
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/setup.py b/setup.py
index 4bfdc5c..b2f2988 100755
--- a/setup.py
+++ b/setup.py
@@ -12,7 +12,8 @@ setup(name='talerbank',
                         "psycopg2",
                         "requests",
                         "uWSGI",
-                        "validictory"
+                        "validictory",
+                        "mock"
                         ],
 
       package_data={
diff --git a/talerbank/app/amount.py b/talerbank/app/amount.py
index c3e2b93..5e1f68c 100644
--- a/talerbank/app/amount.py
+++ b/talerbank/app/amount.py
@@ -63,14 +63,14 @@ class Amount:
     # instantiating an amount object.
     @classmethod
     def parse(cls, amount_str: str):
-        exp = r'^\s*([-_*A-Za-z0-9]+):([0-9]+)\.([0-9]+)\s*$'
+        exp = r'^\s*([-_*A-Za-z0-9]+):([0-9]+)\.?([0-9]+)?\s*$'
         import re
         parsed = re.search(exp, amount_str)
         if not parsed:
             raise BadFormatAmount(amount_str)
         value = int(parsed.group(2))
         fraction = 0
-        for i, digit in enumerate(parsed.group(3)):
+        for i, digit in enumerate(parsed.group(3) or "0"):
             fraction += int(int(digit) * (Amount._fraction() / 10 ** (i+1)))
         return cls(parsed.group(1), value, fraction)
 
diff --git a/talerbank/app/tests.py b/talerbank/app/tests.py
index 35374c6..5f9e67b 100644
--- a/talerbank/app/tests.py
+++ b/talerbank/app/tests.py
@@ -476,6 +476,10 @@ class ParseAmountTestCase(TestCase):
         self.assertJSONEqual('{"value": 4, "fraction": 0, "currency": 
"KUDOS"}', ret.dump())
         ret = Amount.parse("KUDOS:4.3")
         self.assertJSONEqual('{"value": 4, "fraction": 30000000, "currency": 
"KUDOS"}', ret.dump())
+        ret = Amount.parse("KUDOS:4")
+        self.assertJSONEqual('{"value": 4, "fraction": 0, "currency": 
"KUDOS"}', ret.dump())
+        ret = Amount.parse("KUDOS:4.") # forbid?
+        self.assertJSONEqual('{"value": 4, "fraction": 0, "currency": 
"KUDOS"}', ret.dump())
         try:
             Amount.parse("Buggy")
         except BadFormatAmount:

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]