"""Tests for the access checks. We're testing every endpoint that's open to non-admin profiles. The MoneyhubProfile used in the tests only has access to `MONEYHUB_ACCOUNT_ID`. """ import pytest from tests.integration.conftest import ( ows_abacus_event_api_client, ows_ledger_api_client, ows_royalties_api_client, ) from tests.integration.consts.headers import BASIC_HEADERS, MONEYHUB_HEADERS from tests.integration.utils.generic_helper import ( create_account, generate_ledger_event, generate_post_ledger_account_body, generate_random_string, ) MONEYHUB_ACCOUNT_ID = 35598 def _setup(account_id): """Create common objects for the tests.""" ows_ledger_client = ows_ledger_api_client(BASIC_HEADERS) ows_royalties_client = ows_royalties_api_client(BASIC_HEADERS) ows_abacus_event_client = ows_abacus_event_api_client(BASIC_HEADERS) create_account(account_id) accounting_periods_response = ows_royalties_client.get_accounting_periods() assert accounting_periods_response.status_code == 200 accounting_runs = accounting_periods_response.json()['items'] open_period = next( (item for item in accounting_runs if item['closed_date'] is None), None ) accounting_runs_response = ows_royalties_client.get_accounting_period_runs( open_period['accounting_period_id'] ) assert accounting_runs_response.status_code == 200 accounting_run_id = accounting_runs_response.json()['items'][0]['accounting_run_id'] ledger_event = generate_ledger_event(accounting_run_id) abacus_event_response = ows_abacus_event_client.post_abacus_event(ledger_event) assert abacus_event_response.status_code == 201 abacus_event_id = abacus_event_response.json()['abacus_event_id'] contract_name = 'orcd_autotest_{}'.format(generate_random_string(16)) contract = ows_royalties_client.generate_contract_body( contract_name, 'distribution' ) contract.update(account_id=account_id) contract_response = ows_royalties_client.post_contract(contract) assert contract_response.status_code == 201 contract_id = contract_response.json()['contract_id'] post_ledger_account_body = [ generate_post_ledger_account_body(abacus_event_id, account_id, contract_id) ] ledger_response = ows_ledger_client.post_ledger_bulk(post_ledger_account_body) assert ledger_response.status_code == 201 @pytest.mark.jira('ACC-8346') def test_access_check_get_current_balance(create_accounting_run, create_run_controller): """Test the access check for the `/current-balance` endpoint.""" _setup(MONEYHUB_ACCOUNT_ID) ows_ledger_moneyhub_client = ows_ledger_api_client(MONEYHUB_HEADERS) # The MoneyhubProfile makes a request for an Account they have access to current_balance_response = ( ows_ledger_moneyhub_client.get_ledger_account_current_balance( MONEYHUB_ACCOUNT_ID ) ) assert current_balance_response.status_code == 200 # The MoneyhubProfile makes a request for an Account they don't have access to current_balance_response = ( ows_ledger_moneyhub_client.get_ledger_account_current_balance(1) ) assert current_balance_response.status_code == 403