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: do not trigger /admin/a


From: gnunet
Subject: [GNUnet-SVN] [taler-bank] branch master updated: do not trigger /admin/add/incoming at the exchange upon withdrawal.
Date: Thu, 14 Dec 2017 15:52:48 +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 ec0d72c  do not trigger /admin/add/incoming at the exchange upon 
withdrawal.
ec0d72c is described below

commit ec0d72c624cfd10c32b310313fe0ff05feed21ad
Author: Marcello Stanisci <address@hidden>
AuthorDate: Thu Dec 14 15:47:07 2017 +0100

    do not trigger /admin/add/incoming at the exchange
    upon withdrawal.
---
 talerbank/app/schemas.py |  4 +--
 talerbank/app/tests.py   | 81 +++++++++++++++++++++++++-----------------------
 talerbank/app/views.py   | 25 ++-------------
 3 files changed, 45 insertions(+), 65 deletions(-)

diff --git a/talerbank/app/schemas.py b/talerbank/app/schemas.py
index 9e02400..d65b082 100644
--- a/talerbank/app/schemas.py
+++ b/talerbank/app/schemas.py
@@ -37,7 +37,6 @@ WITHDRAW_SESSION_SCHEMA = {
     "type": "object",
     "properties": {
         "amount": {"type": AMOUNT_SCHEMA},
-        "exchange_url": {"type": "string"},
         "reserve_pub": {"type": "string"},
         "exchange_account_number": {"type": "integer"},
         "sender_wiredetails": {
@@ -109,7 +108,6 @@ INCOMING_REQUEST_SCHEMA = {
     "properties": {
         "amount": {"type": AMOUNT_SCHEMA},
         "subject": {"type": "string"},
-        "exchange_url": {"type": "string"},
         "credit_account": {"type": "integer"},
         "auth": AUTH_SCHEMA
     }
@@ -123,7 +121,7 @@ PIN_TAN_ARGS = {
         "amount_currency": {"type": "string"},
         "exchange": {"type": "string"},
         "reserve_pub": {"type": "string"},
-        "wire_details": {"format": "wiredetails_string"}
+        "exchange_wire_details": {"format": "wiredetails_string"}
     }
 }
 
diff --git a/talerbank/app/tests.py b/talerbank/app/tests.py
index cc26710..1cba338 100644
--- a/talerbank/app/tests.py
+++ b/talerbank/app/tests.py
@@ -41,26 +41,29 @@ def clear_db():
         cursor.execute("ALTER SEQUENCE app_banktransaction_id_seq RESTART")
 class WithdrawTestCase(TestCase):
     def setUp(self):
-        BankAccount(
+        self.user_bank_account = BankAccount(
             user=User.objects.create_user(
                 username="test_user",
                 password="test_password"),
-            account_no=100).save()
+            account_no=100)
+        self.user_bank_account.save()
 
-        BankAccount(
+        self.exchange_bank_account = BankAccount(
             user=User.objects.create_user(
                 username="test_exchange",
                 password=""),
-            account_no=99).save()
+            account_no=99)
+        self.exchange_bank_account.save()
         self.client = Client()
 
     def tearDown(self):
         clear_db()
 
+    @patch('talerbank.app.views.wire_transfer')
     @patch('hashlib.new')
-    @patch('requests.post')
     @patch('time.time')
-    def test_withdraw(self, mocked_time, mocked_post, mocked_hashlib):
+    def test_withdraw(self, mocked_time,
+                      mocked_hashlib, mocked_wire_transfer):
         wire_details = '''{
             "test": {
                 "type":"test",
@@ -69,45 +72,43 @@ class WithdrawTestCase(TestCase):
                 "name":"example"
             }
         }'''
+        amount = Amount(settings.TALER_CURRENCY, 0, 1)
         params = {
-            "amount_value": "0",
-            "amount_fraction": "1",
-            "amount_currency": settings.TALER_CURRENCY,
-            "exchange": "http://exchange.example/";,
+            "amount_value": str(amount.value),
+            "amount_fraction": str(amount.fraction),
+            "amount_currency": amount.currency,
             "reserve_pub": "UVZ789",
-            "wire_details": wire_details.replace("\n", "").replace(" ", "")
+            "exchange": "https://exchange.example.com/";,
+            "exchange_wire_details":
+                wire_details.replace("\n", "").replace(" ", "")
         }
-        self.client.login(username="test_user", password="test_password")
+        self.client.login(username="test_user",
+                          password="test_password")
 
-        self.client.get(reverse("pin-question", urlconf=urls),
-                        params)
+        response = self.client.get(
+            reverse("pin-question", urlconf=urls),
+            params)
+        self.assertEqual(response.status_code, 200)
         # We mock hashlib in order to fake the CAPTCHA.
         hasher = MagicMock()
         hasher.hexdigest = MagicMock()
         hasher.hexdigest.return_value = "0"
         mocked_hashlib.return_value = hasher
-        post = MagicMock()
-        post.status_code = 200
-        mocked_post.return_value = post
         mocked_time.return_value = 0
-        self.client.post(reverse("pin-verify", urlconf=urls),
-                         {"pin_1": "0"})
-        expected_json = {
-            "reserve_pub": "UVZ789",
-            "execution_date": "/Date(0)/",
-            "sender_account_details": {
-                "type": "test",
-                "bank_uri": "http://testserver/";,
-                "account_number": 100
-                },
-            "transfer_details": {"timestamp": 0},
-            "amount": {
-                "value": 0,
-                "fraction": 1,
-                "currency": settings.TALER_CURRENCY}
-        }
-        
mocked_post.assert_called_with("http://exchange.example/admin/add/incoming";,
-                                       json=expected_json)
+
+        response = self.client.post(
+            reverse("pin-verify", urlconf=urls),
+            {"pin_1": "0"})
+        
+        args, kwargs = mocked_wire_transfer.call_args
+
+        self.assertTrue(
+            args[0].dump() == amount.dump() \
+            and self.user_bank_account in args \
+            and "UVZ789" in args \
+            and self.exchange_bank_account in args \
+            and kwargs.get("session_expand") == \
+                {"debt_limit": True})
 
     def tearDown(self):
         clear_db()
@@ -115,10 +116,12 @@ class WithdrawTestCase(TestCase):
 class InternalWireTransferTestCase(TestCase):
 
     def setUp(self):
-        BankAccount(user=User.objects.create_user(username='give_money',
-                                                  password="gm")).save()
-        BankAccount(user=User.objects.create_user(username='take_money'),
-                    account_no=88).save()
+        BankAccount(user=User.objects.create_user(
+            username='give_money',
+            password="gm")).save()
+        BankAccount(user=User.objects.create_user(
+            username='take_money'),
+            account_no=88).save()
 
     def tearDown(self):
         clear_db()
diff --git a/talerbank/app/views.py b/talerbank/app/views.py
index 725715c..d65d38a 100644
--- a/talerbank/app/views.py
+++ b/talerbank/app/views.py
@@ -199,16 +199,16 @@ def pin_tan_question(request):
         # Currency is not checked, as any mismatches will be
         # detected afterwards
     except (FVE, RFVE) as err:
+        LOGGER.error("invalid '%s'" % err.fieldname)
         return HRBR("invalid '%s'" % err.fieldname)
     user_account = BankAccount.objects.get(user=request.user)
-    wd = json.loads(request.GET["wire_details"])
+    wd = json.loads(request.GET["exchange_wire_details"])
     request.session["exchange_account_number"] = \
         wd["test"]["account_number"]
     amount = Amount(request.GET["amount_currency"],
                     int(request.GET["amount_value"]),
                     int(request.GET["amount_fraction"]))
     request.session["amount"] = amount.dump()
-    request.session["exchange_url"] = request.GET["exchange"]
     request.session["reserve_pub"] = request.GET["reserve_pub"]
     request.session["sender_wiredetails"] = dict(
         type="test",
@@ -259,27 +259,6 @@ def pin_tan_verify(request):
             status=404)
     except WireTransferException as exc:
         return exc.response
-    res = requests.post(
-        urljoin(request.session["exchange_url"],
-                "admin/add/incoming"),
-        json={"reserve_pub": request.session["reserve_pub"],
-              "execution_date":
-                  "/Date(" + str(int(time.time())) + ")/",
-              "sender_account_details":
-                  request.session["sender_wiredetails"],
-              "transfer_details":
-                  {"timestamp": int(time.time() * 1000)},
-              "amount": amount.dump()})
-    if res.status_code != 200:
-        return render(
-            request,
-            "error_exchange.html",
-            {"message": "Could not transfer funds to the"
-                        "exchange. The exchange (%s) gave"
-                        "a bad response." \
-                        % request.session["exchange_url"],
-             "response_text": res.text,
-             "response_status": res.status_code})
     request.session["just_withdrawn"] = True
     return redirect("profile")
 

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



reply via email to

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