"""Integration tests for account payee history.""" from abacus_common_logic.connectors.database import db import pytest from tests.integration.conftest import ows_abacus_account_api_client @pytest.mark.jira('ACC-4231', 'PLATFORM-4339') def test_get_account_payee_history(basic_headers, clean_db): """GET for /account/{account_id}/account-payee-history/ endpoint.""" account_id = 123456 ows_account_client = ows_abacus_account_api_client(basic_headers) payload_data = { 'account_id': account_id, 'account_name': 'test', 'created_by': 'sax_ingestion', } query = """INSERT INTO account (account_id, account_name, created_by, created_at, last_modified_by, last_modified) VALUES ({account_id}, '{account_name}', '{created_by}', '2022-03-29 01:38:06', 'default_user_id', '2022-03-29 01:38:11')""" db.engine.execute(query.format(**payload_data)) # Inserting to account payee does not add record for history table post_body = { 'account_id': account_id, 'payoneer_payee_id': 123123, 'payoneer_payee_name': 'Joe Payoneer', 'payoneer_iframe_url': 'payoneer.com/iframe', 'payoneer_iframe_url_date': '2022-02-01', 'payoneer_session_id': 'T-800' } response_post = ows_account_client.post_account_payee(post_body) assert response_post.status_code == 201 account_payee_id = response_post.json()['account_payee_id'] response_get = ows_account_client.get_account_payee_history_by_account_id( account_id ) assert response_get.status_code == 200 assert response_get.json() == [] # Updating account payee will add record for history table response_put = ows_account_client.put_account_payee( account_payee_id, {'payoneer_payee_name': 'Joey Payoneer'}) response_get = ows_account_client.get_account_payee_history_by_account_id( account_id ) assert response_put.status_code == 200 assert response_get.json()[0]['account_id'] == post_body['account_id'] assert response_get.json()[0]['payoneer_payee_id'] == \ post_body['payoneer_payee_id'] assert response_get.json()[0]['payoneer_payee_name'] == \ post_body['payoneer_payee_name'] assert response_get.json()[0]['payoneer_iframe_url'] == \ post_body['payoneer_iframe_url'] assert response_get.json()[0]['payoneer_iframe_url_date'] == \ post_body['payoneer_iframe_url_date'] assert response_get.json()[0]['payoneer_session_id'] == \ post_body['payoneer_session_id'] assert 'account_payee_id' in response_get.json()[0] assert 'account_payee_history_id' in response_get.json()[0] @pytest.mark.jira('PLATFORM-4339') def test_get_account_payee_history_by_account_id_unauthorized( clean_db, unauthorized_headers): """Test GET account payee history by account id with unauthorized headers.""" account_id = 123456 ows_account_client = ows_abacus_account_api_client(unauthorized_headers) payload_data = { 'account_id': account_id, 'account_name': 'test', 'created_by': 'sax_ingestion', } query = """INSERT INTO account (account_id, account_name, created_by, created_at, last_modified_by, last_modified) VALUES ({account_id}, '{account_name}', '{created_by}', '2022-03-29 01:38:06', 'default_user_id', '2022-03-29 01:38:11')""" db.engine.execute(query.format(**payload_data)) response_get_by_acc_id = ows_account_client.get_account_payee_history_by_account_id( account_id ) assert response_get_by_acc_id.status_code == 403 expected = { 'code': 'authorization_error', 'message': 'Unauthorized' } assert response_get_by_acc_id.json() == expected