"""Integration tests for lambda function.""" import pytest from commit_royalties.constants.constants import \ ACCOUNTING_RUN_COMMIT_ROYALTIES_ACTION_NAME from tests.integration.conftest import dockerized_lambda_api_client from tests.integration.conftest import fetch_single_db_entry from tests.integration.conftest import mysqlclient_docker @pytest.mark.jira('ACC-3436') def test_invoke_lambda(basic_headers): """Check ledger_db here.""" dockerized_lambda = dockerized_lambda_api_client(basic_headers) body = {'abacus_event_id': 1067, 'target_type': 'accounting_run', 'target_id': '1472', 'event_name': 'commit_royalties', 'event_date': '1997-07-16T19:20:30.45+01:00'} res = dockerized_lambda.post_lambda('2015-03-31', body) assert res.status_code == 200 assert 'status' in res.json(), \ f"error type was: {res.json()['errorType']}, " \ f"error message was: {res.json()['errorMessage']}" assert res.json()['status'] == 'OK' cnx = mysqlclient_docker() cursor = cnx.cursor() tables = ['ledger_deposit', 'ledger_account'] for table in tables: cursor.execute('SELECT * FROM {}'.format(table)) cursor.fetchall() rc = cursor.rowcount assert rc > 0 query = """ select * from royalty_accounting.abacus_state where action_name = '{}'; """.format(ACCOUNTING_RUN_COMMIT_ROYALTIES_ACTION_NAME) result = fetch_single_db_entry(query) assert result['action_status'] == 'complete' cnx.close()