libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit ea502185c7e76f49724e970350bb40588f7037b3
parent 5a8ac4b3cad1340b0ce01ac7432c3c59c2b4af80
Author: MS <ms@taler.net>
Date:   Fri, 13 Nov 2020 22:21:18 +0100

Integration tests.

Preparing services and let pytest be launched via Makefile.

Diffstat:
MMakefile | 5+++++
Dintegration-tests/test.py | 64----------------------------------------------------------------
Aintegration-tests/tests.py | 135+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mintegration-tests/util.py | 6+-----
4 files changed, 141 insertions(+), 69 deletions(-)

diff --git 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 @@ -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 @@ -0,0 +1,135 @@ +#!/usr/bin/env python3 + +from requests import post, get, auth +from util import ( + startNexus, + startSandbox, + assertResponse, + flushTablesSandbox, + flushTablesNexus +) + +# 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 = "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 + ) + ) + ) + +def prepareNexus(): + # make a new nexus user. + assertResponse( + post( + "http://localhost:5001/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( + "http://localhost:5001/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( + "http://localhost:5001/bank-connections/my-ebics/connect", + json=dict(), + auth=NEXUS_AUTH + ) + ) + # download offered bank accounts + assertResponse( + post( + "http://localhost:5001/bank-connections/my-ebics/fetch-accounts", + json=dict(), + auth=NEXUS_AUTH + ) + ) + # import one bank account into the Nexus + assertResponse( + post( + "http://localhost:5001/bank-connections/my-ebics/import-account", + json=dict( + offeredAccountId=BANK_LABEL, + nexusBankAccountId=NEXUS_BANK_LABEL + ), + auth=NEXUS_AUTH + ) + ) + +startNexus(NEXUS_DB) +startSandbox(SANDBOX_DB) + +prepareSandbox() +prepareNexus() + +#def test_0(): +# assertResponse( +# REQUEST HERE! +# ) + +flushTablesNexus(NEXUS_DB) +flushTablesSandbox(SANDBOX_DB) diff --git a/integration-tests/util.py b/integration-tests/util.py @@ -155,8 +155,4 @@ 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) - return response + assert response.status_code in acceptedResponses