gnunet-svn
[Top][All Lists]
Advanced

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

[taler-bank] branch master updated: fix test cases


From: gnunet
Subject: [taler-bank] branch master updated: fix test cases
Date: Tue, 25 Feb 2020 18:32:25 +0100

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

dold pushed a commit to branch master
in repository bank.

The following commit(s) were added to refs/heads/master by this push:
     new 2ce89f7  fix test cases
2ce89f7 is described below

commit 2ce89f777e70f595d3e66ec987d41309bc9a09df
Author: Florian Dold <address@hidden>
AuthorDate: Tue Feb 25 23:02:08 2020 +0530

    fix test cases
---
 talerbank/app/tests.py | 61 +++++++++++++++++---------------------------------
 talerbank/app/views.py | 17 ++++++--------
 2 files changed, 28 insertions(+), 50 deletions(-)

diff --git a/talerbank/app/tests.py b/talerbank/app/tests.py
index abbf9f3..026884b 100644
--- a/talerbank/app/tests.py
+++ b/talerbank/app/tests.py
@@ -46,7 +46,7 @@ LOGGER.setLevel(logging.DEBUG)
 
 # logging.disable(logging.CRITICAL)
 # reenable: logging.disable(logging.NOTSET)
-logging.disable(logging.NOTSET)
+#logging.disable(logging.NOTSET)
 
 
 def make_auth_line(username, password):
@@ -201,7 +201,8 @@ class RegisterTestCase(TestCase):
         # Normal case.
         response = client.post(
             reverse("register-headless", urlconf=urls),
-            {"username": "test_register_headless", "password": "password*+#@"},
+            content_type="application/json",
+            data={"username": "test_register_headless", "password": 
"password*+#@"},
         )
         self.assertEqual(200, response.status_code)
 
@@ -215,14 +216,16 @@ class RegisterTestCase(TestCase):
         # Try registering unavailable username.
         response = client.post(
             reverse("register-headless", urlconf=urls),
-            {"username": "test_register_headless", "password": "password"},
+            content_type="application/json",
+            data={"username": "test_register_headless", "password": 
"password"},
         )
         self.assertEqual(409, response.status_code)
 
         # NOTE: Django 2.2.2 allows ANY character!  Is this normal?
         response = client.post(
             reverse("register-headless", urlconf=urls),
-            {"username": "'''+++;;;'''", "password": "password2"},
+            content_type="application/json",
+            data={"username": "'''+++;;;'''", "password": "password2"},
         )
         self.assertEqual(200, response.status_code)
 
@@ -270,7 +273,7 @@ class WithdrawHeadlessTestCase(TestCase):
         # Gets account #2, in line with config.
         BankAccount(
             user=User.objects.create_user(
-                username="normal_exchange", password="normal_password"
+                username="Exchange", password="some_password"
             ),
             account_no=2,
         ).save()
@@ -278,12 +281,10 @@ class WithdrawHeadlessTestCase(TestCase):
     def test_withdraw_headless(self):
         client = Client()
 
-        # Use default exchange.
-        data = (
-            '{"auth": {"type": "basic"}, \
-                 "reserve_pub": "RESERVEPUB", \
-                 "amount": "%s:10"}'
-            % settings.TALER_CURRENCY
+        data=dict(
+                reserve_pub="FAKERESERVEPUB",
+                amount=f"{settings.TALER_CURRENCY}:10",
+                exchange_payto_uri="payto://x-taler-bank/localhost/Exchange",
         )
         response = client.post(
             reverse("withdraw-headless", urlconf=urls),
@@ -295,45 +296,25 @@ class WithdrawHeadlessTestCase(TestCase):
         self.assertEqual(200, response.status_code)
 
         # Try withdrawing more than owning.
-        data = (
-            '{"auth": {"type": "basic"}, \
-                 "reserve_pub": "RESERVEPUB", \
-                 "amount": "%s:100"}'
-            % settings.TALER_CURRENCY
+        settings.TALER_MAX_DEBT = f"{settings.TALER_CURRENCY}:0"
+        data=dict(
+                reserve_pub="FAKERESERVEPUB",
+                amount=f"{settings.TALER_CURRENCY}:101",
+                exchange_payto_uri="payto://x-taler-bank/localhost/Exchange",
         )
         response = client.post(
             reverse("withdraw-headless", urlconf=urls),
             data=data,
             content_type="application/json",
-            follow=True,
             HTTP_AUTHORIZATION=make_auth_line("headless_wallet", 
"headless_password"),
         )
         self.assertEqual(406, response.status_code)
 
-        # Try withdrawing giving exchange field.
-        data = (
-            '{"auth": {"type": "basic"}, \
-                 "exchange_wire_details": 
"payto://x-taler-bank/bank.example.com/2", \
-                 "reserve_pub": "RESERVEPUB", \
-                 "amount": "%s:0.4"}'
-            % settings.TALER_CURRENCY
-        )
-        response = client.post(
-            reverse("withdraw-headless", urlconf=urls),
-            data=data,
-            content_type="application/json",
-            follow=True,
-            HTTP_AUTHORIZATION=make_auth_line("headless_wallet", 
"headless_password"),
-        )
-        self.assertEqual(200, response.status_code)
-
         # Try withdrawing giving non-existent recipient.
-        data = (
-            '{"auth": {"type": "basic"}, \
-                 "exchange_wire_details": 
"payto://x-taler-bank/bank.example.com/2222", \
-                 "reserve_pub": "RESERVEPUB", \
-                 "amount": "%s:0.4"}'
-            % settings.TALER_CURRENCY
+        data=dict(
+                reserve_pub="FAKERESERVEPUB",
+                amount=f"{settings.TALER_CURRENCY}:101",
+                
exchange_payto_uri="payto://x-taler-bank/localhost/idonotexist",
         )
         response = client.post(
             reverse("withdraw-headless", urlconf=urls),
diff --git a/talerbank/app/views.py b/talerbank/app/views.py
index ca1afb2..f2ec50a 100644
--- a/talerbank/app/views.py
+++ b/talerbank/app/views.py
@@ -961,7 +961,6 @@ def withdraw_headless(request, user):
     """
     Serves a headless withdrawal request for the Taler protocol.
     """
-
     data = WithdrawHeadless(json.loads(decode_body(request)))
     h = get_plain_host(request)
     sender_payto = f"payto://x-taler-bank/{h}/{user.username}"
@@ -969,15 +968,13 @@ def withdraw_headless(request, user):
 
     exchange_payto = data.get("exchange_payto_uri")
     if not exchange_payto:
-        return JsonResponse(dict(hint="exchange_payto_uri missig"))
-    exchange_accno = get_acct_from_payto(exchange_payto)
-
+        return JsonResponse(dict(hint="exchange_payto_uri missig"), status=400)
+    exchange_account_name = get_acct_from_payto(exchange_payto)
     try:
-        exchange_bankaccount = 
BankAccount.objects.get(account_no=exchange_accno)
-    except ObjectDoesNotExist:
-        err = dict(hint="Bank account not found")
-        return JsonResponse(err, status=404)
-
+        exchange_user = User.objects.get(username=exchange_account_name)
+    except User.DoesNotExist:
+        return JsonResponse(dict(hint="exchange bank account does not exist"), 
status=404)
+    exchange_bankaccount = exchange_user.bankaccount
     wire_transfer(
         Amount.parse(data.get("amount")),
         user.bankaccount,
@@ -1191,7 +1188,7 @@ def wire_transfer(amount, debit_account, credit_account, 
subject, request_uid=No
                     status=409,
                 )
 
-    LOGGER.debug(
+    LOGGER.info(
         "transfering %s => %s, %s, %s"
         % (
             debit_account.user.username,

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



reply via email to

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