[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [taler-bank] 04/06: testing operations with wrong currencie
From: |
gnunet |
Subject: |
[GNUnet-SVN] [taler-bank] 04/06: testing operations with wrong currencies |
Date: |
Mon, 29 May 2017 11:25:19 +0200 |
This is an automated email from the git hooks/post-receive script.
marcello pushed a commit to branch master
in repository bank.
commit a3aa43006dd791bd54ef256318c7b0f89aabed19
Author: Marcello Stanisci <address@hidden>
AuthorDate: Wed May 24 16:47:20 2017 +0200
testing operations with wrong currencies
---
talerbank/app/tests_err.py | 59 +++++++++++++++++++++++++++++++++-------------
talerbank/app/views.py | 13 ++--------
2 files changed, 45 insertions(+), 27 deletions(-)
diff --git a/talerbank/app/tests_err.py b/talerbank/app/tests_err.py
index 36c6ce7..26b1ae7 100644
--- a/talerbank/app/tests_err.py
+++ b/talerbank/app/tests_err.py
@@ -39,12 +39,7 @@ class RegisterTestCase(TestCase):
def setUp(self):
bank = User.objects.create_user(username='Bank')
- # The bank user currency will differ from the currency used
- # to create the new user's account, so a currency mismatch is
- # expected when the 100 KUDOS will be attempted to be given
- # to the new user.
- # This scenario expects a 500 Internal server error response to
- # be returned
+ # Activating this user with a faulty currency.
ba = BankAccount(user=bank, currency="XYZ")
ba.account_no = 1
ba.save()
@@ -58,6 +53,10 @@ class RegisterTestCase(TestCase):
{"username": "test_register",
"password": "test_register"},
follow=True)
+ # A currency mismatch is expected when the 100 KUDOS will be
+ # attempted to be given to the new user.
+ # This scenario expects a 500 Internal server error response to
+ # be returned.
self.assertEqual(500, response.status_code)
@@ -74,26 +73,32 @@ class LoginTestCase(TestCase):
def tearDown(self):
clearDb()
- # Bad credentials will be sent, so a xz response is expected
- # to be returned
def test_login(self):
c = Client()
+ # Sending non existent credentials.
response = c.post(reverse("login", urlconf=urls),
{"username": "test_user",
"password": "test_passwordoo"},
follow=True)
- self.assertNotEqual(200, response.status_code)
+ # The current logic -- django's default -- returns 200 OK
+ # even when the login didn't succeed.
+ # So the test here ensures that the bank just doesn't crash.
+ self.assertEqual(200, response.status_code)
class AmountTestCase(TestCase):
+ # Trying to compare amount of different currencies
def test_cmp(self):
a1 = dict(value=1, fraction=0, currency="X")
- _a1 = dict(value=1, fraction=0, currency="X")
- a2 = dict(value=2, fraction=0, currency="X")
- self.assertEqual(-1, amounts.amount_cmp(a1, a2))
- self.assertEqual(1, amounts.amount_cmp(a2, a1))
- self.assertEqual(0, amounts.amount_cmp(a1, _a1))
+ a2 = dict(value=2, fraction=0, currency="Y")
+ try:
+ amounts.amount_cmp(a1, a2)
+ except amounts.CurrencyMismatchException:
+ self.assertTrue(True)
+ return
+ # Should never get here
+ self.assertTrue(False)
class AddIncomingTestCase(TestCase):
"""Test money transfer's API"""
@@ -110,6 +115,11 @@ class AddIncomingTestCase(TestCase):
bank_account.save()
user_account.save()
+ no1 = BankAccount.objects.get(account_no=1)
+ no2 = BankAccount.objects.get(account_no=2)
+ logger.info("1 username: %s" % no1.user.username)
+ logger.info("2 username: %s" % no2.user.username)
+
def tearDown(self):
clearDb()
@@ -124,11 +134,12 @@ class AddIncomingTestCase(TestCase):
"fraction": 0, \
"currency": "%s"}}' \
% settings.TALER_CURRENCY
+ # Trying with wrong credentials
response = c.post(reverse("add-incoming", urlconf=urls),
data=data,
content_type="application/json",
- follow=True, **{"HTTP_X_TALER_BANK_USERNAME":
"user_user", "HTTP_X_TALER_BANK_PASSWORD": "user_password"})
- self.assertEqual(200, response.status_code)
+ follow=True, **{"HTTP_X_TALER_BANK_USERNAME":
"user_useroo", "HTTP_X_TALER_BANK_PASSWORD": "user_passwordoo"})
+ self.assertEqual(401, response.status_code)
data = '{"auth": {"type": "basic"}, \
"credit_account": 1, \
"wtid": "TESTWTID", \
@@ -138,11 +149,27 @@ class AddIncomingTestCase(TestCase):
"fraction": 0, \
"currency": "%s"}}' \
% "WRONGCURRENCY"
+ # Trying with wrong currency
response = c.post(reverse("add-incoming", urlconf=urls),
data=data,
content_type="application/json",
follow=True, **{"HTTP_X_TALER_BANK_USERNAME":
"user_user", "HTTP_X_TALER_BANK_PASSWORD": "user_password"})
self.assertEqual(406, response.status_code)
+ # Trying to go debit
+ data = '{"auth": {"type": "basic"}, \
+ "credit_account": 1, \
+ "wtid": "TESTWTID", \
+ "exchange_url": "https://exchange.test", \
+ "amount": \
+ {"value": 60, \
+ "fraction": 0, \
+ "currency": "%s"}}' \
+ % settings.TALER_CURRENCY
+ response = c.post(reverse("add-incoming", urlconf=urls),
+ data=data,
+ content_type="application/json",
+ follow=True, **{"HTTP_X_TALER_BANK_USERNAME":
"user_user", "HTTP_X_TALER_BANK_PASSWORD": "user_password"})
+
class HistoryTestCase(TestCase):
diff --git a/talerbank/app/views.py b/talerbank/app/views.py
index 77decc8..87696b1 100644
--- a/talerbank/app/views.py
+++ b/talerbank/app/views.py
@@ -64,15 +64,6 @@ def javascript_licensing(request):
def login_view(request):
just_logged_out = get_session_flag(request, "just_logged_out")
- if "POST" == request.method:
- login_form = MyAuthenticationForm(request.POST)
- if login_form.is_valid():
- username = login_form.cleaned_data["username"]
- password = login_form.cleaned_data["password"]
- logger.info("u:%s, p:%s" % (username, password))
- else:
- logger.error("Bad form gotten in POST")
- return HttpResponseBadRequest("Bad form POSTed")
response = django.contrib.auth.views.login(
request,
authentication_form=MyAuthenticationForm,
@@ -571,11 +562,11 @@ def wire_transfer(amount,
msg = "The amount to be transferred (%s) doesn't match the bank's
currency (%s)" % (amount["currency"], settings.TALER_CURRENCY)
status_code = 406
if settings.TALER_CURRENCY != credit_account.balance_obj["currency"]:
- logger.error("Internal inconsistency: credit account's currency
(%s) differs from bank's one (%s)" % (credit_account.balance_obj["currency"],
settings.TALER_CURRENCY))
+ logger.error("Internal inconsistency: credit account's currency
(%s) differs from bank's (%s)" % (credit_account.balance_obj["currency"],
settings.TALER_CURRENCY))
msg = "Internal server error"
status_code = 500
elif settings.TALER_CURRENCY != debit_account.balance_obj["currency"]:
- logger.error("Internal inconsistency: debit account's currency
(%s) differs from bank's one (%s)" % (debit_account.balance_obj["currency"],
settings.TALER_CURRENCY))
+ logger.error("Internal inconsistency: debit account's currency
(%s) differs from bank's (%s)" % (debit_account.balance_obj["currency"],
settings.TALER_CURRENCY))
msg = "Internal server error"
status_code = 500
logger.error(msg)
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [taler-bank] branch master updated (9430850 -> 05d86a1), gnunet, 2017/05/29
- [GNUnet-SVN] [taler-bank] 06/06: commenting out faults-injected tests, gnunet, 2017/05/29
- [GNUnet-SVN] [taler-bank] 03/06: Add manual authentication before logging a user in. Just calling login() without authenticating the user before, returns 200 even for wrong login attempts., gnunet, 2017/05/29
- [GNUnet-SVN] [taler-bank] 05/06: removing unneeded comments, gnunet, 2017/05/29
- [GNUnet-SVN] [taler-bank] 04/06: testing operations with wrong currencies,
gnunet <=
- [GNUnet-SVN] [taler-bank] 01/06: addressing #5013, gnunet, 2017/05/29
- [GNUnet-SVN] [taler-bank] 02/06: first tests under erroneous circumstances, gnunet, 2017/05/29