"""Integration tests for lambda function.""" import operator import pytest from tests.integration.conftest import check_db_empty from tests.integration.conftest import dockerized_lambda_api_client from tests.integration.conftest import query_db DUPLICATE_ENTRIES_QUERY = """ SELECT abacus_event_id, contract_id, total_gross_revenue_amount, COUNT(*) AS number_of_rows FROM ledger_accounting_run_balance GROUP BY 1, 2, 3 HAVING number_of_rows > 1 """ @pytest.mark.jira('ACC-3559', 'ACC-8449') def test_invoke_lambda(basic_headers): """Assert lambda action.""" dockerized_lambda = dockerized_lambda_api_client(basic_headers) body = { 'abacus_event_id': 1, 'target_type': 'accounting_run', 'target_id': 1473, 'event_name': 'accounting_run_calculate', 'event_date': '1997-11-09T19: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' check_db_empty(operator.gt, 'ledger_accounting_run_balance') # NOTE: We're asserting that batches are flushed correctly # and that we don't insert any duplicate rows duplicate_rows = query_db(DUPLICATE_ENTRIES_QUERY) assert len(duplicate_rows) == 0