[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [taler-bank] 06/09: linting done with views
From: |
gnunet |
Subject: |
[GNUnet-SVN] [taler-bank] 06/09: linting done with views |
Date: |
Tue, 05 Dec 2017 13:21:48 +0100 |
This is an automated email from the git hooks/post-receive script.
marcello pushed a commit to branch master
in repository bank.
commit 5745f9ee2c2007d69cbf51810de99ac3fe8bbb09
Author: Marcello Stanisci <address@hidden>
AuthorDate: Tue Dec 5 12:48:23 2017 +0100
linting done with views
---
talerbank/app/tests.py | 36 ++++++++++++++++++------------------
talerbank/app/views.py | 10 ++++------
2 files changed, 22 insertions(+), 24 deletions(-)
diff --git a/talerbank/app/tests.py b/talerbank/app/tests.py
index d249f13..3a74f5f 100644
--- a/talerbank/app/tests.py
+++ b/talerbank/app/tests.py
@@ -37,23 +37,23 @@ def clear_db():
class WithdrawTestCase(TestCase):
def setUp(self):
- user_bankaccount = BankAccount(
- user=User.objects.create_user(username="test_user",
- password="test_password"),
- account_no=100)
- user_bankaccount.save()
-
- exchange_bankaccount = BankAccount(
- user=User.objects.create_user(username="test_exchange",
- password=""),
- account_no=99)
- exchange_bankaccount.save()
+ BankAccount(
+ user=User.objects.create_user(
+ username="test_user",
+ password="test_password"),
+ account_no=100).save()
+
+ BankAccount(
+ user=User.objects.create_user(
+ username="test_exchange",
+ password=""),
+ account_no=99).save()
+ self.client = Client()
@patch('hashlib.new') # Need to patch update() and hexdigest() methods.
@patch('requests.post')
@patch('time.time')
def test_withdraw(self, mocked_time, mocked_post, mocked_hashlib):
- client = Client()
wire_details = '''{
"test": {
"type":"test",
@@ -70,10 +70,10 @@ class WithdrawTestCase(TestCase):
"reserve_pub": "UVZ789",
"wire_details": wire_details.replace("\n", "").replace(" ", "")
}
- client.login(username="test_user", password="test_password")
+ self.client.login(username="test_user", password="test_password")
- client.get(reverse("pin-question", urlconf=urls),
- params)
+ self.client.get(reverse("pin-question", urlconf=urls),
+ params)
# We mock hashlib in order to fake the CAPTCHA.
hasher = MagicMock()
hasher.hexdigest = MagicMock()
@@ -83,8 +83,8 @@ class WithdrawTestCase(TestCase):
post.status_code = 200
mocked_post.return_value = post
mocked_time.return_value = 0
- client.post(reverse("pin-verify", urlconf=urls),
- {"pin_1": "0"})
+ self.client.post(reverse("pin-verify", urlconf=urls),
+ {"pin_1": "0"})
expected_json = {
"reserve_pub": "UVZ789",
"execution_date": "/Date(0)/",
@@ -329,7 +329,6 @@ class HistoryTestCase(TestCase):
except (json.JSONDecodeError, KeyError):
data = {}
- # FIXME print urls which break the test.
self.assertEqual(data.get(ctx.expected_resp.get("field")),
ctx.expected_resp.get("value"))
self.assertEqual(ctx.expected_resp.get("status"),
@@ -426,6 +425,7 @@ class MeasureHistory(TestCase):
# Make sure logging level is WARNING, otherwise the loop
# will overwhelm the console.
for i in range(self.ntransfers):
+ del i # to pacify PEP checkers
wire_transfer(Amount(settings.TALER_CURRENCY, 1),
self.user_bankaccount0,
self.user_bankaccount,
diff --git a/talerbank/app/views.py b/talerbank/app/views.py
index 2a38279..eebb49f 100644
--- a/talerbank/app/views.py
+++ b/talerbank/app/views.py
@@ -49,10 +49,8 @@ from .schemas import (validate_pin_tan_args,
check_withdraw_session,
LOGGER = logging.getLogger(__name__)
class DebtLimitExceededException(Exception):
- def __init__(self, msg):
- self.msg = msg
- def __str__(self):
- return self.msg
+ def __init__(self):
+ super().__init__("Debt limit exceeded")
class SameAccountException(Exception):
pass
@@ -532,7 +530,7 @@ def wire_transfer_exc_handler(view_func):
return wraps(view_func)(_decorator)
@wire_transfer_exc_handler
-def wire_transfer(amount, debit_account, credit_account, subject, **kwargs):
+def wire_transfer(amount, debit_account, credit_account, subject):
LOGGER.info("%s => %s, %s, %s" %
(debit_account.account_no,
credit_account.account_no,
@@ -580,7 +578,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("Debt limit exceeded")
+ raise DebtLimitExceededException()
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, 2017/12/05
- [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 <=