diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-06-08 17:57:09 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-06-08 17:57:09 +0530 |
commit | 142df4189b48f00ebf0b227ff646dc62a86efe40 (patch) | |
tree | af54c26c759bba581f320c5f02600e3f17faea65 /integration-tests | |
parent | 3dbf7c87943e8ff7c1194d65ac60c1665d2d1a90 (diff) | |
download | libeufin-142df4189b48f00ebf0b227ff646dc62a86efe40.tar.gz libeufin-142df4189b48f00ebf0b227ff646dc62a86efe40.tar.bz2 libeufin-142df4189b48f00ebf0b227ff646dc62a86efe40.zip |
use integration test helpers everywhere
Diffstat (limited to 'integration-tests')
-rwxr-xr-x | integration-tests/test-ebics-backup.py | 70 | ||||
-rwxr-xr-x | integration-tests/test-ebics-highlevel.py | 2 | ||||
-rwxr-xr-x | integration-tests/test-ebics.py | 69 | ||||
-rwxr-xr-x | integration-tests/test-loopback-highlevel.py | 48 | ||||
-rwxr-xr-x | integration-tests/test-sandbox.py | 38 | ||||
-rwxr-xr-x | integration-tests/test-taler-facade.py | 53 | ||||
-rw-r--r-- | integration-tests/util.py | 42 |
7 files changed, 41 insertions, 281 deletions
diff --git a/integration-tests/test-ebics-backup.py b/integration-tests/test-ebics-backup.py index ea51f6c0..7b4b126e 100755 --- a/integration-tests/test-ebics-backup.py +++ b/integration-tests/test-ebics-backup.py @@ -8,6 +8,8 @@ import socket import hashlib import base64 +from util import startNexus, startSandbox + # Steps implemented in this test. # # 0 Prepare sandbox. @@ -52,82 +54,20 @@ NEXUS_DB="test-nexus.sqlite3" def fail(msg): print(msg) - nexus.terminate() - sandbox.terminate() exit(1) - -def checkPorts(ports): - for i in ports: - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - try: - s.bind(("0.0.0.0", i)) - s.close() - except: - print("Port {} is not available".format(i)) - exit(77) - - def assertResponse(response): if response.status_code != 200: print("Test failed on URL: {}".format(response.url)) # stdout/stderr from both services is A LOT of text. # Confusing to dump all that to console. print("Check nexus.log and sandbox.log, probably under /tmp") - nexus.terminate() - sandbox.terminate() exit(1) # Allows for finer grained checks. return response - -# -1 Clean databases and start services. -os.chdir("..") -assert 0 == call(["rm", "-f", "sandbox/libeufin-sandbox.sqlite3"]) -assert 0 == call(["rm", "-f", "nexus/{}".format(NEXUS_DB)]) -DEVNULL = open(os.devnull, "w") - -assert 0 == call( - ["./gradlew", "nexus:run", "--console=plain", "--args=superuser admin --password x --db-name={}".format(NEXUS_DB)] -) - -# Start nexus -checkPorts([5001]) -nexus = Popen( - ["./gradlew", "nexus:run", "--console=plain", "--args=serve --db-name={}".format(NEXUS_DB)], - stdout=PIPE, - stderr=PIPE, -) -for i in range(10): - try: - get("http://localhost:5001/") - except: - if i == 9: - nexus.terminate() - stdout, stderr = nexus.communicate() - print("Nexus timed out") - print("{}\n{}".format(stdout.decode(), stderr.decode())) - exit(77) - sleep(2) - continue - break -# Start sandbox -checkPorts([5000]) -sandbox = Popen(["./gradlew", "sandbox:run"], stdout=PIPE, stderr=PIPE) -for i in range(10): - try: - get("http://localhost:5000/") - except: - if i == 9: - nexus.terminate() - sandbox.terminate() - stdout, stderr = nexus.communicate() - print("Sandbox timed out") - print("{}\n{}".format(stdout.decode(), stderr.decode())) - exit(77) - sleep(2) - continue - break +startNexus(NEXUS_DB) +startSandbox() # 0.a assertResponse( @@ -227,6 +167,4 @@ assertResponse( ) ) -nexus.terminate() -sandbox.terminate() print("Test passed!") diff --git a/integration-tests/test-ebics-highlevel.py b/integration-tests/test-ebics-highlevel.py index 22ad4b33..f78f09ff 100755 --- a/integration-tests/test-ebics-highlevel.py +++ b/integration-tests/test-ebics-highlevel.py @@ -78,8 +78,6 @@ def assertResponse(response): return response -os.chdir("..") - startNexus(NEXUS_DB) startSandbox() diff --git a/integration-tests/test-ebics.py b/integration-tests/test-ebics.py index 5c37a58e..04d1c810 100755 --- a/integration-tests/test-ebics.py +++ b/integration-tests/test-ebics.py @@ -8,6 +8,8 @@ import socket import hashlib import base64 +from util import startNexus, startSandbox + # Steps implemented in this test. # # 0 Prepare sandbox. @@ -63,82 +65,21 @@ NEXUS_DB="test-nexus.sqlite3" def fail(msg): print(msg) - nexus.terminate() - sandbox.terminate() exit(1) - -def checkPorts(ports): - for i in ports: - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - try: - s.bind(("0.0.0.0", i)) - s.close() - except: - print("Port {} is not available".format(i)) - exit(77) - - def assertResponse(response): if response.status_code != 200: print("Test failed on URL: {}".format(response.url)) # stdout/stderr from both services is A LOT of text. # Confusing to dump all that to console. print("Check nexus.log and sandbox.log, probably under /tmp") - nexus.terminate() - sandbox.terminate() exit(1) # Allows for finer grained checks. return response +startSandbox() +startNexus(NEXUS_DB) -# -1 Clean databases and start services. -os.chdir("..") -assert 0 == call(["rm", "-f", "sandbox/libeufin-sandbox.sqlite3"]) -assert 0 == call(["rm", "-f", "nexus/{}".format(NEXUS_DB)]) -DEVNULL = open(os.devnull, "w") - -assert 0 == call( - ["./gradlew", "nexus:run", "--console=plain", "--args=superuser admin --password x --db-name={}".format(NEXUS_DB)] -) - -# Start nexus -checkPorts([5001]) -nexus = Popen( - ["./gradlew", "nexus:run", "--console=plain", "--args=serve --db-name={}".format(NEXUS_DB)], - stdout=PIPE, - stderr=PIPE, -) -for i in range(10): - try: - get("http://localhost:5001/") - except: - if i == 9: - nexus.terminate() - stdout, stderr = nexus.communicate() - print("Nexus timed out") - print("{}\n{}".format(stdout.decode(), stderr.decode())) - exit(77) - sleep(2) - continue - break -# Start sandbox -checkPorts([5000]) -sandbox = Popen(["./gradlew", "sandbox:run"], stdout=PIPE, stderr=PIPE) -for i in range(10): - try: - get("http://localhost:5000/") - except: - if i == 9: - nexus.terminate() - sandbox.terminate() - stdout, stderr = nexus.communicate() - print("Sandbox timed out") - print("{}\n{}".format(stdout.decode(), stderr.decode())) - exit(77) - sleep(2) - continue - break # 0.a assertResponse( @@ -302,6 +243,4 @@ resp = assertResponse( if len(resp.json().get("transactions")) != 1: fail("Unexpected number of transactions; should be 1") -nexus.terminate() -sandbox.terminate() print("Test passed!") diff --git a/integration-tests/test-loopback-highlevel.py b/integration-tests/test-loopback-highlevel.py index 74d037e8..dcda6433 100755 --- a/integration-tests/test-loopback-highlevel.py +++ b/integration-tests/test-loopback-highlevel.py @@ -8,6 +8,8 @@ import socket import hashlib import base64 +from util import startSandbox, startNexus + # Steps implemented in this test. # # 0 Prepare nexus. @@ -33,62 +35,19 @@ NEXUS_DB="test-nexus.sqlite3" def fail(msg): print(msg) - nexus.terminate() exit(1) - -def checkPorts(ports): - for i in ports: - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - try: - s.bind(("0.0.0.0", i)) - s.close() - except: - print("Port {} is not available".format(i)) - exit(77) - - def assertResponse(response): if response.status_code != 200: print("Test failed on URL: {}".format(response.url)) # stdout/stderr from both services is A LOT of text. # Confusing to dump all that to console. print("Check nexus.log and sandbox.log, probably under /tmp") - nexus.terminate() exit(1) # Allows for finer grained checks. return response - -# -1 Clean databases and start services. -os.chdir("..") -assert 0 == call(["rm", "-f", "nexus/{}".format(NEXUS_DB)]) -DEVNULL = open(os.devnull, "w") - -assert 0 == call( - ["./gradlew", "nexus:run", "--console=plain", "--args=superuser admin --password x --db-name={}".format(NEXUS_DB)] -) - -# Start nexus -checkPorts([5001]) -nexus = Popen( - ["./gradlew", "nexus:run", "--console=plain", "--args=serve --db-name={}".format(NEXUS_DB)], - stdout=PIPE, - stderr=PIPE, -) -for i in range(10): - try: - get("http://localhost:5001/") - except: - if i == 9: - nexus.terminate() - stdout, stderr = nexus.communicate() - print("Nexus timed out") - print("{}\n{}".format(stdout.decode(), stderr.decode())) - exit(77) - sleep(2) - continue - break +startNexus(NEXUS_DB) # 0.a, make a new nexus user. assertResponse( @@ -120,5 +79,4 @@ assertResponse( ) ) -nexus.terminate() print("Test passed!") diff --git a/integration-tests/test-sandbox.py b/integration-tests/test-sandbox.py index 944514a7..ba9b709f 100755 --- a/integration-tests/test-sandbox.py +++ b/integration-tests/test-sandbox.py @@ -8,6 +8,8 @@ import socket import hashlib import base64 +from util import startSandbox + # EBICS details EBICS_URL = "http://localhost:5000/ebicsweb" HOST_ID = "HOST01" @@ -24,53 +26,19 @@ BANK_ACCOUNT_LABEL = "savings" def fail(msg): print(msg) - sandbox.terminate() exit(1) - -def checkPorts(ports): - for i in ports: - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - try: - s.bind(("0.0.0.0", i)) - s.close() - except: - print("Port {} is not available".format(i)) - exit(77) - - def assertResponse(response): if response.status_code != 200: print("Test failed on URL: {}".format(response.url)) # stdout/stderr from both services is A LOT of text. # Confusing to dump all that to console. print("Check sandbox.log, probably under /tmp") - sandbox.terminate() exit(1) # Allows for finer grained checks. return response - -# -1 Clean databases and start the service. -os.chdir("..") -assert 0 == call(["rm", "-f", "sandbox/libeufin-sandbox.sqlite3"]) -DEVNULL = open(os.devnull, "w") - -# Start sandbox -checkPorts([5000]) -sandbox = Popen(["./gradlew", "sandbox:run"], stdout=PIPE, stderr=PIPE) -for i in range(10): - try: - get("http://localhost:5000/") - except: - if i == 9: - sandbox.terminate() - print("Sandbox timed out") - print("{}\n{}".format(stdout.decode(), stderr.decode())) - exit(77) - sleep(2) - continue - break +startSandbox() # Create a Ebics host. assertResponse( diff --git a/integration-tests/test-taler-facade.py b/integration-tests/test-taler-facade.py index 8b2e15d8..30025cc1 100755 --- a/integration-tests/test-taler-facade.py +++ b/integration-tests/test-taler-facade.py @@ -8,6 +8,8 @@ import socket import hashlib import base64 +from util import startNexus, startSandbox + # Nexus user details USERNAME = "person" PASSWORD = "y" @@ -40,8 +42,6 @@ SANDBOX_DB="/tmp/test-sandbox.sqlite3" def fail(msg): print(msg) - nexus.terminate() - sandbox.terminate() exit(1) def checkPorts(ports): @@ -60,55 +60,14 @@ def assertResponse(response): # stdout/stderr from both services is A LOT of text. # Confusing to dump all that to console. print("Check nexus.log and sandbox.log, probably under /tmp") - nexus.terminate() - sandbox.terminate() exit(1) # Allows for finer grained checks. return response -# Clean databases and start services. -os.chdir("..") -assert 0 == call(["rm", "-f", SANDBOX_DB]) -assert 0 == call(["rm", "-f", NEXUS_DB]) -DEVNULL = open(os.devnull, "w") - -assert 0 == call( - ["nexus", "superuser", "admin", "--password=x", "--db-name={}".format(NEXUS_DB)] -) -# start nexus -checkPorts([5001]) -nexus = Popen(["nexus", "serve", "--db-name={}".format(NEXUS_DB)]) -for i in range(10): - try: - get("http://localhost:5001/") - except: - if i == 9: - nexus.terminate() - print("Nexus timed out") - print("{}\n{}".format(stdout.decode(), stderr.decode())) - exit(77) - sleep(2) - continue - break - -# start sandbox -checkPorts([5000]) -sandbox = Popen(["sandbox", "serve", "--db-name={}".format(SANDBOX_DB)]) -for i in range(10): - try: - get("http://localhost:5000/") - except: - if i == 9: - nexus.terminate() - sandbox.terminate() - stdout, stderr = nexus.communicate() - print("Sandbox timed out") - print("{}\n{}".format(stdout.decode(), stderr.decode())) - exit(77) - sleep(2) - continue - break +os.chdir("..") +startNexus(NEXUS_DB) +startSandbox() # make ebics host at sandbox assertResponse( @@ -239,6 +198,4 @@ assertResponse( print("sleeping 100s") sleep(100) -nexus.terminate() -sandbox.terminate() print("Test passed!") diff --git a/integration-tests/util.py b/integration-tests/util.py index aae7f5e3..86e3f6af 100644 --- a/integration-tests/util.py +++ b/integration-tests/util.py @@ -5,6 +5,7 @@ import socket from requests import post, get from time import sleep import atexit +from pathlib import Path def checkPort(port): @@ -13,21 +14,20 @@ def checkPort(port): s.bind(("0.0.0.0", port)) s.close() except: - print("Port {} is not available".format(i)) + print(f"Port {port} is not available") exit(77) def startSandbox(): - check_call(["rm", "-f", "sandbox/libeufin-sandbox.sqlite3"]) - check_call(["./gradlew", "sandbox:assemble"]) + db_full_path = str(Path.cwd() / "libeufin-sandbox.sqlite3") + check_call(["rm", "-f", db_full_path]) + check_call(["../gradlew", "-p", "..", "sandbox:assemble"]) checkPort(5000) - sandbox = Popen(["./gradlew", - "sandbox:run", - "--console=plain", - "--args=serve"], - stdout=open("sandbox-stdout.log", "w"), - stderr=open("sandbox-stderr.log", "w"), - ) + sandbox = Popen( + ["../gradlew", "-p", "..", "sandbox:run", "--console=plain", "--args=serve --db-name={}".format(db_full_path)], + stdout=open("sandbox-stdout.log", "w"), + stderr=open("sandbox-stderr.log", "w"), + ) atexit.register(lambda: sandbox.terminate()) for i in range(10): try: @@ -43,29 +43,31 @@ def startSandbox(): break -def startNexus(dbfile): - check_call(["rm", "-f", "nexus/{}".format(dbfile)]) +def startNexus(dbname): + db_full_path = str(Path.cwd() / dbname) + check_call(["rm", "-f", "--", db_full_path]) check_call( - [ - "./gradlew", - "nexus:assemble", - ] + ["../gradlew", "-p", "..", "nexus:assemble",] ) check_call( [ - "./gradlew", + "../gradlew", + "-p", + "..", "nexus:run", "--console=plain", - "--args=superuser admin --password x --db-name={}".format(dbfile), + "--args=superuser admin --password x --db-name={}".format(db_full_path), ] ) checkPort(5001) nexus = Popen( [ - "./gradlew", + "../gradlew", + "-p", + "..", "nexus:run", "--console=plain", - "--args=serve --db-name={}".format(dbfile), + "--args=serve --db-name={}".format(db_full_path), ], stdout=open("nexus-stdout.log", "w"), stderr=open("nexus-stderr.log", "w"), |