gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-bank] 02/05: fix query of non-existent future /histo


From: gnunet
Subject: [GNUnet-SVN] [taler-bank] 02/05: fix query of non-existent future /history element
Date: Sat, 06 May 2017 22:30:44 +0200

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

marcello pushed a commit to branch master
in repository bank.

commit 5b0ff06f7471981ee8d07f1314098e1dc9dcbe70
Author: Marcello Stanisci <address@hidden>
AuthorDate: Sat May 6 21:55:27 2017 +0200

    fix query of non-existent future /history element
---
 talerbank/app/tests.py |  7 ++++++-
 talerbank/app/views.py | 26 ++++++++++----------------
 2 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/talerbank/app/tests.py b/talerbank/app/tests.py
index 5215591..17a8399 100644
--- a/talerbank/app/tests.py
+++ b/talerbank/app/tests.py
@@ -22,6 +22,7 @@ from .models import BankAccount
 from . import urlsadmin, urls
 from . import amounts
 from .views import wire_transfer
+import json
 
 import logging
 
@@ -111,7 +112,11 @@ class HistoryTestCase(TestCase):
         response = c.get(reverse("history", urlconf=urls), {"auth": "basic", 
"delta": "+4"},
                          **{"HTTP_X_TALER_BANK_USERNAME": "User", 
"HTTP_X_TALER_BANK_PASSWORD": "Password"})
         self.assertEqual(200, response.status_code)
-
+        # Get non-existent record: the latest plus one in the future
+        response = c.get(reverse("history", urlconf=urls), {"auth": "basic", 
"delta": "+1", "start": "5"},
+                         **{"HTTP_X_TALER_BANK_USERNAME": "User", 
"HTTP_X_TALER_BANK_PASSWORD": "Password"})
+        data = response.content.decode("utf-8")
+        logger.info(json.dumps(data))
 
 # This tests whether a bank account goes red and then
 # goes green again
diff --git a/talerbank/app/views.py b/talerbank/app/views.py
index 62fa6be..fe8652d 100644
--- a/talerbank/app/views.py
+++ b/talerbank/app/views.py
@@ -105,7 +105,6 @@ def profile_page(request):
         just_registered=just_registered,
         no_initial_bonus=no_initial_bonus,
     )
-    logger.info("Profile context: '%s'", json.dumps(context))
     if settings.TALER_SUGGESTED_EXCHANGE:
         context["suggested_exchange"] = settings.TALER_SUGGESTED_EXCHANGE
 
@@ -255,14 +254,11 @@ def register(request):
         return render(request, "register.html", dict(not_available=True))
     with transaction.atomic():
         user = User.objects.create_user(username=username, password=password)
-        logger.info("Registering user using '%s' currency", 
settings.TALER_CURRENCY)
         user_account = BankAccount(user=user, currency=settings.TALER_CURRENCY)
         user_account.save()
     bank_internal_account = BankAccount.objects.get(account_no=1)
     amount = dict(value=100, fraction=0, currency=settings.TALER_CURRENCY)
     try:
-        logger.info("debit account: '%s', credit account: '%s'" % \
-                     (bank_internal_account.user.username, 
user_account.user.username))
         wire_transfer(amount, bank_internal_account, user_account, "Joining 
bonus")
     except DebtLimitExceededException:
         logger.info("Debt situation encountered")
@@ -341,11 +337,11 @@ def history(request):
     delta = request.GET.get("delta")
     if not delta:
         return HttpResponseBadRequest()
-    parsed_delta = re.search("(\+)([0-9]+)", delta)
+    parsed_delta = re.search("([\+-])([0-9]+)", delta)
     try:
         parsed_delta.group(0)
     except AttributeError:
-        return JasonResponse(dict(error="Bad 'delta' parameter"), status=400)
+        return JsonResponse(dict(error="Bad 'delta' parameter"), status=400)
     delta = int(parsed_delta.group(2))
     # start
     start = request.GET.get("start")
@@ -378,8 +374,12 @@ def history(request):
     if "debit" == direction:
         query_string = Q(debit_account=target_account)
 
-    # FIXME problem with 'sign_filter'
-    qs = BankTransaction.objects.filter(query_string, 
sign_filter).order_by("%sid" % sign)[:delta]
+    # FIXME problem with 204 No content.  A query of +1 with the
+    # latest as the start makes the system crash.
+
+    qs = BankTransaction.objects.filter(query_string, sign_filter)
+    if 0 < qs.count():
+        qs = qs.order_by("%sid" % sign)[:delta]
     for entry in qs:
         counterpart = entry.credit_account.user.username
         sign_ = "-"
@@ -389,7 +389,8 @@ def history(request):
         history.append(dict(counterpart=counterpart,
                             amount=entry.amount_obj,
                             sign=sign_,
-                            subject=entry.subject))
+                            subject=entry.subject,
+                            row_id=entry.id))
 
     return JsonResponse(dict(data=history), status=200)
 
@@ -410,14 +411,9 @@ def auth_and_login(request):
         return JsonResponse(dict(error="auth method not supported"),
                             status=405)        
 
-    
-    logging.info(request.META.keys())
-
     username = request.META.get("HTTP_X_TALER_BANK_USERNAME")
     password = request.META.get("HTTP_X_TALER_BANK_PASSWORD")
 
-    logging.info("Authenticating '%s'/'%s'" % (username, password))
-
     if not username or not password:
         return False
 
@@ -435,7 +431,6 @@ def add_incoming(request):
     This view is CSRF exempt, since it is not used from
     within the browser, and only over the private admin interface.
     """
-    logger.info("Handling /admin/add/incoming.")
     data = json.loads(request.body.decode("utf-8"))
     subject = "%s %s" % (data["wtid"], data["exchange_url"])
     try:
@@ -454,7 +449,6 @@ def add_incoming(request):
         return JsonResponse(dict(error="authentication failed"),
                              status=401)
 
-    logger.info("Submitting wire transfer: '%s'", subject)
     try:
         credit_account = BankAccount.objects.get(user=data["credit_account"])
     except BankAccount.DoesNotExist:

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



reply via email to

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