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: defining json schema fo


From: gnunet
Subject: [GNUnet-SVN] [taler-bank] branch master updated: defining json schema for /history requests
Date: Thu, 30 Mar 2017 17:15:59 +0200

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 2789025  defining json schema for /history requests
2789025 is described below

commit 2789025fec6871f008cfdb9658f9319e65633737
Author: Marcello Stanisci <address@hidden>
AuthorDate: Thu Mar 30 17:15:27 2017 +0200

    defining json schema for /history requests
---
 talerbank/app/schemas.py | 13 +++++++++++++
 talerbank/app/tests.py   | 20 ++++++++++++++++++++
 talerbank/app/urls.py    |  1 +
 talerbank/app/views.py   | 13 +++++++++++++
 4 files changed, 47 insertions(+)

diff --git a/talerbank/app/schemas.py b/talerbank/app/schemas.py
index 7c1c9af..2e252e0 100644
--- a/talerbank/app/schemas.py
+++ b/talerbank/app/schemas.py
@@ -37,6 +37,16 @@ wiredetails_schema = {
     }
 }
 
+history_schema = {
+    "type": "object",
+    "properties" : {
+        "username": {"type": "string"},
+        "password": {"type": "string"},
+        "start": {"type": "integer", "required": False},
+        "delta": {"type": "integer", "required": False}
+    }
+}
+
 amount_schema = {
     "type": "object",
     "properties": {
@@ -61,6 +71,9 @@ incoming_request_schema = {
 def validate_amount(amount):
     validictory.validate(amount, amount_schema)
 
+def validate_history(request_data):
+    validictory.validate(request_data, history_schema)
+
 def validate_wiredetails(wiredetails):
     validictory.validate(wiredetails, wiredetails_schema)
 
diff --git a/talerbank/app/tests.py b/talerbank/app/tests.py
index a0236b5..ac8c268 100644
--- a/talerbank/app/tests.py
+++ b/talerbank/app/tests.py
@@ -88,6 +88,26 @@ class AmountTestCase(TestCase):
         self.assertEqual(0, amounts.amount_cmp(a1, _a1))
 
 
+class HistoryTestCase(TestCase):
+
+    def setUp(self):
+        user = User.objects.create_user(username='User', password="Passoword")
+        uba = BankAccount(user=user, currency=settings.TALER_CURRENCY)
+        uba.account_no = 1
+        uba.save() 
+
+    def tearDown(self):
+        clearDb()
+
+    def test_history(self):
+        c = Client()
+        response = c.post(reverse("history", urlconf=urls),
+                          data= '{"username": "User", \
+                                  "password": "Passoword"}',
+                          content_type="application/json")
+        self.assertEqual(200, response.status_code)
+
+
 # This tests whether a bank account goes red and then
 # goes green again
 class DebitTestCase(TestCase):
diff --git a/talerbank/app/urls.py b/talerbank/app/urls.py
index 3ab6485..85aec1c 100644
--- a/talerbank/app/urls.py
+++ b/talerbank/app/urls.py
@@ -27,6 +27,7 @@ urlpatterns = [
     url(r'^logout/$', views.logout_view, name="logout"),
     url(r'^accounts/register/$', views.register, name="register"),
     url(r'^profile$', views.profile_page, name="profile"),
+    url(r'^history$', views.history, name="history"),
     url(r'^withdraw$', views.withdraw_nojs, name="withdraw-nojs"),
     url(r'^public-accounts$', views.public_accounts, name="public-accounts"),
     url(r'^public-accounts/(?P<name>[a-zA-Z0-9 ]+)$', views.public_accounts, 
name="public-accounts"),
diff --git a/talerbank/app/views.py b/talerbank/app/views.py
index 3f4ff70..577f719 100644
--- a/talerbank/app/views.py
+++ b/talerbank/app/views.py
@@ -334,6 +334,19 @@ def public_accounts(request, name=None):
     )
     return render(request, "public_accounts.html", context)
 
+# Although this call doesn't change the server's state,
+# it uses POST because it takes a password among its parameters
address@hidden
+def history(request):
+    """
+    This API is used to get a list of transactions related to one user.
+    """
+    data = json.loads(request.body.decode("utf-8"))
+    try: schemas.validate_history(data)
+    except ValueError:
+        return HttpResponseBadRequest()
+    return HttpResponse(200)
+
 
 @csrf_exempt
 @require_POST

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



reply via email to

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