"""Integration tests for lambda function.""" import os from conftest import check_table_empty from conftest import check_table_not_empty from conftest import dockerized_lambda_api_client from conftest import get_db_field_value from conftest import s3_url_exists from conftest import upload_file_to_s3 import pytest @pytest.mark.jira('ACC-7659') def test_invoke_lambda(basic_headers, clean_db): """Assert lambda action.""" dockerized_lambda = dockerized_lambda_api_client(basic_headers) tables_to_check = [ 'account', 'account_contract', 'account_payee', 'account_payment_term', 'account_tax_info', 'contract', 'contract_term', 'run_controller_contract' ] for table in tables_to_check: check_table_empty(table) bucket_name = os.environ.get( 'S3_BUCKET_NAME', 'qa-abacus-json-contract-file-import' ) fixed_relative_path = 'tests/integration/utils/test_data_file.json' upload_file_to_s3(bucket_name, fixed_relative_path) body = { 'jira_ticket': 'NO-TICKET-INTEGRATION-TESTS', 'import_user': 'integration_test_a', } res = dockerized_lambda.post_lambda('2015-03-31', body) assert res.status_code == 200, \ f"error type was: {res.json()['errorType']}, " \ f"error message was: {res.json()['errorMessage']}" assert 'status' in res.json(), \ f"error type was: {res.json()['errorType']}, " \ f"error message was: {res.json()['errorMessage']}" assert res.json()['status'] == 'OK' s3_path_report_file = get_db_field_value( 'json_contract_file_import_status', 'process_report_file_s3_path', 'import_user like "integration_test_a"' ) s3_path_processed_file = get_db_field_value( 'json_contract_file_import_status', 'json_file_s3_path', 'import_user like "integration_test_a"' ) assert s3_url_exists(s3_path_report_file) assert s3_url_exists(s3_path_processed_file) tables_to_check = [ 'account', 'account_contract', 'account_payee', 'account_payment_term', 'account_tax_info', 'contract', 'contract_term', 'run_controller', 'run_controller_contract' ] for table in tables_to_check: check_table_not_empty(table) value = get_db_field_value( 'account', 'account_name', 'account_id = 990111' ) assert value == 'POWERHOUSE TALENT SLU' value = get_db_field_value( 'contract', 'contract_name', 'contract_id = 111099' ) assert value == 'Contract PowerhouseTalent Distribution' # with 'overwrite' it should update the fields for the entities provided fixed_relative_path = 'tests/integration/utils/test_data_file_update.json' upload_file_to_s3(bucket_name, fixed_relative_path) body = { 'jira_ticket': 'NO-TICKET-INTEGRATION-TESTS', 'import_user': 'integration_test_b', 'overwrite': '1' } res = dockerized_lambda.post_lambda('2015-03-31', body) assert res.status_code == 200, \ f"error type was: {res.json()['errorType']}, " \ f"error message was: {res.json()['errorMessage']}" assert 'status' in res.json(), \ f"error type was: {res.json()['errorType']}, " \ f"error message was: {res.json()['errorMessage']}" assert res.json()['status'] == 'OK' s3_path_report_file = get_db_field_value( 'json_contract_file_import_status', 'process_report_file_s3_path', 'import_user like "integration_test_b"' ) s3_path_processed_file = get_db_field_value( 'json_contract_file_import_status', 'json_file_s3_path', 'import_user like "integration_test_b"' ) assert s3_url_exists(s3_path_report_file) assert s3_url_exists(s3_path_processed_file) value = get_db_field_value( 'account', 'account_name', 'account_id = 990111' ) assert value == 'UPDATED ACCOUNT NAME' value = get_db_field_value( 'contract', 'contract_name', 'contract_id = 111099' ) assert value == 'UPDATED CONTRACT NAME' @pytest.mark.jira('ACC-8315') def test_create_account_only(basic_headers, clean_db): """Assert lambda action.""" dockerized_lambda = dockerized_lambda_api_client(basic_headers) tables_to_check = [ 'account', 'account_contract', 'account_payee', 'account_payment_term', 'account_tax_info', 'contract', 'contract_term', 'run_controller_contract' ] for table in tables_to_check: check_table_empty(table) bucket_name = os.environ.get( 'S3_BUCKET_NAME', 'qa-abacus-json-contract-file-import' ) fixed_relative_path = 'tests/integration/utils/test_data_file_account_only.json' upload_file_to_s3(bucket_name, fixed_relative_path) body = { 'jira_ticket': 'NO-TICKET-INTEGRATION-TESTS', 'import_user': 'integration_test_c' } res = dockerized_lambda.post_lambda('2015-03-31', body) assert res.status_code == 200, \ f"error type was: {res.json()['errorType']}, " \ f"error message was: {res.json()['errorMessage']}" assert 'status' in res.json(), \ f"error type was: {res.json()['errorType']}, " \ f"error message was: {res.json()['errorMessage']}" assert res.json()['status'] == 'OK' s3_path_report_file = get_db_field_value( 'json_contract_file_import_status', 'process_report_file_s3_path', 'import_user like "integration_test_c"' ) s3_path_processed_file = get_db_field_value( 'json_contract_file_import_status', 'json_file_s3_path', 'import_user like "integration_test_c"' ) assert s3_url_exists(s3_path_report_file) assert s3_url_exists(s3_path_processed_file) tables_to_check = [ 'account', 'account_payee', 'account_payment_term', 'account_tax_info' ] for table in tables_to_check: check_table_not_empty(table) check_table_empty('contract')