diff options
author | Marcello Stanisci <stanisci.m@gmail.com> | 2019-04-04 17:16:19 +0200 |
---|---|---|
committer | Marcello Stanisci <stanisci.m@gmail.com> | 2019-04-04 17:16:19 +0200 |
commit | 35cb277f709adcce43af8cca4b22c9bc9e5d6932 (patch) | |
tree | 5099803717eae753dd43869fd294abf81d0530e2 | |
parent | 6f7415a2d2c612bf91aa7a73449ef1a141790386 (diff) | |
download | bank-35cb277f709adcce43af8cca4b22c9bc9e5d6932.tar.gz bank-35cb277f709adcce43af8cca4b22c9bc9e5d6932.tar.bz2 bank-35cb277f709adcce43af8cca4b22c9bc9e5d6932.zip |
Calling /history-range from test cases.
To be tested more.
-rw-r--r-- | talerbank/app/schemas.py | 6 | ||||
-rw-r--r-- | 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): |