gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated (5a8ac4b -> f3cb043)


From: gnunet
Subject: [libeufin] branch master updated (5a8ac4b -> f3cb043)
Date: Sun, 15 Nov 2020 22:06:51 +0100

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

ms pushed a change to branch master
in repository libeufin.

    from 5a8ac4b  Integration tests.
     new ea50218  Integration tests.
     new 1910639  Integration tests.
     new bfea728  comment
     new be3c1e7  Integration tests.
     new 411798c  Testing backup generation and import.
     new f3cb043  Testing payment initiation and submission.

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 Makefile                   |   5 ++
 integration-tests/test.py  |  64 --------------
 integration-tests/tests.py | 212 +++++++++++++++++++++++++++++++++++++++++++++
 integration-tests/util.py  |  43 ++++-----
 4 files changed, 239 insertions(+), 85 deletions(-)
 delete mode 100755 integration-tests/test.py
 create mode 100755 integration-tests/tests.py

diff --git a/Makefile b/Makefile
index 4c22294..a454ceb 100644
--- a/Makefile
+++ b/Makefile
@@ -39,3 +39,8 @@ assemble:
 .PHONY: check
 check:
        @./gradlew check
+
+
+.PHONY: tests
+tests:
+       @cd integration-tests; py.test tests.py; cd ..
diff --git a/integration-tests/test.py b/integration-tests/test.py
deleted file mode 100755
index cd77b44..0000000
--- a/integration-tests/test.py
+++ /dev/null
@@ -1,64 +0,0 @@
-#!/usr/bin/env python3
-
-from util import startNexus, startSandbox, assertResponse, flushTablesSandbox
-from requests import post, get
-
-# Databases
-NEXUS_DB="/tmp/test-nexus.sqlite3"
-SANDBOX_DB="/tmp/test-sandbox.sqlite3"
-
-# Nexus user details
-NEXUS_USERNAME = "person"
-NEXUS_PASSWORD = "y"
-
-# EBICS details
-EBICS_URL = "http://localhost:5000/ebicsweb";
-EBICS_HOST = "HOST01"
-EBICS_PARTNER = "PARTNER1"
-EBICS_USER = "USER1"
-EBICS_VERSION = "H004"
-
-# Subscriber's bank account at the Sandbox
-BANK_IBAN = "GB33BUKB20201555555555"
-BANK_BIC = "BUKBGB22"
-BANK_NAME = "Oliver Smith"
-BANK_LABEL = "savings"
-
-def prepareSandbox():
-    # make ebics host at sandbox
-    assertResponse(
-        post(
-            "http://localhost:5000/admin/ebics/host";,
-            json=dict(hostID=EBICS_HOST, ebicsVersion=EBICS_VERSION),
-        )
-    )
-    
-    # make new ebics subscriber at sandbox
-    assertResponse(
-        post(
-            "http://localhost:5000/admin/ebics/subscribers";,
-            json=dict(hostID=EBICS_HOST, partnerID=EBICS_PARTNER, 
userID=EBICS_USER),
-        )
-    )
-    
-    # give a bank account to such subscriber, at sandbox
-    assertResponse(
-        post(
-            "http://localhost:5000/admin/ebics/bank-accounts";,
-            json=dict(
-                subscriber=dict(hostID=EBICS_HOST, partnerID=EBICS_PARTNER, 
userID=EBICS_USER),
-                iban=BANK_IBAN,
-                bic=BANK_BIC,
-                name=BANK_NAME,
-                label=BANK_LABEL
-            )
-        )
-    )
-
-startNexus(NEXUS_DB)
-startSandbox(SANDBOX_DB)
-
-prepareSandbox()
-print("Services correctly started.")
-print("Emptying tables at Sandbox")
-flushTablesSandbox(SANDBOX_DB)
diff --git a/integration-tests/tests.py b/integration-tests/tests.py
new file mode 100755
index 0000000..8979723
--- /dev/null
+++ b/integration-tests/tests.py
@@ -0,0 +1,212 @@
+#!/usr/bin/env python3
+
+from requests import post, get, auth
+from time import sleep
+from util import (
+    startNexus,
+    startSandbox,
+    assertResponse,
+    flushTablesSandbox,
+    flushTablesNexus,
+    makeNexusSuperuser
+)
+
+# Base URLs
+S = "http://localhost:5000";
+N = "http://localhost:5001";
+
+# Databases
+NEXUS_DB="/tmp/test-nexus.sqlite3"
+SANDBOX_DB="/tmp/test-sandbox.sqlite3"
+
+# Nexus user details
+NEXUS_USERNAME = "person"
+NEXUS_PASSWORD = "y"
+NEXUS_BANK_CONNECTION="my-ebics"
+NEXUS_BANK_LABEL="local-savings"
+NEXUS_AUTH = auth.HTTPBasicAuth(
+    NEXUS_USERNAME,
+    NEXUS_PASSWORD
+)
+
+# EBICS details
+EBICS_URL = f"{S}/ebicsweb"
+EBICS_HOST = "HOST01"
+EBICS_PARTNER = "PARTNER1"
+EBICS_USER = "USER1"
+EBICS_VERSION = "H004"
+
+# Subscriber's bank account at the Sandbox
+BANK_IBAN = "GB33BUKB20201555555555"
+BANK_BIC = "BUKBGB22"
+BANK_NAME = "Oliver Smith"
+BANK_LABEL = "savings"
+
+def prepareSandbox():
+    # make ebics host at sandbox
+    assertResponse(
+        post(
+            f"{S}/admin/ebics/host",
+            json=dict(hostID=EBICS_HOST, ebicsVersion=EBICS_VERSION),
+        )
+    )
+    # make new ebics subscriber at sandbox
+    assertResponse(
+        post(
+            f"{S}/admin/ebics/subscribers",
+            json=dict(hostID=EBICS_HOST, partnerID=EBICS_PARTNER, 
userID=EBICS_USER),
+        )
+    )
+    # give a bank account to such subscriber, at sandbox
+    assertResponse(
+        post(
+            f"{S}/admin/ebics/bank-accounts",
+            json=dict(
+                subscriber=dict(hostID=EBICS_HOST, partnerID=EBICS_PARTNER, 
userID=EBICS_USER),
+                iban=BANK_IBAN,
+                bic=BANK_BIC,
+                name=BANK_NAME,
+                label=BANK_LABEL
+            )
+        )
+    )
+
+def prepareNexus():
+    makeNexusSuperuser(NEXUS_DB)
+    # make a new nexus user.
+    assertResponse(
+        post(
+            f"{N}/users",
+            auth=auth.HTTPBasicAuth("admin", "x"),
+            json=dict(username=NEXUS_USERNAME, password=NEXUS_PASSWORD),
+        )
+    )
+    # make a ebics bank connection for the new user.
+    assertResponse(
+        post(
+            f"{N}/bank-connections",
+            json=dict(
+                name=NEXUS_BANK_CONNECTION,
+                source="new",
+                type="ebics",
+                data=dict(
+                    ebicsURL=EBICS_URL,
+                    hostID=EBICS_HOST,
+                    partnerID=EBICS_PARTNER,
+                    userID=EBICS_USER
+                ),
+            ),
+            auth=NEXUS_AUTH
+        )
+    )
+    # synchronizing the connection
+    assertResponse(
+        post(
+            f"{N}/bank-connections/my-ebics/connect",
+            json=dict(),
+            auth=NEXUS_AUTH
+        )
+    )
+    # download offered bank accounts
+    assertResponse(
+        post(
+            f"{N}/bank-connections/my-ebics/fetch-accounts",
+            json=dict(),
+            auth=NEXUS_AUTH
+        )
+    )
+    # import one bank account into the Nexus
+    assertResponse(
+        post(
+            f"{N}/bank-connections/my-ebics/import-account",
+            json=dict(
+                offeredAccountId=BANK_LABEL,
+                nexusBankAccountId=NEXUS_BANK_LABEL
+            ),
+            auth=NEXUS_AUTH
+        )
+    )
+
+startNexus(NEXUS_DB)
+startSandbox(SANDBOX_DB)
+
+def setup_function():
+    prepareSandbox()
+    prepareNexus()
+
+def teardown_function():
+  flushTablesNexus(NEXUS_DB)
+  flushTablesSandbox(SANDBOX_DB)
+
+# Tests whether Nexus knows the imported bank account.
+def test_imported_account():
+    resp = assertResponse(
+        get(
+            f"{N}/bank-connections/my-ebics/accounts",
+            auth=NEXUS_AUTH
+        )
+    )
+    imported_account = resp.json().get("accounts").pop()
+    assert imported_account.get("nexusBankAccountId") == NEXUS_BANK_LABEL
+
+def test_empty_history():
+    resp = assertResponse(
+        get(
+            f"{N}/bank-accounts/{NEXUS_BANK_LABEL}/transactions",
+            auth=NEXUS_AUTH
+        )
+    )
+    assert len(resp.json().get("transactions")) == 0
+
+def test_backup():
+    resp = assertResponse(
+        post(
+            f"{N}/bank-connections/{NEXUS_BANK_CONNECTION}/export-backup",
+            json=dict(passphrase="secret"),
+            auth=NEXUS_AUTH
+        )
+    )
+    sleep(3)
+    assertResponse(
+        post(
+            f"{N}/bank-connections",
+            json=dict(name="my-ebics-restored", data=resp.json(), 
passphrase="secret", source="backup"),
+            auth=NEXUS_AUTH
+        )
+    )
+
+def test_payment():
+    resp = assertResponse(
+        post(
+            f"{N}/bank-accounts/{NEXUS_BANK_LABEL}/payment-initiations",
+            json=dict(
+                iban="FR7630006000011234567890189",
+                bic="AGRIFRPP",
+                name="Jacques La Fayette",
+                subject="integration test",
+                amount="EUR:1",
+            ),
+            auth=NEXUS_AUTH
+        )
+    )
+    PAYMENT_UUID = resp.json().get("uuid")
+    assertResponse(
+        post(
+            
f"{N}/bank-accounts/{NEXUS_BANK_LABEL}/payment-initiations/{PAYMENT_UUID}/submit",
+            json=dict(),
+            auth=NEXUS_AUTH
+        )
+    )
+    assertResponse(
+        post(
+            f"{N}/bank-accounts/{NEXUS_BANK_LABEL}/fetch-transactions",
+            auth=NEXUS_AUTH
+        )
+    )
+    resp = assertResponse(
+        get(
+            f"{N}/bank-accounts/{NEXUS_BANK_LABEL}/transactions",
+            auth=NEXUS_AUTH
+        )
+    )
+    assert len(resp.json().get("transactions")) == 1
diff --git a/integration-tests/util.py b/integration-tests/util.py
index 27d8d17..96f75f2 100644
--- a/integration-tests/util.py
+++ b/integration-tests/util.py
@@ -42,14 +42,27 @@ def checkPort(port):
         exit(77)
 
 def kill(name, s):
-    print(f"terminating {name} ...")
     s.terminate()
     s.wait()
 
+def makeNexusSuperuser(dbName):
+    db_full_path = str(Path.cwd() / dbName)
+    check_call(
+        [
+            "../gradlew",
+            "-p",
+            "..",
+            "nexus:run",
+            "--console=plain",
+            f"--args=superuser admin --password x --db-name={db_full_path}",
+        ]
+    )
+
 def flushTablesSandbox(dbName):
+    db_full_path = str(Path.cwd() / dbName)
     check_call(
         ["sqlite3",
-         dbName,
+         db_full_path,
          "DELETE FROM BankAccountReports",
          "DELETE FROM EbicsOrderSignatures",
          "DELETE FROM BankAccountStatements",
@@ -65,9 +78,10 @@ def flushTablesSandbox(dbName):
      )
 
 def flushTablesNexus(dbName):
+    db_full_path = str(Path.cwd() / dbName)
     check_call(
         ["sqlite3",
-         dbName,
+         db_full_path,
          "DELETE FROM EbicsSubscribers",
          "DELETE FROM NexusBankTransactions",
          "DELETE FROM TalerFacadeState",
@@ -84,8 +98,8 @@ def flushTablesNexus(dbName):
         ]
     )
 
-def startSandbox(dbname="sandbox-test.sqlite3"):
-    db_full_path = str(Path.cwd() / dbname)
+def startSandbox(dbName="sandbox-test.sqlite3"):
+    db_full_path = str(Path.cwd() / dbName)
     check_call(["rm", "-f", db_full_path])
     check_call(["../gradlew", "-p", "..", "sandbox:assemble"])
     checkPort(5000)
@@ -110,22 +124,12 @@ def startSandbox(dbname="sandbox-test.sqlite3"):
         break
 
 
-def startNexus(dbname="nexus-test.sqlite3"):
-    db_full_path = str(Path.cwd() / dbname)
+def startNexus(dbName="nexus-test.sqlite3"):
+    db_full_path = str(Path.cwd() / dbName)
     check_call(["rm", "-f", "--", db_full_path])
     check_call(
         ["../gradlew", "-p", "..", "nexus:assemble",]
     )
-    check_call(
-        [
-            "../gradlew",
-            "-p",
-            "..",
-            "nexus:run",
-            "--console=plain",
-            "--args=superuser admin --password x 
--db-name={}".format(db_full_path),
-        ]
-    )
     checkPort(5001)
     nexus = Popen(
         [
@@ -155,8 +159,5 @@ def startNexus(dbname="nexus-test.sqlite3"):
     return nexus
 
 def assertResponse(response, acceptedResponses=[200]):
-    if response.status_code not in acceptedResponses:
-        print("Test failed on URL: {}, status: {}".format(
-            response.url, response.status_code))
-        exit(1)
+    assert response.status_code in acceptedResponses
     return response

-- 
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]