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: Calling /history-range


From: gnunet
Subject: [GNUnet-SVN] [taler-bank] branch master updated: Calling /history-range from test cases.
Date: Thu, 04 Apr 2019 17:16:45 +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 35cb277  Calling /history-range from test cases.
35cb277 is described below

commit 35cb277f709adcce43af8cca4b22c9bc9e5d6932
Author: Marcello Stanisci <address@hidden>
AuthorDate: Thu Apr 4 17:16:19 2019 +0200

    Calling /history-range from test cases.
    
    To be tested more.
---
 talerbank/app/schemas.py |  6 +++--
 talerbank/app/tests.py   | 69 ++++++++++++++++++++++++++++++++++--------------
 2 files changed, 53 insertions(+), 22 deletions(-)

diff --git a/talerbank/app/schemas.py b/talerbank/app/schemas.py
index 90c39d4..f61e448 100644
--- a/talerbank/app/schemas.py
+++ b/talerbank/app/schemas.py
@@ -156,8 +156,10 @@ HISTORY_RANGE_REQUEST_SCHEMA = {
         "cancelled": {"type": "string",
                       "pattern": "^(omit|show)$",
                       "required": False},
-        "start": {"type": "integer"},
-        "end": {"type": "integer"},
+        "start": {"type": "string",
+                  "pattern": r"^[0-9]+$"},
+        "end": {"type": "string",
+                "pattern": r"^[0-9]+$"},
         "ordering": {"type": "string",
                      "pattern": r"^(ascending|descending)$",
                      "required": False},
diff --git a/talerbank/app/tests.py b/talerbank/app/tests.py
index 3fbe170..c820b0b 100644
--- a/talerbank/app/tests.py
+++ b/talerbank/app/tests.py
@@ -382,73 +382,102 @@ class HistoryTestCase(TestCase):
     def tearDown(self):
         clear_db()
 
+    def assert_result(self, response, ctx):
+
+        data = response.content.decode("utf-8")
+        try:
+            # FIXME, not always data is found this way.
+            data = json.loads(data)["data"][0]
+        except (json.JSONDecodeError, KeyError):
+            data = {}
+        self.assertEqual(
+            ctx.expected_resp.get("status"),
+            response.status_code,
+            "Failing request: %s?%s => raw body: %s" % \
+                (response.request["PATH_INFO"],
+                 unquote(response.request["QUERY_STRING"]),
+                 response.content.decode("utf-8")))
+
+        # extract expected data from response
+        expected_data = {}
+        response_data = {}
+        for key, value in ctx.expected_resp.get("fields", []):
+            response_data.update({key: data.get(key)})
+            expected_data.update({key: value})
+
+        self.assertEqual(expected_data, response_data)
+
+    def test_history_range(self):
+
+        ctx = HistoryContext(expected_resp={"status": 204},
+                             start = 1, end = 2, direction="both")
+
+        response = self.client.get(
+            reverse("history-range", urlconf=urls), ctx.urlargs,
+            **{"HTTP_X_TALER_BANK_USERNAME": "User",
+               "HTTP_X_TALER_BANK_PASSWORD": "Password"})
+
+        self.assert_result(response, ctx)
+
     def test_history(self):
         for ctx in (
+
                 HistoryContext(
                     expected_resp={"status": 200},
                     delta="-4", direction="both"),
+
                 HistoryContext(
                     expected_resp={
                         "fields": [("row_id", 9)],
                         "status": 200},
                     delta="+1", start="5", direction="both"),
+
                 HistoryContext(
                     expected_resp={
                         "fields": [("wt_subject", "c")],
                         "status": 200},
                     delta="1", start=2,
                     direction="both", ordering="ascending"),
+
                 HistoryContext(
                     expected_resp={
                         "fields": [("wt_subject", "a")],
                         "status": 200},
                     delta="-1", start=2, direction="both"),
+
                 HistoryContext(
                     expected_resp={"status": 204},
                     delta="1", start="11", direction="both"),
+
                 HistoryContext(
                     expected_resp={
                         "status": 200,
                         "fields": [("wt_subject", "i"),
                                    ("sign", "cancel-")]},
                     start=8, delta="+1", direction="cancel-"),
+
                 HistoryContext(
                     expected_resp={"status": 204},
                     start=8, delta="+1",
                     direction="cancel-", cancelled="omit"),
+
                 HistoryContext(
                     expected_resp={"status": 204},
                     start=8, delta="-1", direction="cancel-"),
+
                 HistoryContext(
                     expected_resp={"status": 204},
                     delta="+1", direction="cancel+"),
+
                 HistoryContext(expected_resp={"status": 200},
                                delta="-1", direction="debit")):
+
             response = self.client.get(
                 reverse("history", urlconf=urls), ctx.urlargs,
                 **{"HTTP_X_TALER_BANK_USERNAME": "User",
                    "HTTP_X_TALER_BANK_PASSWORD": "Password"})
-            data = response.content.decode("utf-8")
-            try:
-                data = json.loads(data)["data"][0]
-            except (json.JSONDecodeError, KeyError):
-                data = {}
-            self.assertEqual(
-                ctx.expected_resp.get("status"),
-                response.status_code,
-                "Failing request: %s?%s" % \
-                    (response.request["PATH_INFO"],
-                     unquote(response.request["QUERY_STRING"])))
-
-            # extract expected data from response
-            expected_data = {}
-            response_data = {}
-            for key, value in ctx.expected_resp.get("fields", []):
-                response_data.update({key: data.get(key)})
-                expected_data.update({key: value})
-
-            self.assertEqual(expected_data, response_data)
 
+            self.assert_result(response, ctx)
 
 class DBAmountSubtraction(TestCase):
     def setUp(self):

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



reply via email to

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