"""Integration tests for contract flowthrough endpoints.""" import requests from tests.integration import conftest from tests.integration.consts import api, constants from tests.integration.utils import generic_helper def test_post_get_put_delete_contract_flowthrough( basic_headers, create_reference_flowthrough_calculation): """POST GET PUT DELETE /contract-flowthrough/ endpoints .""" account_fixture = generic_helper.create_account() ows_abacus_contract_client = conftest.ows_abacus_contract_api_client(basic_headers) contract_name = f'orcd_autotest_{generic_helper.generate_random_string(16)}' contract_body = ows_abacus_contract_client.generate_contract_body( contract_name, account_fixture['account_id'] ) response_post = ows_abacus_contract_client.post_contract(contract_body) assert response_post.status_code == 201 contract_id = response_post.json()['contract_id'] post_flowthrough_body = { 'reference_flowthrough_calculation_id': 1, 'flowthrough_rate': 5.10, 'has_automatic_shutoff': True, 'recoupment_cap': 190831 } res_post = ows_abacus_contract_client.post_contract_flowthrough( contract_id, post_flowthrough_body ) assert res_post.status_code == 201 assert res_post.json()['contract_id'] == contract_id assert res_post.json()['flowthrough_status'] == 'active' assert float(res_post.json()['flowthrough_rate']) == \ post_flowthrough_body['flowthrough_rate'] assert res_post.json()['has_automatic_shutoff'] == \ post_flowthrough_body['has_automatic_shutoff'] assert res_post.json()['recoupment_cap'] == \ post_flowthrough_body['recoupment_cap'] assert 'previous_flowthrough_status' in res_post.json() assert 'status_last_modified_by' in res_post.json() assert 'status_last_modified' in res_post.json() assert 'contract_flowthrough_id' in res_post.json() contract_flowthrough_id = res_post.json()['contract_flowthrough_id'] res_get = ows_abacus_contract_client.get_contract_flowthrough_by_contract_id( contract_id ) assert res_get.status_code == 200 assert res_post.json()['contract_id'] == contract_id assert res_post.json()['flowthrough_status'] == 'active' assert float(res_post.json()['flowthrough_rate']) == \ post_flowthrough_body['flowthrough_rate'] assert res_post.json()['has_automatic_shutoff'] == \ post_flowthrough_body['has_automatic_shutoff'] assert res_post.json()['recoupment_cap'] == \ post_flowthrough_body['recoupment_cap'] assert 'previous_flowthrough_status' in res_post.json() assert 'status_last_modified_by' in res_post.json() assert 'status_last_modified' in res_post.json() assert 'contract_flowthrough_id' in res_post.json() res_get = ows_abacus_contract_client.get_contract_flowthrough_by_flowthrough_id( contract_flowthrough_id ) assert res_get.status_code == 200 assert res_post.json()['contract_id'] == contract_id assert res_post.json()['flowthrough_status'] == 'active' assert float(res_post.json()['flowthrough_rate']) == \ post_flowthrough_body['flowthrough_rate'] assert res_post.json()['has_automatic_shutoff'] == \ post_flowthrough_body['has_automatic_shutoff'] assert res_post.json()['recoupment_cap'] == \ post_flowthrough_body['recoupment_cap'] assert 'previous_flowthrough_status' in res_post.json() assert 'status_last_modified_by' in res_post.json() assert 'status_last_modified' in res_post.json() assert 'contract_flowthrough_id' in res_post.json() put_body = { 'reference_flowthrough_calculation_id': 1, 'flowthrough_rate': 3.5, 'has_automatic_shutoff': False, 'recoupment_cap': 190831 } res_put = ows_abacus_contract_client.put_contract_flowthrough( contract_flowthrough_id, put_body ) assert res_put.status_code == 200 res_get = ows_abacus_contract_client.get_contract_flowthrough_by_flowthrough_id( contract_flowthrough_id ) assert res_get.status_code == 200 assert float(res_put.json()['flowthrough_rate']) == \ put_body['flowthrough_rate'] assert float(res_put.json()['has_automatic_shutoff']) == \ put_body['has_automatic_shutoff'] res_delete = ows_abacus_contract_client.delete_contract_flowthrough( contract_flowthrough_id ) assert res_delete.status_code == 204 res_get = ows_abacus_contract_client.get_contract_flowthrough_by_flowthrough_id( contract_flowthrough_id ) assert res_get.status_code == 404 res_get = ows_abacus_contract_client.get_contract_flowthrough_by_contract_id( contract_id ) assert res_get.status_code == 200 assert res_get.json() == {} def test_get_contract_flowthrough_by_contract_id_authorization( admin_headers: dict[str, str], auth_headers: dict[str, str], unauthorized_headers: dict[str, str], create_reference_flowthrough_calculation: None, ) -> None: """Test get contract flowthrough by contract id authorization.""" contract_id, _, _ = generic_helper.create_account_and_contract( account_id=constants.TEST_ACCOUNT_ID ) post_flowthrough_body = { # Defined in create_reference_flowthrough_calculation fixture 'reference_flowthrough_calculation_id': 1, 'flowthrough_rate': 5.10, 'has_automatic_shutoff': True, 'recoupment_cap': 190831 } res = requests.post( f'{api.QA_BASE_URL}/contract/{contract_id}/contract-flowthrough', json=post_flowthrough_body, headers=admin_headers ) assert res.status_code == 201 res = requests.get( f'{api.QA_BASE_URL}/contract/{contract_id}/contract-flowthrough', headers=auth_headers ) assert res.status_code == 200 res = requests.get( f'{api.QA_BASE_URL}/contract/{contract_id}/contract-flowthrough', headers=unauthorized_headers ) assert res.status_code == 403 assert res.json()['message'] == 'User is forbidden'