"""Integration tests.""" import requests from payee.constants.constants import PREEXISTING_PAYONEER_ACCOUNT_PROGRAM_IDS from tests.integration.conftest import ACCOUNT_PAYEE_ID, ows_payee_api_client from tests.integration.consts import api from tests.integration.utils.generic_helper import generate_random_string def test_get_hello(): """Get Hello Endpoint.""" response = requests.get(api.HEALTH_CHECK) assert response.status_code == 200, '\nReason: {}\nURL: {}'.format( response.reason, response.url ) response_body = response.json() assert 'status' in response_body assert 'ok' in response_body['status'] def test_send_mass_payout_req_to_payoneer(basic_headers): """POST /payoneer/programs/100158940/mass-payouts .""" ows_payee_client = ows_payee_api_client(basic_headers) post_body = [ { 'client_reference_id': 'test1', 'account_payee_id': '56732', 'description': 'Mass Payouts 1', 'currency': 'USD', 'amount': 222, }, { 'client_reference_id': 'test2', 'account_payee_id': '56733', 'description': 'Mass Payouts 2', 'currency': 'USD', 'amount': 555, }, ] response_post = ows_payee_client.post_payoneer_mass_payout(post_body) assert response_post.status_code == 201 def test_post_account_payee_tax_details_empty_address2(basic_headers): """POST /account-payee/{account_payee_id}/tax-details.""" ows_payee_client = ows_payee_api_client(basic_headers) updated_business_name = 'QA_automation_{}'.format(generate_random_string(16)) account_payee_id = 2 post_body = { 'vat_number': '355699311774', 'business_name': updated_business_name, 'business_number': '013301333', 'country_of_tax_residency_code': 'POL', 'address': { 'address_1': 'Down the line street', 'address_2': '', 'zip': '10001', 'country_code': 'USA', 'city': 'New York', 'province': 'Quebec', }, } response_post = ows_payee_client.post_account_payee_tax_details( account_payee_id, post_body ) assert response_post.status_code == 201, response_post.json() assert response_post.json()['account_payee_id'] == account_payee_id assert response_post.json()['vat_number'] == post_body['vat_number'] assert response_post.json()['business_name'] == post_body['business_name'] assert response_post.json()['business_number'] == post_body['business_number'] assert ( response_post.json()['country_of_tax_residency_code'] == post_body['country_of_tax_residency_code'] ) assert response_post.json()['address'] == post_body['address'] assert 'modified_by_profile_type' in response_post.json() assert 'modified_by_profile_id' in response_post.json() assert 'modified_by_identity' in response_post.json() assert 'modified_by' in response_post.json() assert 'modified_at' in response_post.json() assert 'revision' in response_post.json() def test_post_get_account_payee_tax_details(basic_headers): """POST/GET /account-payee/{account_payee_id}/tax-details .""" ows_payee_client = ows_payee_api_client(basic_headers) updated_business_name = 'QA_automation_{}'.format(generate_random_string(16)) account_payee_id = 2 post_body = { 'vat_number': '710882182', 'business_name': updated_business_name, 'business_number': '013301333', 'country_of_tax_residency_code': 'POL', 'address': { 'address_1': 'Down the line street', 'address_2': 'Alternative address', 'zip': '10001', 'country_code': 'USA', 'city': 'New York', 'province': 'Quebec', }, } response_get = ows_payee_client.get_account_payee_tax_details(ACCOUNT_PAYEE_ID) assert response_get.status_code == 200 assert 'account_payee_id' in response_get.json() assert 'vat_number' in response_get.json() assert 'business_name' in response_get.json() assert 'business_number' in response_get.json() assert 'country_of_tax_residency_code' in response_get.json() assert 'address' in response_get.json() assert 'business_name' != updated_business_name response_post = ows_payee_client.post_account_payee_tax_details( account_payee_id, post_body ) assert response_post.status_code == 201, response_post.json() assert response_post.json()['account_payee_id'] == account_payee_id assert response_post.json()['vat_number'] == post_body['vat_number'] assert response_post.json()['business_name'] == post_body['business_name'] assert response_post.json()['business_number'] == post_body['business_number'] assert ( response_post.json()['country_of_tax_residency_code'] == post_body['country_of_tax_residency_code'] ) assert response_post.json()['address'] == post_body['address'] assert 'modified_by_profile_type' in response_post.json() assert 'modified_by_profile_id' in response_post.json() assert 'modified_by_identity' in response_post.json() assert 'modified_by' in response_post.json() assert 'modified_at' in response_post.json() assert 'revision' in response_post.json() response_get = ows_payee_client.get_account_payee_tax_details(account_payee_id) assert response_get.status_code == 200 assert response_get.json()['business_name'] == updated_business_name def test_get_account_payee_tax_details_receipt(basic_headers): """GET /account-payee/{account_payee_id}/tax-details/receipt .""" ows_payee_client = ows_payee_api_client(basic_headers) response_get = ows_payee_client.get_account_payee_tax_details_receipt( ACCOUNT_PAYEE_ID ) assert response_get.status_code == 200 assert 'PDF' in response_get.text def test_get_account_payee_payoneer_status(basic_headers): """GET /account-payee/{account_payee_id}/payoneer-status .""" ows_payee_client = ows_payee_api_client(basic_headers) response_get = ows_payee_client.get_account_payee_payoneer_status(2) assert response_get.status_code == 200 assert 'payoneer_account_id' in response_get.json() assert 'status' in response_get.json() def test_get_account_payee_tax_receipt_url(basic_headers): """GET /account-payee/{account_payee_id}/tax-details/receipt-url .""" ows_payee_client = ows_payee_api_client(basic_headers) response_get = ows_payee_client.get_account_payee_tax_details_receipt_url( ACCOUNT_PAYEE_ID ) assert response_get.status_code == 200 assert 'receipt_url' in response_get.json() def test_post_payoneer_registration_link(documents_headers): """POST /payoneer/registration-link .""" ows_payee_client = ows_payee_api_client(documents_headers) post_body = { 'account_payee_id': ACCOUNT_PAYEE_ID, 'payoneer_program_id': PREEXISTING_PAYONEER_ACCOUNT_PROGRAM_IDS[0], } response_post = ows_payee_client.post_payoneer_registration_link(post_body) assert response_post.status_code == 201 assert 'registration_link' in response_post.json() assert 'account_payee_id' in response_post.json() def test_post_tax_details_dataloader(basic_headers): """GET /tax-details-history and POST /tax-details-dataloader.""" ows_payee_client = ows_payee_api_client(basic_headers) # TODO: change this id to test_ids once test entities are created in QA (DOC-382) account_payee_id_1 = 4 account_payee_id_2 = 5 account_payee_ids = [account_payee_id_1, account_payee_id_2] for acc_id in account_payee_ids: business_name = 'QA_automation_{}'.format(generate_random_string(16)) post_body = { 'vat_number': '036139833', 'business_name': business_name, 'business_number': '013301333', 'country_of_tax_residency_code': 'POL', 'address': { 'address_1': 'Down the line street', 'address_2': 'Alternative address', 'zip': '10001', 'country_code': 'USA', 'city': 'New York', 'province': 'Quebec', }, } response_post = ows_payee_client.post_account_payee_tax_details( acc_id, post_body ) assert response_post.status_code == 201 updated_business_name = 'QA_automation_{}'.format(generate_random_string(16)) post_body = { 'vat_number': '293129633', 'business_name': updated_business_name, 'business_number': '013301333', 'country_of_tax_residency_code': 'POL', 'address': { 'address_1': 'Down the line street', 'address_2': 'Alternative address', 'zip': '10001', 'country_code': 'USA', 'city': 'New York', 'province': 'Quebec', }, } response_post = ows_payee_client.post_account_payee_tax_details( acc_id, post_body ) assert response_post.status_code == 201 res_get = ows_payee_client.get_account_payee_tax_details_history(account_payee_id_1) assert res_get.status_code == 200 assert len(res_get.json()['items']) > 0 revision_1 = res_get.json()['items'][0]['revision'] res_get = ows_payee_client.get_account_payee_tax_details_history(account_payee_id_2) assert res_get.status_code == 200 assert len(res_get.json()['items']) > 0 revision_2 = res_get.json()['items'][0]['revision'] body = [ {'accountPayeeId': account_payee_id_1, 'revision': revision_1}, {'accountPayeeId': account_payee_id_2, 'revision': revision_2}, ] res_post = ows_payee_client.post_account_payee_tax_details_dataloader(body) assert res_post.status_code == 200 assert len(res_post.json()) == 2 assert res_post.json()[0]['data']['account_payee_id'] == account_payee_id_1 assert res_post.json()[0]['data']['revision'] == str(revision_1) assert res_post.json()[1]['data']['account_payee_id'] == account_payee_id_2 assert res_post.json()[1]['data']['revision'] == str(revision_2) def test_post_tax_details_dataloader_no_access(bad_headers): """POST /tax-details-dataloader (no access).""" # TODO: change this id to test_id once test entities are created in QA (DOC-382) account_payee_id = 2 ows_payee_client = ows_payee_api_client(bad_headers) body = [{'accountPayeeId': account_payee_id, 'revision': 'testing_here'}] res_post = ows_payee_client.post_account_payee_tax_details_dataloader(body) assert res_post.status_code == 401 assert res_post.json() == { 'error': "No valid identity found in request context, You don't have access to this resource!" } def test_post_knr_details_dataloader(basic_headers): """GET /knr-details-history and POST /knr-details-dataloader.""" ows_payee_client = ows_payee_api_client(basic_headers) # TODO: change this id to test_ids once test entities are created in QA (DOC-382) account_payee_id_1 = 2 account_payee_id_2 = 3 res_get = ows_payee_client.get_account_payee_knr_details_history(account_payee_id_1) assert res_get.status_code == 200 assert len(res_get.json()['items']) > 0 revision_1 = res_get.json()['items'][0]['revision'] res_get = ows_payee_client.get_account_payee_knr_details_history(account_payee_id_2) assert res_get.status_code == 200 assert len(res_get.json()['items']) > 0 revision_2 = res_get.json()['items'][0]['revision'] body = [ {'accountPayeeId': account_payee_id_1, 'revision': revision_1}, {'accountPayeeId': account_payee_id_2, 'revision': revision_2}, ] res_post = ows_payee_client.post_account_payee_knr_details_dataloader(body) assert res_post.status_code == 200 assert len(res_post.json()) == 2 assert res_post.json()[0]['data']['account_payee_id'] == account_payee_id_1 assert res_post.json()[0]['data']['revision'] == str(revision_1) assert res_post.json()[1]['data']['account_payee_id'] == account_payee_id_2 assert res_post.json()[1]['data']['revision'] == str(revision_2) def test_post_knr_details_dataloader_no_access(bad_headers): """POST /knr-details-dataloader (no access).""" # TODO: change this id to test_id once test entities are created in QA (DOC-382) account_payee_id = 2 ows_payee_client = ows_payee_api_client(bad_headers) body = [{'accountPayeeId': account_payee_id, 'revision': 'testing_here'}] res_post = ows_payee_client.post_account_payee_knr_details_dataloader(body) assert res_post.status_code == 200 assert res_post.json() == [{'error': "You don't have access to this resource!"}] def test_post_tax_withholding_override(basic_headers): """POST account-payee/withholding-tax-override/dataloader .""" account_payee_id = 2 ows_payee_client = ows_payee_api_client(basic_headers) body_list = [ ( { 'certificate_expiration_date': '2025-10-01', 'message': 'old messgae', 'rate_override': 20.00, }, 200, ), ( { 'certificate_expiration_date': '2022-10-02', 'message': 'new message', 'rate_override': 30.25, }, 200, ), ({}, 400), ({'certificate_expiration_date': 'invalid_date'}, 400), ({'rate_override': 101}, 400), ] for body, expected_code in body_list: res_post = ows_payee_client.post_tax_withholding_override( account_payee_id, body ) assert res_post.status_code == expected_code if expected_code == 200: assert res_post.json().get('account_payee_id') == account_payee_id assert res_post.json().get('certificate_expiration_date') == body.get( 'certificate_expiration_date' ) assert res_post.json().get('message') == body.get('message') assert float(res_post.json().get('rate_override')) == body.get( 'rate_override' ) def test_post_tax_withholding_override_dataloader(basic_headers): """POST account-payee/withholding-tax-override/dataloader .""" ows_payee_client = ows_payee_api_client(basic_headers) body = [1, 2, 3] res_post = ows_payee_client.post_tax_withholding_override_dataloader(body) assert res_post.status_code == 200 items = res_post.json().get('items') assert len(items) == 3 for item in items: assert 'data' in item data = item.get('data', None) if data: assert data.get('account_payee_id') in [1, 2]