"""Integration tests for payment hold history.""" from datetime import datetime, timezone from abacus_common_logic.utils.dates import safe_format_date import pytest from tests.integration.conftest import ows_abacus_account_api_client @pytest.mark.jira('ACC-4086', 'PLATFORM-4339') def test_get_payment_hold_history(clean_db, basic_headers): """POST for /payment_hold and GET for /payment_hold_history endpoints.""" account_id = 123456 ows_account_client = ows_abacus_account_api_client(basic_headers) post_account = { 'account_name': 'Test Account', 'account_id': account_id, } response_post_account = ows_account_client.post_account(post_account) assert response_post_account.status_code == 201 today = safe_format_date(datetime.now(timezone.utc)) post_hold_body = { 'is_on_hold': True, 'reason': 'orcd_payment_hold_testing_reason', 'start_date': str(today), 'created_by': 'vz' } response_post_payment_hold = ows_account_client.post_payment_hold( account_id, post_hold_body) assert response_post_payment_hold.status_code == 201 response_get_payment_hold_history = ows_account_client.get_payment_hold_history( account_id) assert response_get_payment_hold_history.status_code == 200 expected_item = dict(**post_hold_body, account_id=account_id) history_item = response_get_payment_hold_history.json()[0] expected_item.update( payment_hold_id=history_item['payment_hold_id'], last_modified_by=history_item['last_modified_by'], last_modified=history_item['last_modified'], ) expected_item.update(created_at=today) assert response_get_payment_hold_history.json()[0] == expected_item @pytest.mark.jira('PLATFORM-4339') def test_get_payment_hold_history_unauthorized( clean_db, unauthorized_headers): """GET /account//payment-hold-history.""" account_id = 123455 ows_account_client = ows_abacus_account_api_client(unauthorized_headers) response_get_by_acc_id = ows_account_client.get_payment_hold_history( 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