[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [taler-bank] branch master updated (4c48839 -> c511745)
From: |
gnunet |
Subject: |
[GNUnet-SVN] [taler-bank] branch master updated (4c48839 -> c511745) |
Date: |
Sat, 06 May 2017 22:30:42 +0200 |
This is an automated email from the git hooks/post-receive script.
marcello pushed a change to branch master
in repository bank.
from 4c48839 deploy FIXME
new 5168b65 sign & delta dealt with. testing needed.
new 5b0ff06 fix query of non-existent future /history element
new 773c15c test latest /history record returned
new 938f20a test non existent future /history record
new c511745 additional fixes as of the 'start' /history's argument. new
crashes when trying to build the history response returning one element having
row id in the middle of the id samples.
The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
talerbank/app/tests.py | 21 +++++++++++++++++++++
talerbank/app/views.py | 48 ++++++++++++++++++++----------------------------
2 files changed, 41 insertions(+), 28 deletions(-)
diff --git a/talerbank/app/tests.py b/talerbank/app/tests.py
index 5215591..a73e2db 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
@@ -102,6 +103,11 @@ class HistoryTestCase(TestCase):
wire_transfer(dict(value=1, fraction=0,
currency=settings.TALER_CURRENCY), ub, ub_p, subject="a")
wire_transfer(dict(value=1, fraction=0,
currency=settings.TALER_CURRENCY), ub, ub_p, subject="b")
wire_transfer(dict(value=1, fraction=0,
currency=settings.TALER_CURRENCY), ub, ub_p, subject="c")
+ wire_transfer(dict(value=1, fraction=0,
currency=settings.TALER_CURRENCY), ub, ub_p, subject="d")
+ wire_transfer(dict(value=1, fraction=0,
currency=settings.TALER_CURRENCY), ub, ub_p, subject="e")
+ wire_transfer(dict(value=1, fraction=0,
currency=settings.TALER_CURRENCY), ub, ub_p, subject="f")
+ wire_transfer(dict(value=1, fraction=0,
currency=settings.TALER_CURRENCY), ub, ub_p, subject="g")
+ wire_transfer(dict(value=1, fraction=0,
currency=settings.TALER_CURRENCY), ub, ub_p, subject="h")
def tearDown(self):
clearDb()
@@ -111,7 +117,22 @@ 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 latest record
+ response = c.get(reverse("history", urlconf=urls), {"auth": "basic",
"delta": "-1"},
+ **{"HTTP_X_TALER_BANK_USERNAME": "User",
"HTTP_X_TALER_BANK_PASSWORD": "Password"})
+ data = response.content.decode("utf-8")
+ data = json.loads(data)
+ self.assertEqual(data["data"][0]["subject"], "h")
+ logger.info("latest row_id: %s" % data["data"][0]["row_id"])
+ # Get non-existent record: the latest plus one in the future
+ response = c.get(reverse("history", urlconf=urls), {"auth": "basic",
"delta": "+1", "start": "10"},
+ **{"HTTP_X_TALER_BANK_USERNAME": "User",
"HTTP_X_TALER_BANK_PASSWORD": "Password"})
+ data = response.content.decode("utf-8")
+ self.assertJSONEqual(data, {"data": []})
+ # Get a delta=+1 record in the middle of the list
+ 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"})
# 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 d88a763..e0bb3c0 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,28 +337,26 @@ 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")
-
- # sign (past/future) FIXME: if not given, the call
- # must return the latest 'delta' entries: this code
- # does not currently do that!
- # The query should also apply some ordering to the
- # records.
+ if start:
+ start = int(start)
sign = parsed_delta.group(1)
if not start:
sign = "-"
- if "+" == sign:
- sign = Q(id__gt=start)
- else:
- sign = Q(id__lt=start)
+ # Assuming Q() means 'true'
+ sign_filter = Q()
+ if "-" == sign and start:
+ sign_filter = Q(id__lt=start)
+ elif "+" == sign and start:
+ sign_filter = Q(id__gt=start)
# direction (debit/credit)
direction = request.GET.get("direction")
@@ -380,17 +374,22 @@ def history(request):
if "debit" == direction:
query_string = Q(debit_account=target_account)
- qs = BankTransaction.objects.filter(query_string, sign)[:delta]
+ # FIXME *DO* return 204 No content when history is empty.
+
+ 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 = "-"
+ sign_ = "-"
if entry.credit_account.user.username == user_account.username:
counterpart = entry.debit_account.user.username
- sign = "+"
+ sign_ = "+"
history.append(dict(counterpart=counterpart,
amount=entry.amount_obj,
- sign=sign,
- subject=entry.subject))
+ sign=sign_,
+ subject=entry.subject,
+ row_id=entry.id))
return JsonResponse(dict(data=history), status=200)
@@ -411,14 +410,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
@@ -436,7 +430,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:
@@ -455,7 +448,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
- [GNUnet-SVN] [taler-bank] branch master updated (4c48839 -> c511745),
gnunet <=
- [GNUnet-SVN] [taler-bank] 05/05: additional fixes as of the 'start' /history's argument. new crashes when trying to build the history response returning one element having row id in the middle of the id samples., gnunet, 2017/05/06
- [GNUnet-SVN] [taler-bank] 03/05: test latest /history record returned, gnunet, 2017/05/06
- [GNUnet-SVN] [taler-bank] 04/05: test non existent future /history record, gnunet, 2017/05/06
- [GNUnet-SVN] [taler-bank] 01/05: sign & delta dealt with. testing needed., gnunet, 2017/05/06
- [GNUnet-SVN] [taler-bank] 02/05: fix query of non-existent future /history element, gnunet, 2017/05/06