diff options
author | Torsten Grote <t@grobox.de> | 2020-07-24 11:09:30 -0300 |
---|---|---|
committer | Torsten Grote <t@grobox.de> | 2020-07-28 15:42:39 -0300 |
commit | 08c3209dbc06329b4566ddd8d1dd7ab1c7e28ed7 (patch) | |
tree | 794658b2b9dfc3a39d8e374feae7e03919742f63 /tests/components/wallet.py | |
parent | 503c35d5f5972551cffa1fecb8b7b463503cc662 (diff) | |
download | wallet-core-08c3209dbc06329b4566ddd8d1dd7ab1c7e28ed7.tar.xz |
Add CI config for Gitlab CI integration tests (bash and pytest)
Diffstat (limited to 'tests/components/wallet.py')
-rw-r--r-- | tests/components/wallet.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/components/wallet.py b/tests/components/wallet.py new file mode 100644 index 000000000..77099ab88 --- /dev/null +++ b/tests/components/wallet.py @@ -0,0 +1,50 @@ +import json +import os +from subprocess import run + + +class Wallet: + + def __init__(self, config): + self.db = os.path.join(config.tmpdir, "wallet-db.json") + self.arg_db = "--wallet-db=%s" % self.db + self.log_path = os.path.join(config.tmpdir, "wallet.log") + + def cmd(self, command, request=None): + if request is None: + request = dict() + request = json.dumps(request) + r = run(["taler-wallet-cli", self.arg_db, "api", command, request], + timeout=10, text=True, capture_output=True) + self.write_to_log(r.stderr) + if r.returncode != 0: + print(r) + assert r.returncode == 0 + json_r = json.loads(r.stdout) + if json_r["isError"]: + print(r) + assert not json_r["isError"] + if "result" not in json_r: + # TODO should there not always be a "result"? + return None + return json_r["result"] + + def testing_withdraw(self, amount, exchange_url, bank_url): + r = run(["taler-wallet-cli", self.arg_db, "--no-throttle", "testing", "withdraw", + "-a", amount, + "-e", exchange_url, + "-b", bank_url + ], 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) + self.write_to_log(r.stderr) + return r.stdout.rstrip() + + def write_to_log(self, data): + with open(self.log_path, "a") as f: + f.write(data) |