"""Integration tests for lambda function.""" import json import pytest from conftest import ( VENDOR_ID, db_delete_test_account, db_select_account, dockerized_lambda_api_client, ) @pytest.mark.jira('ACC-5774') def test_create_account(basic_headers): """Assert lambda action (create account).""" dockerized_lambda = dockerized_lambda_api_client(basic_headers) # delete test account entry from previous runs if any db_delete_test_account(VENDOR_ID) # verify test account is not in db yet response = db_select_account(VENDOR_ID) assert len(response) == 0 # trigger the lambda file_path = 'tests/integration/sample_event.json' with open(file_path) as json_file: json_data = json.load(json_file) res = dockerized_lambda.post_lambda('2015-03-31', json_data) assert res.status_code == 200 assert res.json() == {'status': 'OK'} # check whether an account made it to db response = db_select_account(VENDOR_ID) assert len(response) == 1 assert response[0]['account_name'] == 'sync_account_lambda_integration_test' @pytest.mark.jira('ACC-5774') def test_update_account(basic_headers): """Assert lambda action (update account).""" dockerized_lambda = dockerized_lambda_api_client(basic_headers) # delete test account entry from previous runs if any db_delete_test_account(VENDOR_ID) # verify test account is not in db yet response = db_select_account(VENDOR_ID) assert len(response) == 0 # trigger the lambda file_path = 'tests/integration/sample_event.json' with open(file_path) as json_file: json_data = json.load(json_file) res = dockerized_lambda.post_lambda('2015-03-31', json_data) assert res.status_code == 200 assert res.json() == {'status': 'OK'} # check whether an account made it to db response = db_select_account(VENDOR_ID) assert len(response) == 1 assert response[0]['account_name'] == 'sync_account_lambda_integration_test' # trigger the lambda to update an account file_path = 'tests/integration/sample_update_event.json' with open(file_path) as json_file: json_data = json.load(json_file) res = dockerized_lambda.post_lambda('2015-03-31', json_data) assert res.status_code == 200 assert res.json() == {'status': 'OK'} # check whether an account was updated response = db_select_account(VENDOR_ID) assert len(response) == 1 assert response[0]['account_name'] == 'sync_account_lambda_integration_test_updated'