"""Generic integration tests.""" import pytest from royalties.tests.integration.conftest import ows_royalties_api_client @pytest.mark.jira('ACC-6403') def test_get_adjustments_template(basic_headers): """Test GET /abacus-adjustments/download/template .""" ows_royalties_client = ows_royalties_api_client(basic_headers) res_get = ows_royalties_client.get_adjustment_file_template() assert res_get.status_code == 200 assert '-abacus-adjustments.s3.amazonaws.com/' in res_get.json()['template_url'] assert 'Adjustment_Template.xlsx' in res_get.json()['template_url'] @pytest.mark.jira('ACC-6321') def test_get_invalid_adjustment_file_download( basic_headers, statement_period_fixtures, statement_period_adjustments_file_error_fixture, ): """Test GET /statement-period-adjustment-file//download/error .""" # defined in fixtures in tests/conftest.py file_id = 1 ows_royalties_client = ows_royalties_api_client(basic_headers) res_get = ows_royalties_client.get_invalid_adjustment_file_download(file_id) assert res_get.status_code == 200 assert 'errors/Test7.xlsx' in res_get.json()['invalid_report_url'] assert 'qa-abacus-adjustments' in res_get.json()['invalid_report_url'] @pytest.mark.jira('ACC-6321') def test_get_valid_adjustment_file_download( basic_headers, statement_period_fixtures, statement_period_adjustments_file_report_fixture, ): """Test GET /statement-period-adjustment-file/>/download/report .""" # defined in fixtures in tests/conftest.py file_id = 1 ows_royalties_client = ows_royalties_api_client(basic_headers) res_get = ows_royalties_client.get_valid_adjustment_file_download(file_id) assert res_get.status_code == 200 assert 'test_fixtures/test_adjustment.xlsx' in res_get.json()['valid_report_url'] assert 'qa-abacus-adjustments' in res_get.json()['valid_report_url'] @pytest.mark.jira('ACC-6465') def test_get_statement_period_adjustment_files( basic_headers, statement_period_fixtures, mock_statement_period_adjustment_files ): """Test GET /statement-period-adjustment-files .""" ows_royalties_client = ows_royalties_api_client(basic_headers) res_get = ows_royalties_client.get_statement_periods_adjustment_files() assert res_get.status_code == 200 assert len(res_get.json()['items']) == 3 assert res_get.json()['total_count'] == 3 statuses = ['applied', 'not_approved', 'approved'] for status in statuses: params = {'status': status} res_get = ows_royalties_client.get_statement_periods_adjustment_files(params) assert res_get.status_code == 200 assert len(res_get.json()['items']) == 1 assert res_get.json()['total_count'] == 1 assert res_get.json()['items'][0]['status'] == status params = {'status': 'applied, not_approved'} res_get = ows_royalties_client.get_statement_periods_adjustment_files(params) assert res_get.status_code == 200 assert len(res_get.json()['items']) == 2 assert res_get.json()['total_count'] == 2 res_body = res_get.json()['items'] assert all( 'status' in item and item['status'] in params['status'] for item in res_body ) params = {'statement_period_adjustment_file_id': 92} res_get = ows_royalties_client.get_statement_periods_adjustment_files(params) assert res_get.status_code == 200 assert len(res_get.json()['items']) == 1 assert res_get.json()['total_count'] == 1 assert ( res_get.json()['items'][0]['statement_period_adjustment_file_id'] == params['statement_period_adjustment_file_id'] ) @pytest.mark.jira('ACC-7912', 'ACC-7913', 'ACC-7914') def test_get_statement_period_adjustment_files_by_search_params( basic_headers, statement_period_fixtures, mock_statement_period_adjustment_files ): """Test GET /statement-period-adjustment-files by search_params .""" ows_royalties_client = ows_royalties_api_client(basic_headers) params = {'file_name': 'adjustment-file-1-2024.xlsx'} res_get = ows_royalties_client.get_adjustment_files_with_params(params) assert res_get.status_code == 200 assert len(res_get.json()['items']) == 1 assert res_get.json()['total_count'] == 1 assert res_get.json()['items'][0]['file_name'] == params['file_name'] params = {'statement_period_id': '999'} res_get = ows_royalties_client.get_adjustment_files_with_params(params) assert res_get.status_code == 200 assert len(res_get.json()['items']) == 2 assert res_get.json()['total_count'] == 2 assert res_get.json()['items'][0]['statement_period_id'] == int( params['statement_period_id'] ) params = {'created_by': 'd5ca8ac3-7e51-4793-8775-50d11282504c'} res_get = ows_royalties_client.get_adjustment_files_with_params(params) assert res_get.status_code == 200 assert len(res_get.json()['items']) == 1 assert res_get.json()['total_count'] == 1 assert res_get.json()['items'][0]['created_by'] == params['created_by'] @pytest.mark.jira('ACC-9893', 'ACC-9861') def test_post_get_statement_period_adjustment_file_batch_criteria_by_file_id( basic_headers, statement_period_fixtures, statement_period_adjustments_file_report_fixture, ): """Test POST GET /batch-criteria .""" # defined in fixtures in tests/conftest.py file_id = 1 ows_royalties_client = ows_royalties_api_client(basic_headers) post_body = { 'statement_period_adjustment_file_id': file_id, 'batch_criteria': { 'payment_schedules': ['30_days_after_quarter_end'], 'reference_payment_entities': [1, 2, 3], }, } res_post = ows_royalties_client.post_statement_period_adjustment_file_batch_criteria_by_file_id( file_id, post_body, ) assert res_post.status_code == 201 assert res_post.json() == { **post_body, 'statement_period_adjustment_batch_criteria_id': 1, } res_get = ows_royalties_client.get_statement_period_adjustment_file_batch_criteria_by_file_id( file_id, ) assert res_get.status_code == 200 assert res_get.json() == { **post_body, 'statement_period_adjustment_batch_criteria_id': 1, } @pytest.mark.jira('ACC-9904') def test_get_statement_period_adjustment_files_by_search_params( basic_headers, statement_period_fixtures ): """Test POST /statement-period//adjustment-file/batch-criteria .""" ows_royalties_client = ows_royalties_api_client(basic_headers) # statement_period_adjustment_file table is cleaned between tests so the file_id is expected to be 1 file_id = 1 batch_criteria = { 'payment_schedules': ['30_days_after_quarter_end'], 'reference_payment_entities': [1, 2, 3], } file_name = 'Test flowthrough adjustment' post_body = {'batch_criteria': batch_criteria, 'file_name': file_name} res_post = ( ows_royalties_client.post_adjustment_file_batch_criteria_for_statement_period( 11, post_body ) ) assert res_post.status_code == 201 res_get = ows_royalties_client.get_statement_period_adjustment_file_batch_criteria_by_file_id( file_id, ) assert res_get.status_code == 200 assert res_get.json() == { 'batch_criteria': batch_criteria, 'statement_period_adjustment_batch_criteria_id': 1, 'statement_period_adjustment_file_id': file_id, }