aboutsummaryrefslogtreecommitdiff
path: root/tests/components
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-07-29 14:33:59 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-07-29 14:33:59 +0530
commit7e34b6699a77620b148b167e6aa12d50cc7456e5 (patch)
treeced77a5d6eac157ea4234b574c5856e0e7451e70 /tests/components
parent08c3209dbc06329b4566ddd8d1dd7ab1c7e28ed7 (diff)
downloadwallet-core-7e34b6699a77620b148b167e6aa12d50cc7456e5.tar.xz
test cases
Diffstat (limited to 'tests/components')
-rw-r--r--tests/components/bank.py47
-rw-r--r--tests/components/wallet.py14
2 files changed, 55 insertions, 6 deletions
diff --git a/tests/components/bank.py b/tests/components/bank.py
index 707edbfc4..ee2d6e923 100644
--- a/tests/components/bank.py
+++ b/tests/components/bank.py
@@ -3,8 +3,24 @@ from subprocess import run
import psutil
+import requests
+
+import secrets
+
from .taler_service import TalerService
+from dataclasses import dataclass
+
+@dataclass
+class BankUser:
+ username: str
+ password: str
+
+@dataclass
+class WithdrawUriResponse:
+ taler_withdraw_uri: str
+ withdrawal_id: str
+
class Bank(TalerService):
@@ -14,7 +30,7 @@ class Bank(TalerService):
# get localhost port and store bank URL
r = run(["taler-config", "-c", config.conf, "-s", "BANK", "-o", "HTTP_PORT"],
check=True, text=True, capture_output=True)
- self.url = "http://localhost:%s" % r.stdout.rstrip()
+ self.url = "http://localhost:%s/" % r.stdout.rstrip()
def start(self):
db = "postgres:///%s" % self.config.db
@@ -33,6 +49,35 @@ class Bank(TalerService):
self.request.addfinalizer(close_log)
+ def register_random_user(self):
+ username = f"testuser-{secrets.token_hex(10)}"
+ password = f"testpw-{secrets.token_hex(10)}"
+ requests.post(
+ f"{self.url}testing/register",
+ json=dict(username=username, password=password)
+ )
+ return BankUser(username, password)
+
+ def generate_withdraw_uri(self, bankuser, amount):
+ auth = (bankuser.username, bankuser.password)
+ resp = requests.post(
+ f"{self.url}accounts/{bankuser.username}/withdrawals",
+ json=dict(amount=amount),
+ auth=auth
+ )
+ rj = resp.json()
+ return WithdrawUriResponse(
+ taler_withdraw_uri=rj["taler_withdraw_uri"],
+ withdrawal_id=rj["withdrawal_id"],
+ )
+
+ def confirm_withdrawal(self, bankuser, withdrawal_id):
+ auth = (bankuser.username, bankuser.password)
+ resp = requests.post(
+ f"{self.url}accounts/{bankuser.username}/withdrawals/{withdrawal_id}/confirm",
+ auth=auth
+ )
+
# Alternative way to check if the bank came up.
# Testing the URL has the issue that on the CI, django keeps closing the connection.
@staticmethod
diff --git a/tests/components/wallet.py b/tests/components/wallet.py
index 77099ab88..cedae84e1 100644
--- a/tests/components/wallet.py
+++ b/tests/components/wallet.py
@@ -37,11 +37,15 @@ class Wallet:
], timeout=10, check=True, text=True, capture_output=True)
self.write_to_log(r.stderr)
- def gen_withdraw_uri(self, amount, bank_url):
- r = run(["taler-wallet-cli", self.arg_db, "testing", "gen-withdraw-uri",
- "-a", amount,
- "-b", bank_url
- ], timeout=10, check=True, text=True, capture_output=True)
+ def run_pending(self):
+ r = run(["taler-wallet-cli", self.arg_db, "run-pending"],
+ timeout=10, check=True, text=True, capture_output=True)
+ self.write_to_log(r.stderr)
+ return r.stdout.rstrip()
+
+ def run_until_done(self):
+ r = run(["taler-wallet-cli", self.arg_db, "run-until-done"],
+ timeout=10, check=True, text=True, capture_output=True)
self.write_to_log(r.stderr)
return r.stdout.rstrip()