This document describes the comprehensive test suite for the invoice automation system. The tests validate all functionality including core features, new enhancements (meeting time/duration overrides and rate management), and integration with external services.
tests/
├── __init__.py # Test package initialization
├── conftest.py # Shared fixtures and test configuration
├── test_unit.py # Unit tests for individual functions
├── test_integration.py # Integration tests with external APIs
├── test_commands.py # Interactive command system tests
├── test_e2e.py # End-to-end workflow tests
└── test_data/ # Sample test data
├── customers.json # Sample Stripe customers
├── meetings.json # Sample calendar events
└── invoices.json # Sample invoices
pip install -r test_requirements.txt# Using pytest directly
pytest
# Using the test runner script
python run_tests.py
# With coverage report
python run_tests.py --coverage# Unit tests only
python run_tests.py unit
# Integration tests only
python run_tests.py integration
# Interactive command tests
python run_tests.py commands
# End-to-end tests
python run_tests.py e2e
# Quick tests (excludes slow tests)
python run_tests.py quickTests individual functions in isolation:
test_parse_time_input_*- Time parsing with various formatstest_parse_duration_input_*- Duration parsing and validationtest_validate_hourly_rate_*- Rate validation and parsing
test_generate_meeting_id- Meeting ID generation consistencytest_calculate_meeting_duration- Duration calculation accuracytest_get_customer_hourly_rate- Rate retrieval with fallbackstest_check_meeting_invoice_status- Invoice status checking
test_get_calendar_service_*- Various authentication scenariostest_token_refresh_*- Token refresh success and failure casestest_authentication_failure_*- Error handling during auth flow
test_meeting_initialization- Meeting object structuretest_edited_meeting_values- Override value handlingtest_meeting_amount_calculation- Billing calculations
Tests interactions with external services (mocked):
- Customer fetching with pagination
- Invoice creation and line items
- Customer metadata updates
- Error handling for API failures
- Event fetching within date ranges
- Meeting-to-customer matching
- OAuth token handling and refresh
- Token expiration and re-authentication flow
- Error recovery scenarios
- Authentication failure handling
Tests the interactive command system:
- Meeting selection/deselection (
1,2, etc.) - Bulk operations (
all,none) - Meeting editing (
edit 1,time 1) - Rate management (
rate 1 250,setrate email@example.com 200) - Invalid command handling
test_edit_meeting_details- Time/duration editing flowtest_synopsis_entry- Meeting description input- Input validation and error handling
Tests complete workflows:
- Single customer with multiple meetings
- Meeting time/duration editing workflow
- Custom rate application workflow
- Customer rate update workflow
- No meetings found
- All meetings already invoiced
- API failures and recovery
- Invalid data handling
- Authentication token expiration during runtime
- Network connectivity issues
- 5 test customers with various configurations
- Some with hourly rates, some without
- Different rate tiers ($150-$300/hour)
- 6 calendar events with different scenarios
- Various durations (30 min to 2 hours)
- Different attendee configurations
- Existing invoices in different states (draft, open, paid)
- Used for testing duplicate invoice prevention
# Generate coverage report
pytest --cov=invoice_automation --cov-report=html
# View coverage report
open htmlcov/index.html- Overall coverage: >80%
- Critical paths: 100%
- Error handling: >90%
- Authentication flows: 100%
Use pytest markers to run specific test categories:
# Run only unit tests
pytest -m unit
# Run only integration tests
pytest -m integration
# Run only end-to-end tests
pytest -m e2e
# Exclude slow tests
pytest -m "not slow"name: Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.9'
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install -r test_requirements.txt
- name: Run tests
run: pytest --cov=invoice_automationclass TestFeatureName:
"""Test suite for specific feature"""
def test_happy_path(self, test_invoicer, mock_input):
"""Test normal successful flow"""
# Arrange
test_data = {...}
# Act
result = test_invoicer.method_name(test_data)
# Assert
assert result.expected_value == actual_value
def test_edge_case(self, test_invoicer):
"""Test boundary conditions"""
pass
def test_error_handling(self, test_invoicer, mocker):
"""Test error scenarios"""
passCommon fixtures available in conftest.py:
test_invoicer- Pre-configured invoicer instancesample_customer- Test customer datasample_meeting- Test meeting datamock_input- Mock user inputmock_print- Capture print output
pytest tests/test_unit.py::TestParsingFunctions::test_parse_time_input_valid_formats -vpytest -spytest --pdbpytest -l- Isolation: Each test should be independent
- Mocking: Mock external services (Stripe, Google Calendar)
- Fixtures: Use shared fixtures for common test data
- Assertions: Be specific about what you're testing
- Coverage: Aim for high coverage but focus on critical paths
- Documentation: Document complex test scenarios
Import errors: Ensure the parent directory is in Python path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))Mock not working: Check mock path matches actual import
mocker.patch('invoice_automation.stripe.Customer.list') # ❌ Wrong
mocker.patch('stripe.Customer.list') # ✅ CorrectFixture not found: Ensure conftest.py is in the tests directory
- Performance benchmarks
- Load testing for bulk operations
- Integration tests with real test accounts
- Mutation testing
- Security testing for API key handling