From f57371e5ca1c4b28a7151a0663688240b2431514 Mon Sep 17 00:00:00 2001 From: Francesco Cesareo Date: Mon, 15 Jan 2024 16:56:47 +0100 Subject: [PATCH 1/9] wip --- int_test_nodo.sh | 6 +- .../bdd-test/features/environment.py | 14 +- .../db_operation_apicfg_testing_support.py | 49 ++++ src/integ-test/bdd-test/resources/config.json | 267 +++++++++--------- .../resources/query_AutomationTest.json | 3 +- 5 files changed, 203 insertions(+), 136 deletions(-) create mode 100644 src/integ-test/bdd-test/features/steps/db_operation_apicfg_testing_support.py diff --git a/int_test_nodo.sh b/int_test_nodo.sh index c0d35ebb26..ed4c0c4f12 100644 --- a/int_test_nodo.sh +++ b/int_test_nodo.sh @@ -3,7 +3,8 @@ pip install -U -r ./requirements.txt < list: + print('execute_sql_query ...') + print(query) + try: + print('executing_sql_query ...') + headers = {} + if 'APICFG_SUBSCRIPTION_KEY' in os.environ: + headers["Ocp-Apim-Subscription-Key"] = "" + + url = apicfg_testing_support.get("base_path") + apicfg_testing_support.get("service") + response = requests.post(url, data=query, headers=headers) + return response.json() + except Exception as e: + print(f"The error '{e}' occurred") + + +def closeConnection(conn) -> None: + print('Fake connection closed successfully') diff --git a/src/integ-test/bdd-test/resources/config.json b/src/integ-test/bdd-test/resources/config.json index 83c3e7847c..7fc672ddf8 100644 --- a/src/integ-test/bdd-test/resources/config.json +++ b/src/integ-test/bdd-test/resources/config.json @@ -1,132 +1,139 @@ { - "_comment": "this file should be generated by test caller in order to configure systems and variables environment", - "services": { - "nodo-dei-pagamenti": { - "url": "http://localhost:9080/", - "healthcheck": "nodo-dev-health/ready", - "soap_service": "", - "rest_service": "nodo-dev", - "refresh_config_service": "nodo-dev/config/refresh/CONFIG" - }, - "mock-ec": { - "url": "http://localhost:8089/", - "healthcheck": "servizi/PagamentiTelematiciRPT/info", - "soap_service": "servizi/PagamentiTelematiciRPT", - "rest_service": "" - }, - "mock-psp": { - "url": "http://localhost:8090/", - "healthcheck": "servizi/MockPSP/info", - "soap_service": "servizi/MockPSP", - "rest_service": "" - }, - "mock-pm": { - "url": "http://localhost:8084/", - "healthcheck": "/info", - "soap_service": "", - "rest_service": "" - }, - "secondary-mock-ec": { - "url": "http://localhost:8091/", - "healthcheck": "servizi/PagamentiTelematiciRPT/info", - "soap_service": "servizi/PagamentiTelematiciRPT", - "rest_service": "" - }, - "secondary-mock-psp": { - "url": "http://localhost:8092/", - "healthcheck": "servizi/MockPSP/info", - "soap_service": "servizi/MockPSP", - "rest_service": "" - } - }, - "global_configuration": { - "creditor_institution_code": "66666666666", - "creditor_institution_code_old": "66666666666", - "creditor_institution_code_secondary": "88888888888", - "psp": "60000000001", - "id_broker_psp": "60000000001", - "intermediarioPA": "66666666666", - "intermediarioPAOld": "66666666666", - "fiscalCodePA": "12345678901", - "id_station": "66666666666_01", - "id_station_old": "66666666666_05", - "stazione_versione_primitive_2": "66666666666_08", - "id_station_secondary": "88888888888_01", - "id_station_disabled": "STAZIONE_NOT_ENABLED", - "intermediario_stz_disabled": "INT_STZ_NOT_ENABLED", - "intermediario_disabled": "INT_NOT_ENABLED", - "id_station_int_disabled": "STZ_INT_NOT_ENABLED", - "paDisabled": "NOT_ENABLED", - "pspDisabled": "NOT_ENABLED", - "canale": "60000000001_07", - "canaleRtPull": "60000000001_06", - "canaleRtPush": "60000000001_03", - "canale_ATTIVATO_PRESSO_PSP": "60000000001_01", - "canale_IMMEDIATO_MULTIBENEFICIARIO": "60000000001_03", - "canale_DIFFERITO_MOD2": "60000000001_04", - "canaleRtPull_sec": "60000000001_03_ONUS", - "intermediarioPSP2": "60000000002", - "canale32": "60000000002_01", - "canale_versione_primitive_2": "60000000001_08", - "id_broker": "66666666666", - "id_broker_old": "66666666666", - "cod_segr": "02", - "cod_segr_old": "12", - "Gln": "6666666666666", - "ccPoste": "666666666666", - "ccPoste_noIBAN": "616666666666", - "pspPoste": "POSTE3", - "brokerPspPoste": "BANCOPOSTA", - "channelPoste": "POSTE3", - "psp_AGID": "AGID_01", - "broker_AGID": "97735020584", - "canale_AGID": "97735020584_03", - "canale_AGID_02": "97735020584_02", - "canale_AGID_BBT": "97735020584_02", - "password": "pwdpwdpwd", - "pspEcommerce": "36892710904", - "brokerEcommerce": "36892710904", - "canaleEcommerce": "36892710904_02", - "ragione_sociale": "PA paolo", - "pspFittizio": "15376371009", - "brokerFittizio": "15376371009", - "canaleFittizio": "15376371009_01" - }, - "db_configuration": { - "nodo_cfg": { - "host": "localhost", - "database": "ORCLCDB.localdomain", - "user": "NODO4_CFG", - "password": "NODO4_CFG", - "port": "1521" - }, - "nodo_online": { - "host": "localhost", - "database": "NDPSPCT_NODO_ONLINE", - "user": "NODO_ONLINE", - "password": "NODO_ONLINE", - "port": "1522" - }, - "nodo_offline": { - "host": "localhost", - "database": "ORCLCDB.localdomain", - "user": "NODO_OFFLINE", - "password": "NODO_OFFLINE", - "port": "1521" - }, - "re": { - "host": "localhost", - "database": "ORCLCDB.localdomain", - "user": "RE", - "password": "RE", - "port": "1521" - }, - "wfesp": { - "host": "localhost", - "database": "ORCLCDB.localdomain", - "user": "WFESP", - "password": "WEFSP", - "port": "1521" - } - } + "_comment": "this file should be generated by test caller in order to configure systems and variables environment", + "services": { + "nodo-dei-pagamenti": { + "url": "https://api.dev.platform.pagopa.it/nodo-replica-ndp", + "healthcheck": "", + "soap_service": " ", + "rest_service": " ", + "refresh_config_service": "https://api.dev.platform.pagopa.it/nodo-replica-ndp/monitoring/v1/config/refresh/CONFIG" + }, + "mock-ec": { + "url": "https://api.dev.platform.pagopa.it/mock-ec-replica-ndp/service/v1/mock", + "healthcheck": "/info", + "soap_service": "", + "rest_service": "" + }, + "mock-psp": { + "url": "https://api.dev.platform.pagopa.it/mock-psp-replica-ndp/service/v1/mock", + "healthcheck": "/info", + "soap_service": "", + "rest_service": "" + }, + "mock-pm": { + "url": "https://api.dev.platform.pagopa.it/mock-pm-replica-ndp/service/v1", + "healthcheck": "/", + "soap_service": "", + "rest_service": "" + }, + "secondary-mock-ec": { + "url": "https://api.dev.platform.pagopa.it/mock-ec-replica-secondary-ndp/service/v1/mock", + "healthcheck": "/info", + "soap_service": "", + "rest_service": "" + }, + "secondary-mock-psp": { + "url": "https://api.dev.platform.pagopa.it/mock-psp-secondary-replica-ndp/service/v1/mock", + "healthcheck": "/info", + "soap_service": "", + "rest_service": "" + }, + "apicfg-testing-support": { + "url": "http://localhost:8080", + "healthcheck": "/info", + "soap_service": " ", + "rest_service": " ", + "refresh_config_service": "" + } + }, + "global_configuration": { + "creditor_institution_code": "66666666666", + "creditor_institution_code_old": "66666666666", + "creditor_institution_code_secondary": "88888888888", + "psp": "60000000001", + "id_broker_psp": "60000000001", + "intermediarioPA": "66666666666", + "intermediarioPAOld": "66666666666", + "fiscalCodePA": "12345678901", + "id_station": "66666666666_01", + "id_station_old": "66666666666_05", + "stazione_versione_primitive_2": "66666666666_08", + "id_station_secondary": "88888888888_01", + "id_station_disabled": "STAZIONE_NOT_ENABLED", + "intermediario_stz_disabled": "INT_STZ_NOT_ENABLED", + "intermediario_disabled": "INT_NOT_ENABLED", + "id_station_int_disabled": "STZ_INT_NOT_ENABLED", + "paDisabled": "NOT_ENABLED", + "pspDisabled": "NOT_ENABLED", + "canale": "60000000001_07", + "canaleRtPull": "60000000001_06", + "canaleRtPush": "60000000001_03", + "canale_ATTIVATO_PRESSO_PSP": "60000000001_01", + "canale_IMMEDIATO_MULTIBENEFICIARIO": "60000000001_03", + "canale_DIFFERITO_MOD2": "60000000001_04", + "canaleRtPull_sec": "60000000001_03_ONUS", + "intermediarioPSP2": "60000000002", + "canale32": "60000000002_01", + "canale_versione_primitive_2": "60000000001_08", + "id_broker": "66666666666", + "id_broker_old": "66666666666", + "cod_segr": "02", + "cod_segr_old": "12", + "Gln": "6666666666666", + "ccPoste": "666666666666", + "ccPoste_noIBAN": "616666666666", + "pspPoste": "POSTE3", + "brokerPspPoste": "BANCOPOSTA", + "channelPoste": "POSTE3", + "psp_AGID": "AGID_01", + "broker_AGID": "97735020584", + "canale_AGID": "97735020584_03", + "canale_AGID_02": "97735020584_02", + "canale_AGID_BBT": "97735020584_02", + "password": "pwdpwdpwd", + "pspEcommerce": "36892710904", + "brokerEcommerce": "36892710904", + "canaleEcommerce": "36892710904_02", + "ragione_sociale": "PA paolo", + "pspFittizio": "15376371009", + "brokerFittizio": "15376371009", + "canaleFittizio": "15376371009_01" + }, + "db_configuration": { + "nodo_cfg": { + "host": "pagopa-d-weu-nodo-flexible-postgresql.postgres.database.azure.com", + "database": "nodo", + "user": "cfg", + "password": "password", + "port": "5432" + }, + "nodo_online": { + "host": "pagopa-d-weu-nodo-flexible-postgresql.postgres.database.azure.com", + "database": "nodo", + "user": "online", + "password": "password", + "port": "5432" + }, + "nodo_offline": { + "host": "pagopa-d-weu-nodo-flexible-postgresql.postgres.database.azure.com", + "database": "nodo", + "user": "offline", + "password": "password", + "port": "5432" + }, + "re": { + "host": "pagopa-d-weu-nodo-flexible-postgresql.postgres.database.azure.com", + "database": "nodo", + "user": "re", + "password": "password", + "port": "5432" + }, + "wfesp": { + "host": "pagopa-d-weu-nodo-flexible-postgresql.postgres.database.azure.com", + "database": "nodo", + "user": "wfesp", + "password": "password", + "port": "5432" + } + } } diff --git a/src/integ-test/bdd-test/resources/query_AutomationTest.json b/src/integ-test/bdd-test/resources/query_AutomationTest.json index c6efcafa84..d04a6bc049 100644 --- a/src/integ-test/bdd-test/resources/query_AutomationTest.json +++ b/src/integ-test/bdd-test/resources/query_AutomationTest.json @@ -1,7 +1,8 @@ { "configurations": { "select_config": "SELECT ck.CONFIG_KEY, ck.CONFIG_VALUE from CONFIGURATION_KEYS ck", - "update_config": "UPDATE CONFIGURATION_KEYS s SET s.CONFIG_VALUE = q'[value]' WHERE s.CONFIG_KEY = 'key'", + "update_config": "UPDATE CONFIGURATION_KEYS SET CONFIG_VALUE = E'[value]' WHERE CONFIG_KEY = 'key'", + "update_config_oracle": "UPDATE CONFIGURATION_KEYS s SET s.CONFIG_VALUE = q'[value]' WHERE s.CONFIG_KEY = 'key'", "update_config_pg" : "UPDATE cfg.CONFIGURATION_KEYS SET CONFIG_VALUE = 'value' WHERE CONFIG_KEY = 'key'" }, "NewMod3": { From 6a3188e9a34d4be3b5bfa1dbc0dfd6af55e219ab Mon Sep 17 00:00:00 2001 From: Francesco Cesareo Date: Fri, 19 Jan 2024 12:06:52 +0100 Subject: [PATCH 2/9] improvements --- .../bdd-test/features/environment.py | 9 +- .../db_operation_apicfg_testing_support.py | 2 +- .../bdd-test/features/steps/steps.py | 116 ++++++++---------- .../bdd-test/features/steps/utils.py | 16 ++- 4 files changed, 69 insertions(+), 74 deletions(-) diff --git a/src/integ-test/bdd-test/features/environment.py b/src/integ-test/bdd-test/features/environment.py index b2a2ef93a0..b28510f512 100644 --- a/src/integ-test/bdd-test/features/environment.py +++ b/src/integ-test/bdd-test/features/environment.py @@ -1,15 +1,14 @@ import json from behave.model import Table -import os, requests +import os import steps.utils as utils -import time + if 'NODOPGDB' in os.environ: import steps.db_operation_pg as db - import psycopg2 - from psycopg2 import OperationalError else: import steps.db_operation as db - import os, cx_Oracle, requests + import cx_Oracle + import requests if 'APICFG' in os.environ: import steps.db_operation_apicfg_testing_support as db diff --git a/src/integ-test/bdd-test/features/steps/db_operation_apicfg_testing_support.py b/src/integ-test/bdd-test/features/steps/db_operation_apicfg_testing_support.py index 51d9cacfc6..688e243958 100644 --- a/src/integ-test/bdd-test/features/steps/db_operation_apicfg_testing_support.py +++ b/src/integ-test/bdd-test/features/steps/db_operation_apicfg_testing_support.py @@ -36,7 +36,7 @@ def executeQuery(conn, query:str) -> list: print('executing_sql_query ...') headers = {} if 'APICFG_SUBSCRIPTION_KEY' in os.environ: - headers["Ocp-Apim-Subscription-Key"] = "" + headers["Ocp-Apim-Subscription-Key"] = os.getenv("APICFG_SUBSCRIPTION_KEY", default="") url = apicfg_testing_support.get("base_path") + apicfg_testing_support.get("service") response = requests.post(url, data=query, headers=headers) diff --git a/src/integ-test/bdd-test/features/steps/steps.py b/src/integ-test/bdd-test/features/steps/steps.py index 13fe26c157..4cdf648220 100644 --- a/src/integ-test/bdd-test/features/steps/steps.py +++ b/src/integ-test/bdd-test/features/steps/steps.py @@ -13,8 +13,14 @@ import xmltodict if 'NODOPGDB' in os.environ: import db_operation_pg as db + import db_operation_pg as db_online + import db_operation_pg as db_offline else: import db_operation as db + import db_operation as db_online + import db_operation as db_offline +if 'APICFG' in os.environ: + import db_operation_apicfg_testing_support as db import json_operations as jo import pytz import requests @@ -1540,12 +1546,12 @@ def step_impl(context, primitive): @step("nodo-dei-pagamenti has config parameter {param} set to {value}") def step_impl(context, param, value): + db_name = "nodo_cfg" db_selected = context.config.userdata.get( - "db_configuration").get('nodo_cfg') + "db_configuration").get(db_name) selected_query = utils.query_json(context, 'update_config', 'configurations').replace( 'value', value).replace('key', param) - conn = db.getConnection(db_selected.get('host'), db_selected.get( - 'database'), db_selected.get('user'), db_selected.get('password'), db_selected.get('port')) + conn = utils.get_db_connection(db_name, db, db_online, db_offline, db_selected) setattr(context, param, value) print(">>>>>>>>>>>>>>>", getattr(context, param)) @@ -1616,8 +1622,8 @@ def step_impl(context, query_name, date, macro, db_name): selected_query = utils.query_json( context, query_name, macro).replace('date', date) - conn = db.getConnection(db_selected.get('host'), db_selected.get( - 'database'), db_selected.get('user'), db_selected.get('password'), db_selected.get('port')) + + conn = utils.get_db_connection(db_name, db, db_online, db_offline, db_selected) exec_query = db.executeQuery(conn, selected_query) db.closeConnection(conn) @@ -1625,10 +1631,10 @@ def step_impl(context, query_name, date, macro, db_name): @then("restore initial configurations") def step_impl(context): + db_name = "nodo_cfg" db_selected = context.config.userdata.get( - "db_configuration").get('nodo_cfg') - conn = db.getConnection(db_selected.get('host'), db_selected.get( - 'database'), db_selected.get('user'), db_selected.get('password'), db_selected.get('port')) + "db_configuration").get(db_name) + conn = utils.get_db_connection(db_name, db, db_online, db_offline, db_selected) config_dict = getattr(context, 'configurations') for key, value in config_dict.items(): @@ -1654,8 +1660,7 @@ def step_impl(context, query_name, macro, db_name, table_name, columns): selected_query = utils.replace_local_variables(selected_query, context) selected_query = utils.replace_global_variables(selected_query, context) - conn = db.getConnection(db_selected.get('host'), db_selected.get( - 'database'), db_selected.get('user'), db_selected.get('password'), db_selected.get('port')) + conn = utils.get_db_connection(db_name, db, db_online, db_offline, db_selected) exec_query = db.executeQuery(conn, selected_query) if exec_query is not None: @@ -1802,8 +1807,7 @@ def step_impl(context, value, column, query_name, table_name, db_name, name_macr db_config = context.config.userdata.get("db_configuration") db_selected = db_config.get(db_name) - conn = db.getConnection(db_selected.get('host'), db_selected.get( - 'database'), db_selected.get('user'), db_selected.get('password'), db_selected.get('port')) + conn = utils.get_db_connection(db_name, db, db_online, db_offline, db_selected) selected_query = utils.query_json(context, query_name, name_macro).replace( "columns", column).replace("table_name", table_name) @@ -1848,8 +1852,7 @@ def step_impl(context, query_name, table_name, param, value, where_condition, va 'param', param).replace('value', value).replace('where_condition', where_condition).replace('valore', valore) selected_query = utils.replace_local_variables(selected_query, context) selected_query = utils.replace_context_variables(selected_query, context) - conn = db.getConnection(db_selected.get('host'), db_selected.get( - 'database'), db_selected.get('user'), db_selected.get('password'), db_selected.get('port')) + conn = utils.get_db_connection(db_name, db, db_online, db_offline, db_selected) exec_query = db.executeQuery(conn, selected_query) db.closeConnection(conn) @@ -1859,8 +1862,7 @@ def step_impl(context, query_name, table_name, where_condition, macro, db_name): selected_query = utils.query_json(context, query_name, macro).replace('table_name', table_name).replace('where_condition', where_condition) selected_query = utils.replace_local_variables(selected_query, context) selected_query = utils.replace_context_variables(selected_query, context) - conn = db.getConnection(db_selected.get('host'), db_selected.get( - 'database'), db_selected.get('user'), db_selected.get('password'), db_selected.get('port')) + conn = utils.get_db_connection(db_name, db, db_online, db_offline, db_selected) exec_query = db.executeQuery(conn, selected_query) db.closeConnection(conn) @@ -1874,8 +1876,7 @@ def step_impl(context, query_name, table_name, param, where_condition, macro, db selected_query = utils.replace_local_variables(selected_query, context) selected_query = utils.replace_context_variables(selected_query, context) selected_query = utils.replace_global_variables(selected_query, context) - conn = db.getConnection(db_selected.get('host'), db_selected.get( - 'database'), db_selected.get('user'), db_selected.get('password'), db_selected.get('port')) + conn = utils.get_db_connection(db_name, db, db_online, db_offline, db_selected) exec_query = db.executeQuery(conn, selected_query) db.closeConnection(conn) @@ -1884,8 +1885,7 @@ def step_impl(context, query_name, table_name, param, where_condition, macro, db def step_impl(context, column, query_name, table_name, db_name, name_macro, number): db_config = context.config.userdata.get("db_configuration") db_selected = db_config.get(db_name) - conn = db.getConnection(db_selected.get('host'), db_selected.get( - 'database'), db_selected.get('user'), db_selected.get('password'), db_selected.get('port')) + conn = utils.get_db_connection(db_name, db, db_online, db_offline, db_selected) if number == 'default_token_duration_validity_millis': default = int( @@ -1897,8 +1897,7 @@ def step_impl(context, column, query_name, table_name, db_name, name_macro, numb query_result = [t[0] for t in exec_query] print('query_result: ', query_result) elem = query_result[0].strftime('%Y-%m-%d %H:%M') - - elif number == 'default_idempotency_key_validity_minutes': + elif number == 'default_idempotency_key_validity_minutes': default = int(getattr(context, 'default_idempotency_key_validity_minutes')) print("###################", default) value = (datetime.datetime.now().astimezone(pytz.timezone('Europe/Rome')) +datetime.timedelta(minutes=default)).strftime('%Y-%m-%d %H:%M') @@ -1909,22 +1908,14 @@ def step_impl(context, column, query_name, table_name, db_name, name_macro, numb query_result = [t[0] for t in exec_query] print('query_result: ', query_result) elem = query_result[0].strftime('%Y-%m-%d %H:%M') - elif number == 'default_durata_estensione_token_IO': - default = int( - getattr(context, 'default_durata_estensione_token_IO')) / 60000 - - + default = int(getattr(context, 'default_durata_estensione_token_IO')) / 60000 value = (datetime.datetime.now().astimezone(pytz.timezone('Europe/Rome')) +datetime.timedelta(minutes=default)).strftime('%Y-%m-%d %H:%M') - - - selected_query = utils.query_json(context, query_name, name_macro).replace( - "columns", column).replace("table_name", table_name) + selected_query = utils.query_json(context, query_name, name_macro).replace("columns", column).replace("table_name", table_name) exec_query = db.executeQuery(conn, selected_query) query_result = [t[0] for t in exec_query] print('query_result: ', query_result) elem = query_result[0].strftime('%Y-%m-%d %H:%M') - elif number == 'Today': value = (datetime.datetime.today()).strftime('%Y-%m-%d') selected_query = utils.query_json(context, query_name, name_macro).replace( @@ -1962,8 +1953,7 @@ def step_impl(context, column, query_name, table_name, db_name, name_macro, numb def step_impl(context, column, query_name, table_name, db_name, name_macro, number, row): db_config = context.config.userdata.get("db_configuration") db_selected = db_config.get(db_name) - conn = db.getConnection(db_selected.get('host'), db_selected.get( - 'database'), db_selected.get('user'), db_selected.get('password'), db_selected.get('port')) + conn = utils.get_db_connection(db_name, db, db_online, db_offline, db_selected) if number == 'default_token_duration_validity_millis': default = int( @@ -2040,7 +2030,7 @@ def step_impl(context, query_name, table_name, param, value, macro, db_name): value = utils.replace_global_variables(value, context) value = utils.replace_local_variables(value, context) value = utils.replace_context_variables(value, context) - conn = db.getConnection(db_selected.get('host'), db_selected.get('database'), db_selected.get('user'), db_selected.get('password'), db_selected.get('port')) + conn = utils.get_db_connection(db_name, db, db_online, db_offline, db_selected) exec_query = db.executeQuery(conn, selected_query) db.closeConnection(conn) @@ -2049,8 +2039,7 @@ def step_impl(context, value, column, query_name, table_name, db_name, name_macr db_config = context.config.userdata.get("db_configuration") db_selected = db_config.get(db_name) - conn = db.getConnection(db_selected.get('host'), db_selected.get( - 'database'), db_selected.get('user'), db_selected.get('password'), db_selected.get('port')) + conn = utils.get_db_connection(db_name, db, db_online, db_offline, db_selected) selected_query = utils.query_json(context, query_name, name_macro).replace( "columns", column).replace("table_name", table_name) @@ -2076,8 +2065,7 @@ def step_impl(context, value, column, query_name, table_name, db_name, name_macr def step_impl(context, column, query_name, table_name, db_name, name_macro, number): db_config = context.config.userdata.get("db_configuration") db_selected = db_config.get(db_name) - conn = db.getConnection(db_selected.get('host'), db_selected.get( - 'database'), db_selected.get('user'), db_selected.get('password'), db_selected.get('port')) + conn = utils.get_db_connection(db_name, db, db_online, db_offline, db_selected) number = int(number) / 60000 value = (datetime.datetime.now().astimezone(pytz.timezone('Europe/Rome')) + @@ -2099,8 +2087,7 @@ def step_impl(context, column, query_name, table_name, db_name, name_macro, numb def step_impl(context, query_name, table_name, db_name, name_macro, number): db_config = context.config.userdata.get("db_configuration") db_selected = db_config.get(db_name) - conn = db.getConnection(db_selected.get('host'), db_selected.get( - 'database'), db_selected.get('user'), db_selected.get('password'), db_selected.get('port')) + conn = utils.get_db_connection(db_name, db, db_online, db_offline, db_selected) selected_query = utils.query_json(context, query_name, name_macro).replace( "columns", '*').replace("table_name", table_name) @@ -2114,8 +2101,7 @@ def step_impl(context, query_name, table_name, db_name, name_macro, number): def step_impl(context, query_name, table_name, db_name, name_macro): db_config = context.config.userdata.get("db_configuration") db_selected = db_config.get(db_name) - conn = db.getConnection(db_selected.get('host'), db_selected.get( - 'database'), db_selected.get('user'), db_selected.get('password'), db_selected.get('port')) + conn = utils.get_db_connection(db_name, db, db_online, db_offline, db_selected) selected_query = utils.query_json(context, query_name, name_macro).replace( "columns", '*').replace("table_name", table_name) @@ -2127,15 +2113,13 @@ def step_impl(context, query_name, table_name, db_name, name_macro): @step('check token_valid_to is {condition} token_valid_from plus {param}') def step_impl(context, condition, param): - nodo_online_db = context.config.userdata.get( - "db_configuration").get('nodo_online') - nodo_online_conn = db.getConnection(nodo_online_db.get('host'), nodo_online_db.get( - 'database'), nodo_online_db.get('user'), nodo_online_db.get('password'), nodo_online_db.get('port')) + db_name = "nodo_online" + nodo_online_db = context.config.userdata.get("db_configuration").get(db_online) + nodo_online_conn = utils.get_db_connection(db_name, db, db_online, db_offline, nodo_online_db) token_validity_query = utils.query_json(context, 'token_validity', 'AppIO').replace( 'columns', 'TOKEN_VALID_FROM, TOKEN_VALID_TO').replace('table_name', 'POSITION_ACTIVATE') - token_valid_from, token_valid_to = db.executeQuery( - nodo_online_conn, token_validity_query)[0] + token_valid_from, token_valid_to = db.executeQuery(nodo_online_conn, token_validity_query)[0] db.closeConnection(nodo_online_conn) print(token_valid_to) @@ -2350,10 +2334,10 @@ def step_impl(context): query4 = f"SELECT * FROM RPT_VERSAMENTI v JOIN RPT r ON v.FK_RPT = r.ID WHERE r.IUV = '{iuv}' AND r.IDENT_DOMINIO = '$activatePaymentNotice1.fiscalCode'" db_config = context.config.userdata.get("db_configuration") - db_selected = db_config.get("nodo_online") + db_name = "nodo_online" + db_selected = db_config.get(db_name) - conn = db.getConnection(db_selected.get('host'), db_selected.get( - 'database'), db_selected.get('user'), db_selected.get('password'), db_selected.get('port')) + conn = utils.get_db_connection(db_name, db, db_online, db_offline, db_selected) query_payment_replaced = utils.replace_local_variables( query_payment, context) @@ -2584,11 +2568,11 @@ def step_impl(context): query3 = f"SELECT s.* FROM PSP s where s.ID_PSP = '{psp}'" query4 = f"SELECT s.METADATA FROM POSITION_PAYMENT_PLAN s where s.NOTICE_ID = '{noticeNumber}' and s.PA_FISCAL_CODE= '{pa}'" + db_name = "nodo_online" db_config = context.config.userdata.get( - "db_configuration").get("nodo_online") + "db_configuration").get(db_name) - conn = db.getConnection(db_config.get('host'), db_config.get( - 'database'), db_config.get('user'), db_config.get('password'), db_config.get('port')) + conn = utils.get_db_connection(db_name, db, db_online, db_offline, db_config) rows = db.executeQuery(conn, query) rows1 = db.executeQuery(conn, query1) @@ -2596,11 +2580,10 @@ def step_impl(context): rows4 = db.executeQuery(conn, query4) db.closeConnection(conn) + db_name="nodo_cfg" + db_config = context.config.userdata.get("db_configuration").get(db_name) - db_config = context.config.userdata.get("db_configuration").get("nodo_cfg") - - conn = db.getConnection(db_config.get('host'), db_config.get( - 'database'), db_config.get('user'), db_config.get('password'), db_config.get('port')) + conn = utils.get_db_connection(db_name, db, db_online, db_offline, db_config) rows3 = db.executeQuery(conn, query3) @@ -2648,7 +2631,7 @@ def step_impl(context): db_config = context.config.userdata.get( "db_configuration").get("nodo_online") - conn = db.getConnection(db_config.get('host'), db_config.get( + conn = db_online.getConnection(db_config.get('host'), db_config.get( 'database'), db_config.get('user'), db_config.get('password'), db_config.get('port')) XML = utils.replace_local_variables(XML, context) @@ -2700,9 +2683,9 @@ def step_impl(context): db.closeConnection(conn) query5 = "SELECT CODICE_FISCALE, RAGIONE_SOCIALE FROM PSP WHERE ID_PSP='$activatePaymentNotice.idPSP'" - db_config = context.config.userdata.get("db_configuration").get("nodo_cfg") - conn = db.getConnection(db_config.get('host'), db_config.get( - 'database'), db_config.get('user'), db_config.get('password'), db_config.get('port')) + db_name = "nodo_cfg" + db_config = context.config.userdata.get("db_configuration").get(db_name) + conn = utils.get_db_connection(db_name, db, db_online, db_offline, db_config) query5 = utils.replace_local_variables(query5, context) rows5 = db.executeQuery(conn, query5) @@ -2901,7 +2884,7 @@ def step_impl(context, causaleVers): db_config = context.config.userdata.get( "db_configuration").get("nodo_online") - conn = db.getConnection(db_config.get('host'), db_config.get( + conn = db_online.getConnection(db_config.get('host'), db_config.get( 'database'), db_config.get('user'), db_config.get('password'), db_config.get('port')) # select clob @@ -3021,8 +3004,7 @@ def step_impl(context, name_macro, db_name, query_name, value, column, table_nam db_config = context.config.userdata.get("db_configuration") db_selected = db_config.get(db_name) - conn = db.getConnection(db_selected.get('host'), db_selected.get( - 'database'), db_selected.get('user'), db_selected.get('password'), db_selected.get('port')) + conn = utils.get_db_connection(db_name, db, db_online, db_offline, db_selected) selected_query = utils.query_json(context, query_name, name_macro).replace( "columns", column).replace("table_name", table_name) @@ -3051,7 +3033,7 @@ def leggi_tabella_con_attesa(context, db_name, query_name, name_macro, column, t db_config = context.config.userdata.get("db_configuration") db_selected = db_config.get(db_name) - conn = db.getConnection(db_selected.get('host'), db_selected.get('database'), db_selected.get('user'), db_selected.get('password'), db_selected.get('port')) + conn = utils.get_db_connection(db_name, db, db_online, db_offline, db_selected) selected_query = utils.query_json(context, query_name, name_macro).replace("columns", column).replace("table_name", table_name) print('>>>>>>>>>>>>', selected_query) diff --git a/src/integ-test/bdd-test/features/steps/utils.py b/src/integ-test/bdd-test/features/steps/utils.py index 00bc85bb93..95259370b3 100644 --- a/src/integ-test/bdd-test/features/steps/utils.py +++ b/src/integ-test/bdd-test/features/steps/utils.py @@ -473,4 +473,18 @@ def searchValueTagRecursive(tag_padre, tag, single_tag): for next_tag in single_tag: list_tag = searchValueTagRecursive(next_tag.tag, tag, next_tag) if list_tag: break - return list_tag \ No newline at end of file + return list_tag + + +def get_db_connection(db_name, db_cfg, db_online, db_offline, db_selected): + conn = None + if db_name == "nodo_online": + conn = db_online.getConnection(db_selected.get('host'), db_selected.get( + 'database'), db_selected.get('user'), db_selected.get('password'), db_selected.get('port')) + elif db_name == "nodo_offline": + conn = db_offline.getConnection(db_selected.get('host'), db_selected.get( + 'database'), db_selected.get('user'), db_selected.get('password'), db_selected.get('port')) + else: + conn = db_cfg.getConnection(db_selected.get('host'), db_selected.get( + 'database'), db_selected.get('user'), db_selected.get('password'), db_selected.get('port')) + return conn \ No newline at end of file From 27cc7fa1ea3c4d4ee05057cdb340e8e646c7a416 Mon Sep 17 00:00:00 2001 From: Francesco Cesareo Date: Fri, 19 Jan 2024 12:41:01 +0100 Subject: [PATCH 3/9] added shorttrack tag --- .../NewMod3/primitives/verifyPaymentNotice_syntax_ok.feature | 2 +- .../features/appIO/flows/GestioneDelToken/GT_01.feature | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/integ-test/bdd-test/features/NewMod3/primitives/verifyPaymentNotice_syntax_ok.feature b/src/integ-test/bdd-test/features/NewMod3/primitives/verifyPaymentNotice_syntax_ok.feature index 9f1ef32b2e..69c7069da3 100644 --- a/src/integ-test/bdd-test/features/NewMod3/primitives/verifyPaymentNotice_syntax_ok.feature +++ b/src/integ-test/bdd-test/features/NewMod3/primitives/verifyPaymentNotice_syntax_ok.feature @@ -20,7 +20,7 @@ Feature: Syntax checks for verifyPaymentReq - OK """ - @runnable @independent + @runnable @independent @shorttrack Scenario: Check valid URL in WSDL namespace When psp sends SOAP verifyPaymentNotice to nodo-dei-pagamenti Then check outcome is OK of verifyPaymentNotice response \ No newline at end of file diff --git a/src/integ-test/bdd-test/features/appIO/flows/GestioneDelToken/GT_01.feature b/src/integ-test/bdd-test/features/appIO/flows/GestioneDelToken/GT_01.feature index b27fd18fee..715d9ac962 100644 --- a/src/integ-test/bdd-test/features/appIO/flows/GestioneDelToken/GT_01.feature +++ b/src/integ-test/bdd-test/features/appIO/flows/GestioneDelToken/GT_01.feature @@ -87,7 +87,7 @@ Feature: GT_01 And checks the value $activateIOPaymentResponse.paymentToken of the record at column TOKEN of the table IDEMPOTENCY_CACHE retrived by the query payment_status on db nodo_online under macro AppIO And checks the value NotNone of the record at column VALID_TO of the table IDEMPOTENCY_CACHE retrived by the query payment_status on db nodo_online under macro AppIO And checks the value NotNone of the record at column TOKEN_VALID_FROM of the table POSITION_ACTIVATE retrived by the query payment_status on db nodo_online under macro AppIO -@runnable @lazy @dependentread @dependentwrite +@runnable @lazy @dependentread @dependentwrite @shorttrack Scenario: Execute nodoChiediInformazioniPagamento (Phase 3) Given the Execute activateIOPayment (Phase 2) scenario executed successfully When WISP sends rest GET informazioniPagamento?idPagamento=$activateIOPaymentResponse.paymentToken to nodo-dei-pagamenti From b9b481dc18f687c3137bc55ca9fad91a690c04df Mon Sep 17 00:00:00 2001 From: Francesco Cesareo Date: Thu, 25 Jan 2024 11:45:43 +0100 Subject: [PATCH 4/9] fix test --- .../appIO-BPAY/flows/sendPaymentResult_PAnew_flow.feature | 1 + 1 file changed, 1 insertion(+) diff --git a/src/integ-test/bdd-test/features/appIO-BPAY/flows/sendPaymentResult_PAnew_flow.feature b/src/integ-test/bdd-test/features/appIO-BPAY/flows/sendPaymentResult_PAnew_flow.feature index 4f3b955e24..698d85ecf9 100644 --- a/src/integ-test/bdd-test/features/appIO-BPAY/flows/sendPaymentResult_PAnew_flow.feature +++ b/src/integ-test/bdd-test/features/appIO-BPAY/flows/sendPaymentResult_PAnew_flow.feature @@ -606,6 +606,7 @@ Feature: flow checks for sendPaymentResult with PA new Then verify the HTTP status code of mod3CancelV2 response is 200 And wait 5 seconds for expiration @test @lazy @dependentread @dependentwrite + Scenario: T_SPR_08 (closePayment) Given the T_SPR_08 (mod3CancelV2) scenario executed successfully And the closePayment scenario executed successfully When WISP sends rest POST v1/closepayment_json to nodo-dei-pagamenti From bfcefe95545171b314f2f0196e7a61129a4cfd42 Mon Sep 17 00:00:00 2001 From: Francesco Cesareo Date: Thu, 25 Jan 2024 11:50:40 +0100 Subject: [PATCH 5/9] fix config.json --- src/integ-test/bdd-test/resources/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/integ-test/bdd-test/resources/config.json b/src/integ-test/bdd-test/resources/config.json index 7fc672ddf8..3083c8c23c 100644 --- a/src/integ-test/bdd-test/resources/config.json +++ b/src/integ-test/bdd-test/resources/config.json @@ -39,7 +39,7 @@ "rest_service": "" }, "apicfg-testing-support": { - "url": "http://localhost:8080", + "url": "https://api.dev.platform.pagopa.it/apiconfig-testing-support/api/v1", "healthcheck": "/info", "soap_service": " ", "rest_service": " ", From e1f177b3e5e3a0f9ee6df2f8fc3914203175648c Mon Sep 17 00:00:00 2001 From: Francesco Cesareo Date: Thu, 25 Jan 2024 14:55:02 +0100 Subject: [PATCH 6/9] improvements --- .../bdd-test/features/environment.py | 5 +++-- .../db_operation_apicfg_testing_support.py | 1 + .../bdd-test/features/steps/steps.py | 10 +++++++++- src/integ-test/bdd-test/resources/config.json | 19 +++++++++++++------ 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/integ-test/bdd-test/features/environment.py b/src/integ-test/bdd-test/features/environment.py index b28510f512..12dcde97d9 100644 --- a/src/integ-test/bdd-test/features/environment.py +++ b/src/integ-test/bdd-test/features/environment.py @@ -46,14 +46,15 @@ def before_all(context): def before_feature(context, feature): services = context.config.userdata.get("services") # add heading - feature.background.steps[0].table = Table(headings=("name", "url", "healthcheck", "soap_service", "rest_service")) + feature.background.steps[0].table = Table(headings=("name", "url", "healthcheck", "soap_service", "rest_service", "subscription_key_name")) # add data in the tables for system_name in services.keys(): row = (system_name, services.get(system_name).get("url", ""), services.get(system_name).get("healthcheck", ""), services.get(system_name).get("soap_service", ""), - services.get(system_name).get("rest_service", "")) + services.get(system_name).get("rest_service", ""), + services.get(system_name).get("subscription_key_name", "")) feature.background.steps[0].table.add_row(row) # DISABLE see @config-ec too diff --git a/src/integ-test/bdd-test/features/steps/db_operation_apicfg_testing_support.py b/src/integ-test/bdd-test/features/steps/db_operation_apicfg_testing_support.py index 688e243958..4245ea89d3 100644 --- a/src/integ-test/bdd-test/features/steps/db_operation_apicfg_testing_support.py +++ b/src/integ-test/bdd-test/features/steps/db_operation_apicfg_testing_support.py @@ -40,6 +40,7 @@ def executeQuery(conn, query:str) -> list: url = apicfg_testing_support.get("base_path") + apicfg_testing_support.get("service") response = requests.post(url, data=query, headers=headers) + return response.json() except Exception as e: print(f"The error '{e}' occurred") diff --git a/src/integ-test/bdd-test/features/steps/steps.py b/src/integ-test/bdd-test/features/steps/steps.py index 4cdf648220..5a1f7c3667 100644 --- a/src/integ-test/bdd-test/features/steps/steps.py +++ b/src/integ-test/bdd-test/features/steps/steps.py @@ -31,6 +31,7 @@ # Constants RESPONSE = "Response" REQUEST = "Request" +SUBKEY = "Ocp-Apim-Subscription-Key" # Steps definitions @@ -48,7 +49,14 @@ def step_impl(context): print(f"calling: {row.get('name')} -> {row.get('url')}") url = row.get("url") + row.get("healthcheck") print(f"calling -> {url}") - headers = {'Host': 'api.dev.platform.pagopa.it:443'} + headers = { + 'Host': 'api.dev.platform.pagopa.it:443' + } + + if row.get("subscription_key_name") != "": + if row.get("subscription_key_name") in os.environ: + headers[SUBKEY] = os.getenv(row.get("subscription_key_name")) + resp = requests.get(url, headers=headers, verify=False) print(f"response: {resp.status_code}") responses &= (resp.status_code == 200) diff --git a/src/integ-test/bdd-test/resources/config.json b/src/integ-test/bdd-test/resources/config.json index 3083c8c23c..425758ac42 100644 --- a/src/integ-test/bdd-test/resources/config.json +++ b/src/integ-test/bdd-test/resources/config.json @@ -6,44 +6,51 @@ "healthcheck": "", "soap_service": " ", "rest_service": " ", + "subscription_key_name": "", "refresh_config_service": "https://api.dev.platform.pagopa.it/nodo-replica-ndp/monitoring/v1/config/refresh/CONFIG" }, "mock-ec": { "url": "https://api.dev.platform.pagopa.it/mock-ec-replica-ndp/service/v1/mock", "healthcheck": "/info", "soap_service": "", - "rest_service": "" + "rest_service": "", + "subscription_key_name": "" }, "mock-psp": { "url": "https://api.dev.platform.pagopa.it/mock-psp-replica-ndp/service/v1/mock", "healthcheck": "/info", "soap_service": "", - "rest_service": "" + "rest_service": "", + "subscription_key_name": "" }, "mock-pm": { "url": "https://api.dev.platform.pagopa.it/mock-pm-replica-ndp/service/v1", "healthcheck": "/", "soap_service": "", - "rest_service": "" + "rest_service": "", + "subscription_key_name": "" }, "secondary-mock-ec": { "url": "https://api.dev.platform.pagopa.it/mock-ec-replica-secondary-ndp/service/v1/mock", "healthcheck": "/info", "soap_service": "", - "rest_service": "" + "rest_service": "", + "subscription_key_name": "" }, "secondary-mock-psp": { "url": "https://api.dev.platform.pagopa.it/mock-psp-secondary-replica-ndp/service/v1/mock", "healthcheck": "/info", "soap_service": "", - "rest_service": "" + "rest_service": "", + "subscription_key_name": "" }, "apicfg-testing-support": { "url": "https://api.dev.platform.pagopa.it/apiconfig-testing-support/api/v1", "healthcheck": "/info", "soap_service": " ", "rest_service": " ", - "refresh_config_service": "" + "refresh_config_service": "", + "subscription_key_name": "APICFG_SUBSCRIPTION_KEY" } }, "global_configuration": { From 3edaf0fc84e85d60a5756c107f8a7d726f0aa83f Mon Sep 17 00:00:00 2001 From: Francesco Cesareo Date: Thu, 25 Jan 2024 17:15:20 +0100 Subject: [PATCH 7/9] fix --- src/integ-test/bdd-test/features/environment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/integ-test/bdd-test/features/environment.py b/src/integ-test/bdd-test/features/environment.py index 12dcde97d9..8f3ed44564 100644 --- a/src/integ-test/bdd-test/features/environment.py +++ b/src/integ-test/bdd-test/features/environment.py @@ -2,13 +2,13 @@ from behave.model import Table import os import steps.utils as utils +import requests if 'NODOPGDB' in os.environ: import steps.db_operation_pg as db else: import steps.db_operation as db import cx_Oracle - import requests if 'APICFG' in os.environ: import steps.db_operation_apicfg_testing_support as db From 930bc39058cb371fbed0db0b0a15acd0ba022aff Mon Sep 17 00:00:00 2001 From: Francesco Cesareo Date: Mon, 28 Oct 2024 18:32:27 +0100 Subject: [PATCH 8/9] fix pagoPA_PERF_apim_REAL --- src/perf-test/k6/cfg/baseURL_Nodo.csv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/perf-test/k6/cfg/baseURL_Nodo.csv b/src/perf-test/k6/cfg/baseURL_Nodo.csv index f4fcf39256..a3a4726505 100644 --- a/src/perf-test/k6/cfg/baseURL_Nodo.csv +++ b/src/perf-test/k6/cfg/baseURL_Nodo.csv @@ -2,5 +2,5 @@ ENV;BASEURL;PRIVATEURL;SOAP_BASEURL;REST_BASEURL pagoPA_DEV_apim;https://api.dev.platform.pagopa.it/nodo-pagamenti/api/v1/webservices/input;10.230.8.5;https://api.dev.platform.pagopa.it/nodo-pagamenti/api/v1/webservices/input;https://10.230.8.5/nodo-pagamenti/api/v1 pagoPA_UAT_apim;https://api.uat.platform.pagopa.it/nodo-pagamenti/api/v1/webservices/input;10.230.9.5;; pagoPA_PERF_apim;https://nodo-dei-pagamenti-prf-npa-nodopagamenti.tst-npc.sia.eu/webservices/input;10.230.9.5;https://nodo-dei-pagamenti-prf-npa-nodopagamenti.tst-npc.sia.eu/webservices/input;https://nodo-dei-pagamenti-prf-npa-nodopagamenti.tst-npc.sia.eu/azurept -pagoPA_PERF_apim_REAL;https://api.uat.platform.pagopa.it/nodo-replica-ndp;;https://api.uat.platform.pagopa.it/nodo-replica-ndp;https://api.uat.platform.pagopa.it/nodo-replica-ndp +pagoPA_PERF_apim_REAL;https://api.uat.platform.pagopa.it/nodo-ndp;;https://api.uat.platform.pagopa.it/nodo-ndp;https://api.uat.platform.pagopa.it/nodo-ndp local;http://localhost:8080;;http://localhost:8080;http://localhost:8080 From b0e15a307368340e7f020b44dcc9ded840dcfb0f Mon Sep 17 00:00:00 2001 From: Francesco Cesareo Date: Mon, 28 Oct 2024 18:42:15 +0100 Subject: [PATCH 9/9] fix pagoPA_PERF_apim_REAL --- src/perf-test/k6/cfg/baseURL_Nodo.csv | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/perf-test/k6/cfg/baseURL_Nodo.csv b/src/perf-test/k6/cfg/baseURL_Nodo.csv index a3a4726505..040ceaf575 100644 --- a/src/perf-test/k6/cfg/baseURL_Nodo.csv +++ b/src/perf-test/k6/cfg/baseURL_Nodo.csv @@ -4,3 +4,5 @@ pagoPA_UAT_apim;https://api.uat.platform.pagopa.it/nodo-pagamenti/api/v1/webserv pagoPA_PERF_apim;https://nodo-dei-pagamenti-prf-npa-nodopagamenti.tst-npc.sia.eu/webservices/input;10.230.9.5;https://nodo-dei-pagamenti-prf-npa-nodopagamenti.tst-npc.sia.eu/webservices/input;https://nodo-dei-pagamenti-prf-npa-nodopagamenti.tst-npc.sia.eu/azurept pagoPA_PERF_apim_REAL;https://api.uat.platform.pagopa.it/nodo-ndp;;https://api.uat.platform.pagopa.it/nodo-ndp;https://api.uat.platform.pagopa.it/nodo-ndp local;http://localhost:8080;;http://localhost:8080;http://localhost:8080 +pagoPA_PRF_apim_REAL;https://api.uat.platform.pagopa.it/nodo-ndp;;https://api.uat.platform.pagopa.it/nodo-ndp;https://api.uat.platform.pagopa.it/nodo-ndp +local;http://localhost:8080;;http://localhost:8080;http://localhost:8080