import json import os import boto3 import pytest from tests.integration.utils.ows_payment_api_client import PaymentAPIClient QA_BASE_URL = 'https://qa-ows-payment.theorchard.io/' QA_LOAD_FROM_S3_BUCKET = f'qa-lambda-documents-load-from-s3' FIXTURES_DIR = 'integration_tests' AWS_REGION = os.environ.get('AWS_DEFAULT_REGION', 'us-east-1') def load_s3_fixture(fixture_name: str) -> list: """Loading some more sensitive fixtures here, that we do not want co commit to VCS.""" try: session = boto3.session.Session() client = session.client(service_name='s3', region_name=AWS_REGION) response = client.get_object( Bucket=QA_LOAD_FROM_S3_BUCKET, Key=f'{FIXTURES_DIR}/{fixture_name}.json' ) fixture = json.loads(response['Body'].read()) except Exception as e: raise RuntimeError(f'Unable to load test fixture from S3: {e}') from e return fixture @pytest.fixture def qa_env_client(abacus_headers) -> PaymentAPIClient: """ Client fixture local to these tests, to ensure we go to QA anyway. The functionality is readonly and requires the app to be connected to Sonwflake. So lets use QA env not to bother with special Snowflake permissions for flexible cases like we have for other integration tests. Note: other integration tests could work with local containers, depending on the config. """ return PaymentAPIClient(QA_BASE_URL, abacus_headers) @pytest.mark.jira('TAP-3327') @pytest.mark.parametrize( 'filters,items', load_s3_fixture('payment_search_integration_tests_fixture') ) def test_payment_search_filters(qa_env_client: PaymentAPIClient, filters, items): """Tests using the retrospective payments data, that won't change.""" resp = qa_env_client.payment_search_search({'filters': filters}) assert resp.status_code == 200, resp.text assert sorted(resp.json()['items'], key=lambda i: i['_id']) == sorted( items, key=lambda i: i['_id'] ), json.dumps(resp.json()['items'], sort_keys=True) assert resp.json()['total_count'] == len(items) @pytest.mark.jira('TAP-3327') def test_payment_search_error(qa_env_client: PaymentAPIClient): """Tests expected validation errors.""" resp = qa_env_client.payment_search_search({'filters': None}) assert resp.status_code == 400, resp.text resp = qa_env_client.payment_search_search({'filters': {}}) assert resp.status_code == 400, resp.text