This document describes the structure, architecture, and usage of the test suite for the Akoya SDK. It is intended for developers who want to understand, extend, or contribute to the test coverage of the SDK.
- Python 3.11 or higher
- Git for version control
- Playwright for automated consent flow
- Environment Variables (see Configuration section)
tests/
endpoint_tests/
controller_test_base.py
test_account_info_controller.py
test_balances_controller.py
test_customers_controller.py
test_investments_controller.py
test_payments_controller.py
test_statements_controller.py
test_transactions_controller.py
test_tax_controller.py
auth_tests/
test_error_scenarios.py
http_response_catcher.py
- endpoint_tests/: Tests for each Akoya SDK controller, organized by product.
- endpoint_tests/controller_test_base.py: Base class for controller tests, handling client setup and authentication.
- auth_tests/: Contains tests for common authentication error scenarios, including specific error codes returned by the Akoya API.
Create a .env file in the project root with the following variables:
# OAuth 2.0 Client Credentials
OAUTH_CLIENT_ID=your_client_id
OAUTH_CLIENT_SECRET=your_client_secret
OAUTH_REDIRECT_URI=your_redirect_uri
# Akoya API Configuration
AKOYA_API_VERSION=v2 # e.g., v2
AKOYA_PROVIDER_ID=mikomo # e.g., mikomo (the bank connector ID)
# Akoya Environment (SANDBOX or PRODUCTION)
ENVIRONMENT=SANDBOX # or PRODUCTION
# Test User Credentials (for automated consent flow)
TEST_USERNAME=your_test_username
TEST_PASSWORD=your_test_password
# Akoya Connector and State (for consent flow)
CONNECTOR=your_connector
STATE=random_state_string
# Redirect URI for Playwright to wait for
RETURN_URL=your_redirect_uriFor CI/CD, add these variables as secrets in your GitHub repository:
OAUTH_CLIENT_IDOAUTH_CLIENT_SECRETAKOYA_API_VERSIONAKOYA_PROVIDER_IDTEST_USERNAMETEST_PASSWORDCONNECTORSTATERETURN_URLENVIRONMENT
- Controller-based: Each controller (e.g., Account Info, Balances, Transactions) has its own test file.
- Test Methods: Each method targets a specific endpoint, using request data and parameters as found in the official Postman collection.
- Error Handling: For endpoints with error scenarios (e.g., invalid token), tests simulate these by injecting invalid credentials.
- Base Class: All test classes inherit from
ControllerTestBase, which manages client instantiation and authentication setup. - Consent Flow: Automated using Playwright, runs only once per test session and reuses the token.
class TestBalancesController(ControllerTestBase):
def test_get_balances(self, client):
response = client.balances.get_balances(
version="v2",
provider_id="mikomo"
)
assert response is not None
assert response.status_code == 200
assert response.body is not None- Identify the Controller: Find the relevant controller test file in
tests/endpoint_tests/(e.g.,test_payments_controller.pyfor Payments endpoints). - Add a Test Method:
- Use the naming convention:
test_<endpoint_description>. - Use the request data (parameters, path, etc.) as in the Postman collection or API docs.
- Use the
clientfixture provided by the base class.
- Use the naming convention:
- Example:
def test_get_new_feature(self, client):
response = client.some_controller.get_new_feature(
version="v2",
provider_id="mikomo",
# ...other params...
)
assert response is not None
assert response.status_code == 200
assert response.body is not None- Error Scenarios: To test error cases (e.g., invalid token), clone the client with an invalid token and assert that an exception is raised.
def test_feature_with_invalid_token(self, client):
invalid_client = client.__class__(config=client.config.clone_with(
authorization_code_auth_credentials=client.config.authorization_code_auth_credentials.clone_with(
oauth_token="invalid_token"
)
))
with pytest.raises(Exception):
invalid_client.some_controller.get_new_feature(...)- Run the Tests to verify your additions (see below).
-
Install Dependencies
From the project root, install the requirements:pip install -r requirements.txt pip install -r test-requirements.txt
-
Install Playwright
python -m playwright install --with-deps
-
Run All Tests
From the project root, run:pytest
This will discover and run all tests in the
tests/directory. -
Run with Verbose Output
pytest -v
-
Run with Tracing
pytest --tracing=retain-on-failure
-
Run a Specific Test File
pytest tests/endpoint_tests/test_balances_controller.py
-
Run a Specific Test Method
pytest tests/endpoint_tests/test_balances_controller.py::TestBalancesController::test_get_balances
The test suite is integrated with GitHub Actions for continuous integration. The workflow:
- Sets up Python 3.11
- Installs dependencies
- Configures environment variables from secrets
- Installs Playwright and its dependencies
- Runs the test suite
- Uploads test artifacts on failure
To view the workflow, see .github/workflows/run-tests.yml.
- Keep test data in sync with the Postman collection and API documentation.
- Use descriptive test names for clarity.
- Group related tests in the appropriate controller test file.
- Test both success and error scenarios for robust coverage.
- Reuse the base class for consistent client setup and teardown.
- Handle pagination by extracting and using
prevandnextlinks from responses. - Use session-scoped fixtures for the consent flow to avoid multiple authentications.
-
Authentication Issues
- Verify environment variables are set correctly
- Check if the consent flow is completing successfully
- Ensure the test user has the necessary permissions
-
Playwright Issues
- Check if browsers are installed:
python -m playwright install --with-deps - Run with tracing:
pytest --tracing=retain-on-failure - Check the
test-results/directory for traces
- Check if browsers are installed:
-
Import Errors
- Ensure you're running from the project root
- Use
PYTHONPATH=.when running tests - Check if
__init__.pyfiles are present in all directories
-
CI/CD Issues
- Verify all required secrets are set in GitHub
- Check the workflow logs for detailed error messages
- Review the uploaded artifacts for traces
- Fork the repository
- Create a feature branch
- Add your tests
- Run the test suite locally
- Submit a pull request
For more details on the SDK and API usage, see the main README.md and the /doc directory.