[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [taler-bank] 02/09: provide __str__ to custom exceptions
From: |
gnunet |
Subject: |
[GNUnet-SVN] [taler-bank] 02/09: provide __str__ to custom exceptions |
Date: |
Tue, 05 Dec 2017 13:21:44 +0100 |
This is an automated email from the git hooks/post-receive script.
marcello pushed a commit to branch master
in repository bank.
commit 3611f616fb9cd91a3fb41c6e8d01f2f7e6ae574f
Author: Marcello Stanisci <address@hidden>
AuthorDate: Mon Dec 4 15:07:36 2017 +0100
provide __str__ to custom exceptions
---
talerbank/app/amount.py | 4 ++--
talerbank/app/tests.py | 7 +++----
talerbank/app/views.py | 8 ++++++--
3 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/talerbank/app/amount.py b/talerbank/app/amount.py
index 0453c35..2edf1cb 100644
--- a/talerbank/app/amount.py
+++ b/talerbank/app/amount.py
@@ -101,7 +101,7 @@ class Amount:
# Add the given amount to this one
def add(self, amount):
if self.currency != amount.currency:
- raise CurrencyMismatch()
+ raise CurrencyMismatch("%s vs %s" % (am1.currency, am2.currency))
self.value += amount.value
self.fraction += amount.fraction
self.__normalize()
@@ -109,7 +109,7 @@ class Amount:
# Subtract passed amount from this one
def subtract(self, amount):
if self.currency != amount.currency:
- raise CurrencyMismatch()
+ raise CurrencyMismatch("%s vs %s" % (am1.currency, am2.currency))
if self.fraction < amount.fraction:
self.fraction += Amount.FRACTION()
self.value -= 1
diff --git a/talerbank/app/tests.py b/talerbank/app/tests.py
index 3d2dfe8..a207c00 100644
--- a/talerbank/app/tests.py
+++ b/talerbank/app/tests.py
@@ -27,6 +27,9 @@ from . import urls
from .views import wire_transfer
from .amount import Amount, CurrencyMismatch, BadFormatAmount
+LOGGER = logging.getLogger()
+LOGGER.setLevel(logging.WARNING)
+
def clear_db():
User.objects.all().delete()
BankAccount.objects.all().delete()
@@ -422,7 +425,6 @@ class MeasureHistory(TestCase):
# Make sure logging level is WARNING, otherwise the loop
# will overwhelm the console.
- logging.getLogger().setLevel(logging.WARNING)
for i in range(self.ntransfers):
wire_transfer(Amount(settings.TALER_CURRENCY, 1),
self.user_bankaccount0,
@@ -437,8 +439,5 @@ class MeasureHistory(TestCase):
setup="from talerbank.app.views import
extract_history",
globals=locals())
total_time = timer.timeit(number=1)
- logging.getLogger().setLevel(logging.INFO)
- logging.getLogger().info("%d records needed %.3f secs" \
- % (self.ntransfers, total_time))
allowed_time_per_record = 0.0017
self.assertLess(total_time, self.ntransfers*allowed_time_per_record)
diff --git a/talerbank/app/views.py b/talerbank/app/views.py
index 994ffc2..2a38279 100644
--- a/talerbank/app/views.py
+++ b/talerbank/app/views.py
@@ -49,7 +49,11 @@ from .schemas import (validate_pin_tan_args,
check_withdraw_session,
LOGGER = logging.getLogger(__name__)
class DebtLimitExceededException(Exception):
- pass
+ def __init__(self, msg):
+ self.msg = msg
+ def __str__(self):
+ return self.msg
+
class SameAccountException(Exception):
pass
@@ -576,7 +580,7 @@ def wire_transfer(amount, debit_account, credit_account,
subject, **kwargs):
" % json.dumps(debit_account.amount.dump()))
LOGGER.info("%s's threshold is: '%s'.\
" % (debit_account.user.username,
json.dumps(threshold.dump())))
- raise DebtLimitExceededException()
+ raise DebtLimitExceededException("Debt limit exceeded")
with transaction.atomic():
debit_account.save()
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [taler-bank] branch master updated (c8f9b7a -> 3d1d4bb), gnunet, 2017/12/05
- [GNUnet-SVN] [taler-bank] 04/09: remove fixme, gnunet, 2017/12/05
- [GNUnet-SVN] [taler-bank] 02/09: provide __str__ to custom exceptions,
gnunet <=
- [GNUnet-SVN] [taler-bank] 09/09: remove initial checks. They pollute tests, and the way the bank is launched makes sure they always pass. Moreover, they check for obvious conditions like: is a 'Bank' user present? Is a database accessible?, gnunet, 2017/12/05
- [GNUnet-SVN] [taler-bank] 03/09: linting, gnunet, 2017/12/05
- [GNUnet-SVN] [taler-bank] 07/09: default log level = warning, gnunet, 2017/12/05
- [GNUnet-SVN] [taler-bank] 05/09: done linting talerconfig, gnunet, 2017/12/05
- [GNUnet-SVN] [taler-bank] 08/09: linting models. WARNING/NOTE: tests passed but this change altered - although did NOT break - the recommended way to use the model API., gnunet, 2017/12/05
- [GNUnet-SVN] [taler-bank] 01/09: port to django2, gnunet, 2017/12/05
- [GNUnet-SVN] [taler-bank] 06/09: linting done with views, gnunet, 2017/12/05