-
Notifications
You must be signed in to change notification settings - Fork 14
Added The test suite #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Adez017
wants to merge
8
commits into
OpenVoiceX:main
Choose a base branch
from
Adez017:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d8cbecb
Restructuring
Adez017 e8f4ce1
Merge branch 'main' of https://github.com/Adez017/Voice-Marketing-Agent
Adez017 8f1479b
Added the test suite
Adez017 85d88a4
revert back
Adez017 21da1a7
Merge branch 'OpenVoiceX:main' into main
Adez017 500bb20
update files
Adez017 409cce6
Update stt_service.py
Hiteshydv001 f0129c7
Merge branch 'OpenVoiceX:main' into main
Adez017 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| [flake8] | ||
| max-line-length = 120 | ||
| exclude = | ||
| .git, | ||
| __pycache__, | ||
| venv, | ||
| env, | ||
| .venv, | ||
| migrations, | ||
| .pytest_cache | ||
| ignore = | ||
| E203, # whitespace before ':' | ||
| W503, # line break before binary operator | ||
| F401 # imported but unused (common in __init__.py files) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| .PHONY: test test-unit test-integration test-coverage lint format install-dev | ||
|
|
||
| # Install development dependencies | ||
| install-dev: | ||
| pip install -r requirements-dev.txt | ||
|
|
||
| # Run all tests | ||
| test: | ||
| pytest | ||
|
|
||
| # Run only unit tests | ||
| test-unit: | ||
| pytest -m "not integration and not slow" | ||
|
|
||
| # Run integration tests | ||
| test-integration: | ||
| pytest -m integration | ||
|
|
||
| # Run tests with coverage report | ||
| test-coverage: | ||
| pytest --cov=src --cov-report=html --cov-report=term | ||
|
|
||
| # Lint code | ||
| lint: | ||
| flake8 src tests | ||
| black --check src tests | ||
| isort --check-only src tests | ||
|
|
||
| # Format code | ||
| format: | ||
| black src tests | ||
| isort src tests | ||
|
|
||
| # Run tests in watch mode (requires pytest-xdist) | ||
| test-watch: | ||
| pytest --looponfail | ||
|
|
||
| # Clean up test artifacts | ||
| clean: | ||
| rm -rf .pytest_cache | ||
| rm -rf htmlcov | ||
| rm -rf .coverage | ||
| find . -type d -name __pycache__ -exec rm -rf {} + | ||
| find . -type f -name "*.pyc" -delete |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| # Testing Guide for Voice Marketing Agents | ||
|
|
||
| ## Quick Start | ||
|
|
||
| 1. **Setup (one-time):** | ||
| ```bash | ||
| cd backend | ||
| python setup_tests.py | ||
| ``` | ||
|
|
||
| 2. **Run tests:** | ||
| ```bash | ||
| pytest | ||
| ``` | ||
|
|
||
| ## Available Commands | ||
|
|
||
| - `make test` - Run all tests | ||
| - `make test-unit` - Run unit tests only | ||
| - `make test-coverage` - Run tests with coverage report | ||
| - `make lint` - Check code quality | ||
| - `make format` - Format code | ||
|
|
||
| ## Test Structure | ||
|
|
||
| - `tests/test_models/` - Database model tests | ||
| - `tests/test_services/` - AI service tests | ||
| - `tests/test_api/` - API endpoint tests | ||
| - `tests/test_agents/` - Agent logic tests | ||
|
|
||
| ## Writing New Tests | ||
|
|
||
| 1. Add test files with `test_` prefix | ||
| 2. Use provided fixtures from `conftest.py` | ||
| 3. Mock external services (LLM, STT, TTS) | ||
| 4. Follow existing test patterns | ||
|
|
||
| ## Coverage Requirements | ||
|
|
||
| - Minimum 80% code coverage | ||
| - All new features must include tests | ||
| - Critical paths must be tested | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| If tests fail: | ||
| 1. Check you're in the `backend/` directory | ||
| 2. Ensure dependencies are installed: `pip install -r requirements-dev.txt` | ||
| 3. Check that main application runs: `python -m src.main` | ||
| #!/bin/bash | ||
|
|
||
| # Test runner script for CI/CD | ||
|
|
||
| set -e | ||
|
|
||
| echo "🧪 Starting Voice Marketing Agents Test Suite" | ||
| echo "==============================================" | ||
|
|
||
| # Check if we're in a virtual environment | ||
| if [[ -z "${VIRTUAL_ENV}" ]]; then | ||
| echo "⚠️ Warning: Not running in a virtual environment" | ||
| fi | ||
|
|
||
| # Install test dependencies | ||
| echo "📦 Installing test dependencies..." | ||
| pip install -r requirements-dev.txt | ||
|
|
||
| # Run code formatting checks | ||
| echo "🎨 Checking code formatting..." | ||
| black --check src tests || { | ||
| echo "❌ Code formatting issues found. Run 'make format' to fix." | ||
| exit 1 | ||
| } | ||
|
|
||
| # Run import sorting checks | ||
| echo "📚 Checking import sorting..." | ||
| isort --check-only src tests || { | ||
| echo "❌ Import sorting issues found. Run 'make format' to fix." | ||
| exit 1 | ||
| } | ||
|
|
||
| # Run linting | ||
| echo "🔍 Running linting..." | ||
| flake8 src tests || { | ||
| echo "❌ Linting issues found." | ||
| exit 1 | ||
| } | ||
|
|
||
| # Run unit tests | ||
| echo "⚡ Running unit tests..." | ||
| pytest tests/ -v --tb=short --cov=src --cov-report=term-missing --cov-fail-under=80 | ||
|
|
||
| echo "" | ||
| echo "✅ All tests passed!" | ||
| echo "📊 Coverage report generated in htmlcov/" | ||
| echo "🎉 Voice Marketing Agents is ready for deployment!" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| [tool.black] | ||
| line-length = 120 | ||
| target-version = ['py311'] | ||
| include = '\.pyi? | ||
| #!/bin/bash | ||
|
|
||
| # Test runner script for CI/CD | ||
|
|
||
| set -e | ||
|
|
||
| echo "🧪 Starting Voice Marketing Agents Test Suite" | ||
| echo "==============================================" | ||
|
|
||
| # Check if we're in a virtual environment | ||
| if [[ -z "${VIRTUAL_ENV}" ]]; then | ||
| echo "⚠️ Warning: Not running in a virtual environment" | ||
| fi | ||
|
|
||
| # Install test dependencies | ||
| echo "📦 Installing test dependencies..." | ||
| pip install -r requirements-dev.txt | ||
|
|
||
| # Run code formatting checks | ||
| echo "🎨 Checking code formatting..." | ||
| black --check src tests || { | ||
| echo "❌ Code formatting issues found. Run 'make format' to fix." | ||
| exit 1 | ||
| } | ||
|
|
||
| # Run import sorting checks | ||
| echo "📚 Checking import sorting..." | ||
| isort --check-only src tests || { | ||
| echo "❌ Import sorting issues found. Run 'make format' to fix." | ||
| exit 1 | ||
| } | ||
|
|
||
| # Run linting | ||
| echo "🔍 Running linting..." | ||
| flake8 src tests || { | ||
| echo "❌ Linting issues found." | ||
| exit 1 | ||
| } | ||
|
|
||
| # Run unit tests | ||
| echo "⚡ Running unit tests..." | ||
| pytest tests/ -v --tb=short --cov=src --cov-report=term-missing --cov-fail-under=80 | ||
|
|
||
| echo "" | ||
| echo "✅ All tests passed!" | ||
| echo "📊 Coverage report generated in htmlcov/" | ||
| echo "🎉 Voice Marketing Agents is ready for deployment!" | ||
|
|
||
| extend-exclude = ''' | ||
| /( | ||
| migrations | ||
| | \.pytest_cache | ||
| )/ | ||
| ''' | ||
|
|
||
| [tool.isort] | ||
| profile = "black" | ||
| line_length = 120 | ||
| multi_line_output = 3 | ||
| include_trailing_comma = true | ||
| force_grid_wrap = 0 | ||
| use_parentheses = true | ||
| ensure_newline_before_comments = true | ||
| skip_glob = ["migrations/*"] | ||
Adez017 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Testing frameworks | ||
| pytest>=7.4.0 | ||
| pytest-asyncio>=0.21.0 | ||
| pytest-mock>=3.11.0 | ||
| httpx>=0.24.0 # For testing FastAPI async endpoints | ||
| factory-boy>=3.3.0 # For creating test data | ||
| faker>=19.0.0 # For generating fake data | ||
|
|
||
| # Test coverage | ||
| pytest-cov>=4.1.0 | ||
|
|
||
| # Code quality | ||
| black>=23.0.0 | ||
| isort>=5.12.0 | ||
| flake8>=6.0.0 | ||
|
|
||
| # Database testing | ||
| pytest-postgresql>=5.0.0 # For isolated test database |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| """ | ||
| Setup script to ensure the testing environment is ready. | ||
| Run this before running tests for the first time. | ||
| """ | ||
| import os | ||
| import sys | ||
| import subprocess | ||
|
|
||
| def install_test_dependencies(): | ||
| """Install test dependencies.""" | ||
| print("📦 Installing test dependencies...") | ||
| try: | ||
| subprocess.run([sys.executable, "-m", "pip", "install", "-r", "requirements-dev.txt"], check=True) | ||
| print("✅ Test dependencies installed successfully!") | ||
| except subprocess.CalledProcessError: | ||
| print("❌ Failed to install test dependencies") | ||
| return False | ||
| return True | ||
|
|
||
| def create_test_directories(): | ||
| """Create necessary test directories.""" | ||
| print("📁 Creating test directories...") | ||
| directories = [ | ||
| "tests", | ||
| "tests/test_models", | ||
| "tests/test_services", | ||
| "tests/test_api", | ||
| "tests/test_agents", | ||
| "tests/utils" | ||
| ] | ||
|
|
||
| for dir_path in directories: | ||
| os.makedirs(dir_path, exist_ok=True) | ||
| # Create __init__.py files for proper Python packages | ||
| init_file = os.path.join(dir_path, "__init__.py") | ||
| if not os.path.exists(init_file): | ||
| with open(init_file, "w") as f: | ||
| f.write("# Test package\n") | ||
|
|
||
| print("✅ Test directories created!") | ||
|
|
||
| def check_environment(): | ||
| """Check if the environment is ready for testing.""" | ||
| print("🔍 Checking environment...") | ||
|
|
||
| # Check if we're in the backend directory | ||
| if not os.path.exists("src"): | ||
| print("❌ Please run this script from the backend directory") | ||
| return False | ||
|
|
||
| # Check if main application files exist | ||
| required_files = [ | ||
| "src/main.py", | ||
| "src/core/database.py", | ||
| "src/models/agent.py" | ||
| ] | ||
|
|
||
| for file_path in required_files: | ||
| if not os.path.exists(file_path): | ||
| print(f"❌ Required file missing: {file_path}") | ||
| return False | ||
|
|
||
| print("✅ Environment looks good!") | ||
| return True | ||
|
|
||
| def main(): | ||
| """Main setup function.""" | ||
| print("🧪 Setting up Voice Marketing Agents Test Environment") | ||
| print("=" * 50) | ||
|
|
||
| if not check_environment(): | ||
| sys.exit(1) | ||
|
|
||
| create_test_directories() | ||
|
|
||
| if not install_test_dependencies(): | ||
| sys.exit(1) | ||
|
|
||
| print("\n🎉 Test environment setup complete!") | ||
| print("\nNext steps:") | ||
| print("1. Run tests: pytest") | ||
| print("2. Run with coverage: pytest --cov=src") | ||
| print("3. Use Makefile commands: make test, make test-coverage") | ||
|
|
||
| if __name__ == "__main__": | ||
| main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.