summaryrefslogtreecommitdiff
path: root/talerbank/app/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'talerbank/app/tests.py')
-rw-r--r--talerbank/app/tests.py71
1 files changed, 48 insertions, 23 deletions
diff --git a/talerbank/app/tests.py b/talerbank/app/tests.py
index 40545e0..2c8729a 100644
--- a/talerbank/app/tests.py
+++ b/talerbank/app/tests.py
@@ -373,43 +373,68 @@ class HistoryTestCase(TestCase):
clear_db()
def test_history(self):
- for ctx in (HistoryContext(expected_resp={"status": 200},
- delta="4", direction="both"),
- HistoryContext(expected_resp={
- "field": "row_id", "value": 6,
- "status": 200}, delta="+1", start="5", direction="both"),
- HistoryContext(expected_resp={
- "field": "wt_subject", "value": "h",
- "status": 200}, delta="-1", start=9, direction="both"),
- HistoryContext(expected_resp={"status": 204},
- delta="1", start="11", direction="both"),
- HistoryContext(expected_resp={"status": 204},
- delta="+1", direction="cancel+"),
- HistoryContext(expected_resp={
- "status": 200,
- "field": "wt_subject",
- "value": "/reject: reimbursement"},
- delta="+1", direction="credit"),
+ for ctx in (HistoryContext(
+ expected_resp={"status": 200},
+ delta="4", direction="both"),
+ HistoryContext(
+ expected_resp={
+ "fields": [("row_id", 6)],
+ "status": 200},
+ delta="+1", start="5", direction="both"),
+ HistoryContext(
+ expected_resp={
+ "fields": [("wt_subject", "h")],
+ "status": 200},
+ delta="-1", start=9, 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-"),
+ HistoryContext(
+ expected_resp={"status": 204},
+ delta="+1", direction="cancel+"),
+ HistoryContext(
+ expected_resp={
+ "status": 200,
+ "fields":
+ [("wt_subject",
+ "/reject: reimbursement")]},
+ delta="+1", direction="credit"),
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"})
+ 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(
- data.get(ctx.expected_resp.get("field")),
- ctx.expected_resp.get("value"))
- 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 k, v in ctx.expected_resp.get("fields", []):
+ response_data.update({k: data.get(k)})
+ expected_data.update({k: v})
+
+ self.assertEqual(expected_data, response_data)
+
+
class DBAmountSubtraction(TestCase):
def setUp(self):
BankAccount(