gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated: Add payment integration test


From: gnunet
Subject: [taler-wallet-core] branch master updated: Add payment integration test (fails early)
Date: Wed, 29 Jul 2020 20:31:31 +0200

This is an automated email from the git hooks/post-receive script.

torsten-grote pushed a commit to branch master
in repository wallet-core.

The following commit(s) were added to refs/heads/master by this push:
     new 899a73ca Add payment integration test (fails early)
899a73ca is described below

commit 899a73ca78a9a66b89248092bd2d804c668b47ee
Author: Torsten Grote <t@grobox.de>
AuthorDate: Wed Jul 29 15:31:09 2020 -0300

    Add payment integration test (fails early)
---
 tests/components/merchant.py | 66 ++++++++++++++++++++++++++++++++++++++++++++
 tests/conftest.py            |  8 ++++++
 tests/test_payments.py       | 11 ++++++++
 3 files changed, 85 insertions(+)

diff --git a/tests/components/merchant.py b/tests/components/merchant.py
new file mode 100644
index 00000000..373b8ed8
--- /dev/null
+++ b/tests/components/merchant.py
@@ -0,0 +1,66 @@
+import os
+from subprocess import run
+
+import requests
+
+from .taler_service import TalerService
+
+
+class Merchant(TalerService):
+
+    def __init__(self, config, watcher_getter, request):
+        super().__init__(config, watcher_getter, request)
+
+        # get localhost port and store merchant URL
+        r = run(["taler-config", "-c", config.conf, "-s", "MERCHANT", "-o", 
"PORT"],
+                check=True, text=True, capture_output=True)
+        self.url = "http://localhost:%s/"; % r.stdout.rstrip()
+
+    def start(self):
+        log_path = os.path.join(self.config.tmpdir, "merchant.log")
+        self.watcher_getter(
+            name='taler-merchant-httpd',
+            arguments=['-c', self.config.conf, '-L', 'INFO', '-l', log_path],
+            checker=self.test_url,
+            request=self.request,  # Needed for the correct execution order of 
finalizers
+        )
+
+    def create_instance(self, instance="default", name="GNU Taler Merchant"):
+        body = {
+            "id": instance,
+            "name": name,
+            "payto_uris": ["payto://x-taler-bank/test_merchant"],
+            "address": {},
+            "jurisdiction": {},
+            "default_max_wire_fee": "TESTKUDOS:1",
+            "default_wire_fee_amortization": 3,
+            "default_max_deposit_fee": "TESTKUDOS:1",
+            "default_wire_transfer_delay": {"d_ms": "forever"},
+            "default_pay_delay": {"d_ms": "forever"}
+        }
+        r = requests.post(self.url + "private/instances", json=body)
+        r.raise_for_status()
+
+    def create_order(self, amount, instance="default", summary="Test Order",
+                     
fulfillment_url="taler://fulfillment-success/Enjoy+your+ice+cream!"):
+        body = {
+            "order": {
+                "amount": amount,
+                "summary": summary,
+                "fulfillment_url": fulfillment_url
+            }
+        }
+        r = requests.post("{}instances/{}/private/orders".format(self.url, 
instance), json=body)
+        r.raise_for_status()
+        return r.json()
+
+    def check_payment(self, order_id, instance="default"):
+        r = requests.get("{}instances/{}/private/orders/{}".format(self.url, 
instance, order_id))
+        r.raise_for_status()
+        return r.json()
+
+    def gen_pay_uri(self, amount, instance="default", summary="Test Order",
+                    
fulfillment_url="taler://fulfillment-success/Enjoy+your+ice+cream!"):
+        order = self.create_order(amount, instance, summary, fulfillment_url)
+        response = self.check_payment(order["order_id"], instance)
+        return response["taler_pay_uri"]
diff --git a/tests/conftest.py b/tests/conftest.py
index 1922d1d4..6bc801ba 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -3,6 +3,7 @@ import pytest
 from tests.components.bank import Bank
 from tests.components.config import Config
 from tests.components.exchange import Exchange
+from tests.components.merchant import Merchant
 from tests.components.wallet import Wallet
 
 
@@ -25,6 +26,13 @@ def bank(watcher_getter, request, config):
     return bank
 
 
+@pytest.fixture
+def merchant(watcher_getter, request, config):
+    merchant = Merchant(config, watcher_getter, request)
+    merchant.start()
+    return merchant
+
+
 @pytest.fixture
 def wallet(watcher_getter, config):
     return Wallet(config)
diff --git a/tests/test_payments.py b/tests/test_payments.py
new file mode 100644
index 00000000..b73d7f79
--- /dev/null
+++ b/tests/test_payments.py
@@ -0,0 +1,11 @@
+#!/usr/bin/env python3
+from tests import print_json
+
+
+def test_payments(exchange, bank, merchant, wallet):
+    merchant.create_instance()
+    pay_uri = merchant.gen_pay_uri("TESTKUDOS:2")
+
+    # TODO fix
+    # result = wallet.cmd("preparePay", {"talerPayUri": pay_uri})
+    # print_json(result)

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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