libeufin

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

commit ee29004c64cf2ccf3640857b8f71139713a814bc
parent 0d98056099e00df3ba5554660d95b3b8a1d121a0
Author: MS <ms@taler.net>
Date:   Tue,  8 Dec 2020 09:39:49 +0100

Migrating to Postgresql.

Diffstat:
Mintegration-tests/tests.py | 24++++++++++--------------
Mintegration-tests/util.py | 71+++++++++++++++++++++++++++++++----------------------------------------
Mnexus/src/main/kotlin/tech/libeufin/nexus/DB.kt | 2+-
Msandbox/build.gradle | 1+
Msandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt | 2+-
5 files changed, 44 insertions(+), 56 deletions(-)

diff --git a/integration-tests/tests.py b/integration-tests/tests.py @@ -13,16 +13,15 @@ from util import ( flushTablesSandbox, flushTablesNexus, makeNexusSuperuser, - removeStaleDatabase + removeStaleTables ) # Base URLs S = "http://localhost:5000" N = "http://localhost:5001" -# Databases -NEXUS_DB="/tmp/test-nexus.sqlite3" -SANDBOX_DB="/tmp/test-sandbox.sqlite3" +# Database +DB = "libeufintestdb" # Nexus user details NEXUS_USERNAME = "person" @@ -80,7 +79,7 @@ def prepareSandbox(): ) def prepareNexus(): - makeNexusSuperuser(NEXUS_DB) + makeNexusSuperuser(DB) # make a new nexus user. assertResponse( post( @@ -135,19 +134,17 @@ def prepareNexus(): ) ) -removeStaleDatabase(NEXUS_DB) -startNexus(NEXUS_DB) - -removeStaleDatabase(SANDBOX_DB) -startSandbox(SANDBOX_DB) +removeStaleTables(DB) +startNexus(DB) +startSandbox(DB) def setup_function(): prepareSandbox() prepareNexus() def teardown_function(): - flushTablesNexus(NEXUS_DB) - flushTablesSandbox(SANDBOX_DB) + flushTablesNexus(DB) + flushTablesSandbox(DB) def test_env(): @@ -314,8 +311,7 @@ def test_payment_double_submission(): ) ) check_call([ - "sqlite3", - NEXUS_DB, + "psql", "-d", DB, f"UPDATE PaymentInitiations SET submitted = false WHERE id = '{PAYMENT_UUID}'" ]) # Submit payment the _second_ time, expecting 500 from Nexus. diff --git a/integration-tests/util.py b/integration-tests/util.py @@ -46,10 +46,9 @@ def kill(name, s): s.terminate() s.wait() -def removeStaleDatabase(dbName): - db_full_path = str(Path.cwd() / dbName) - if os.path.exists(db_full_path): - os.remove(db_full_path) +def removeStaleTables(dbName): + flushTablesNexus(dbName) + flushTablesSandbox(dbName) def makeNexusSuperuser(dbName): db_full_path = str(Path.cwd() / dbName) @@ -66,48 +65,42 @@ def makeNexusSuperuser(dbName): ) def flushTablesSandbox(dbName): - db_full_path = str(Path.cwd() / dbName) check_call( - ["sqlite3", - db_full_path, - "DELETE FROM BankAccountReports", - "DELETE FROM EbicsOrderSignatures", - "DELETE FROM BankAccountStatements", - "DELETE FROM EbicsSubscriberPublicKeys", - "DELETE FROM BankAccountTransactions", - "DELETE FROM EbicsSubscribers", - "DELETE FROM BankAccounts", - "DELETE FROM EbicsUploadTransactionChunks", - "DELETE FROM EbicsDownloadTransactions", - "DELETE FROM EbicsUploadTransactions", - "DELETE FROM EbicsHosts" + ["psql", "-d", dbName, + "-c", "DELETE FROM BankAccountReports", + "-c", "DELETE FROM EbicsOrderSignatures", + "-c", "DELETE FROM BankAccountStatements", + "-c", "DELETE FROM EbicsSubscriberPublicKeys", + "-c", "DELETE FROM BankAccountTransactions", + "-c", "DELETE FROM EbicsSubscribers", + "-c", "DELETE FROM BankAccounts", + "-c", "DELETE FROM EbicsUploadTransactionChunks", + "-c", "DELETE FROM EbicsDownloadTransactions", + "-c", "DELETE FROM EbicsUploadTransactions", + "-c", "DELETE FROM EbicsHosts" ] ) def flushTablesNexus(dbName): - db_full_path = str(Path.cwd() / dbName) check_call( - ["sqlite3", - db_full_path, - "DELETE FROM EbicsSubscribers", - "DELETE FROM NexusBankTransactions", - "DELETE FROM TalerFacadeState", - "DELETE FROM Facades", - "DELETE FROM NexusScheduledTasks", - "DELETE FROM TalerIncomingPayments", - "DELETE FROM NexusBankAccounts", - "DELETE FROM NexusUsers", - "DELETE FROM TalerRequestedPayments", - "DELETE FROM NexusBankConnections", - "DELETE FROM OfferedBankAccounts", - "DELETE FROM NexusBankMessages", - "DELETE FROM PaymentInitiations" + ["psql", "-d", dbName, + "-c", "DELETE FROM EbicsSubscribers", + "-c", "DELETE FROM NexusBankTransactions", + "-c", "DELETE FROM TalerFacadeState", + "-c", "DELETE FROM Facades", + "-c", "DELETE FROM NexusScheduledTasks", + "-c", "DELETE FROM TalerIncomingPayments", + "-c", "DELETE FROM NexusBankAccounts", + "-c", "DELETE FROM NexusUsers", + "-c", "DELETE FROM TalerRequestedPayments", + "-c", "DELETE FROM NexusBankConnections", + "-c", "DELETE FROM OfferedBankAccounts", + "-c", "DELETE FROM NexusBankMessages", + "-c", "DELETE FROM PaymentInitiations" ] ) -def startSandbox(dbName="sandbox-test.sqlite3"): - db_full_path = str(Path.cwd() / dbName) - check_call(["rm", "-f", db_full_path]) +def startSandbox(dbName): check_call(["../gradlew", "-q", "-p", "..", "sandbox:assemble"]) checkPort(5000) sandbox = Popen( @@ -131,9 +124,7 @@ def startSandbox(dbName="sandbox-test.sqlite3"): break -def startNexus(dbName="nexus-test.sqlite3"): - db_full_path = str(Path.cwd() / dbName) - check_call(["rm", "-f", "--", db_full_path]) +def startNexus(dbName): check_call( ["../gradlew", "-q", "-p", "..", "nexus:assemble",] ) diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt @@ -385,7 +385,7 @@ class NexusScheduledTaskEntity(id: EntityID<Int>) : IntEntity(id) { } fun dbCreateTables(dbName: String) { - Database.connect("jdbc:sqlite:${dbName}", "org.sqlite.JDBC") + Database.connect("jdbc:postgresql:${dbName}", "org.postgresql.Driver") TransactionManager.manager.defaultIsolationLevel = Connection.TRANSACTION_SERIALIZABLE transaction { addLogger(StdOutSqlLogger) diff --git a/sandbox/build.gradle b/sandbox/build.gradle @@ -54,6 +54,7 @@ dependencies { implementation 'org.apache.santuario:xmlsec:2.1.4' implementation group: 'org.bouncycastle', name: 'bcprov-jdk16', version: '1.45' implementation group: 'org.xerial', name: 'sqlite-jdbc', version: '3.28.0' + implementation "org.postgresql:postgresql:42.2.18" implementation group: 'org.apache.commons', name: 'commons-compress', version: '1.20' implementation("com.github.ajalt:clikt:2.7.0") implementation "org.jetbrains.exposed:exposed-core:$exposed_version" diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt @@ -302,7 +302,7 @@ object BankAccountReportsTable : IntIdTable() { } fun dbCreateTables(dbName: String) { - Database.connect("jdbc:sqlite:${dbName}", "org.sqlite.JDBC") + Database.connect("jdbc:postgresql:${dbName}", "org.postgresql.Driver") TransactionManager.manager.defaultIsolationLevel = Connection.TRANSACTION_SERIALIZABLE transaction { addLogger(StdOutSqlLogger)