gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-bank] 01/02: withdraw testcase -- missing exchange i


From: gnunet
Subject: [GNUnet-SVN] [taler-bank] 01/02: withdraw testcase -- missing exchange interaction mocking
Date: Wed, 15 Nov 2017 12:19:59 +0100

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

marcello pushed a commit to branch master
in repository bank.

commit 89a3315ca49be01357ad8987ab7e561e623fae97
Author: Marcello Stanisci <address@hidden>
AuthorDate: Thu Nov 9 19:30:18 2017 +0100

    withdraw testcase -- missing exchange interaction mocking
---
 talerbank/app/tests.py | 37 ++++++++++++++++++++++++++++---------
 talerbank/app/views.py |  5 +++--
 2 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/talerbank/app/tests.py b/talerbank/app/tests.py
index 84ab430..2a76f62 100644
--- a/talerbank/app/tests.py
+++ b/talerbank/app/tests.py
@@ -15,10 +15,12 @@
 #  @author Marcello Stanisci
 
 import json
+import hashlib
 from django.test import TestCase, Client
 from django.core.urlresolvers import reverse
 from django.conf import settings
 from django.contrib.auth.models import User
+from mock import patch, MagicMock, Mock
 from .models import BankAccount, BankTransaction
 from . import urls
 from .views import wire_transfer
@@ -30,28 +32,36 @@ def clear_db():
     BankTransaction.objects.all().delete()
 
 class WithdrawTestCase(TestCase):
-    # FIXME tbd
     def setUp(self):
         user_bankaccount = BankAccount(
             user=User.objects.create_user(username="test_user",
                                           password="test_password"))
         user_bankaccount.save()
+
+        exchange_bankaccount = BankAccount(
+            user=User.objects.create_user(username="test_exchange",
+                                          password=""),
+            account_no=99)
+        exchange_bankaccount.save()
     
-    def test_withdraw(self):
+    @patch('hashlib.new') # Need to patch update() and hexdigest() methods.
+    def test_withdraw(self, mocked_hashlib):
         client = Client()
+        wire_details = '''{
+            "test": {
+                "type":"test",
+                "account_number":99,  
+                "bank_uri":"http://bank.example/";,
+                "name":"example"
+            }
+        }'''
         params = {
           "amount_value": "0",
           "amount_fraction": "1",
           "amount_currency": settings.TALER_CURRENCY,
           "exchange": "http://exchange.example/";,
           "reserve_pub": "UVZ789",
-          "wire_details": '''{
-              "test":
-                  {"type":"test"},
-                  {"account_number":"99"},
-                  {"bank_uri":"http://bank.example/"},
-                  {"name":"example"}
-              }'''
+          "wire_details": wire_details.replace("\n", "").replace(" ", "")
         }
         client.post(reverse("login", urlconf=urls),
                     {"username": "test_user",
@@ -59,6 +69,15 @@ class WithdrawTestCase(TestCase):
 
         response = client.get(reverse("pin-question", urlconf=urls),
                               params)
+        # We mock hashlib in order to fake the CAPTCHA.
+        hasher = MagicMock()
+        hasher.hexdigest = MagicMock()
+        hasher.hexdigest.return_value = "0"
+        mocked_hashlib.return_value = hasher
+
+        response = client.post(reverse("pin-verify", urlconf=urls),
+                               {"pin_1": "0"})
+        print(response.content)
 
 class RegisterTestCase(TestCase):
     """User registration"""
diff --git a/talerbank/app/views.py b/talerbank/app/views.py
index 58580af..1e8d56f 100644
--- a/talerbank/app/views.py
+++ b/talerbank/app/views.py
@@ -178,9 +178,10 @@ def pin_tan_verify(request):
     hasher = hashlib.new("sha1")
     hasher.update(settings.SECRET_KEY.encode("utf-8"))
     # pin_0 is the answer given by the user
-    hasher.update(request.POST.get("pin_0").encode("utf-8"))
+    hasher.update(request.POST.get("pin_0" ,"").encode("utf-8"))
     hashed_attempt = hasher.hexdigest()
     if hashed_attempt != request.POST.get("pin_1"):
+        LOGGER.warning("Wrong CAPTCHA answer: %s vs %s" % 
(type(hashed_attempt), type(request.POST.get("pin_1"))))
         request.session["captcha_failed"] = True
         return redirect(request.POST.get("question_url", "profile"))
     # Check the session is a "pin tan" one
@@ -193,7 +194,7 @@ def pin_tan_verify(request):
                       BankAccount.objects.get(user=request.user),
                       exchange_bank_account,
                       request.session["reserve_pub"],
-                      request,
+                      request=request,
                       session_expand=dict(debt_limit=True))
     except (FVE, RFVE) as exc:
         LOGGER.warning("Not a withdrawing session")

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



reply via email to

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