Skip to content

Latest commit

 

History

History
255 lines (186 loc) · 4.84 KB

File metadata and controls

255 lines (186 loc) · 4.84 KB

Testing Guide - Flowfull-Python Client

📋 Overview

This document provides comprehensive information about testing the Flowfull-Python Client.

🧪 Test Suite

The test suite includes:

  • Unit Tests - Test individual components in isolation
  • Integration Tests - Test component interactions
  • Async Tests - Test asynchronous functionality
  • Type Tests - Test Pydantic model validation

Test Coverage

Component Test File Coverage
Operators test_operators.py ✅ 100%
Storage test_storage.py ✅ 100%
Session test_session.py ✅ 100%
Query Builder test_query.py ✅ 100%
Types test_types.py ✅ 100%
Errors test_errors.py ✅ 100%
Sync Client test_client.py ✅ 95%
Async Client test_async_client.py ✅ 95%

🚀 Running Tests

Prerequisites

Install test dependencies:

pip install -r requirements-dev.txt

Quick Start

Windows (PowerShell):

.\run_tests.ps1

Linux/Mac:

python run_tests.py

Direct pytest:

pytest

Common Test Commands

Run All Tests

pytest

Run with Coverage

pytest --cov=core --cov-report=html

Or using the script:

.\run_tests.ps1 -Coverage

Run Specific Test File

pytest tests/test_operators.py
pytest tests/test_client.py

Run Specific Test Class

pytest tests/test_operators.py::TestComparisonOperators

Run Specific Test Method

pytest tests/test_operators.py::TestComparisonOperators::test_eq

Run with Verbose Output

pytest -v
pytest -vv  # Extra verbose

Or using the script:

.\run_tests.ps1 -Verbose

Run Fast Tests Only (Skip Slow)

pytest -m "not slow"

Or using the script:

.\run_tests.ps1 -Fast

Run Only Async Tests

pytest -m asyncio

📊 Coverage Reports

Generate HTML Coverage Report

pytest --cov=core --cov-report=html

Open htmlcov/index.html in your browser to view the report.

Generate Terminal Coverage Report

pytest --cov=core --cov-report=term-missing

Coverage Goals

  • Overall Coverage: 95%+
  • Core Modules: 100%
  • Client Modules: 95%+
  • Helper Modules: 95%+

🔧 Test Configuration

pytest.ini

The pytest.ini file contains pytest configuration:

  • Test discovery patterns
  • Output options
  • Markers for test categorization
  • Async support configuration

conftest.py

The conftest.py file provides shared fixtures:

  • memory_storage - Clean MemoryStorage instance
  • mock_client - FlowfullClient with memory storage
  • mock_async_client - AsyncFlowfullClient with memory storage
  • sample_user_data - Sample user data
  • sample_api_response - Sample API response
  • sample_login_credentials - Sample login credentials
  • sample_session_id - Sample session ID

📝 Writing Tests

Test Structure

"""
Tests for [Component Name]

This file is part of Flowfull-Python Client.
License: AGPL-3.0-or-later
"""

import pytest
from core import [ComponentToTest]


class Test[ComponentName]:
    """Test [component] functionality"""

    def test_[feature](self):
        """Test [specific feature]"""
        # Arrange
        component = [ComponentToTest]()
        
        # Act
        result = component.method()
        
        # Assert
        assert result == expected

Using Fixtures

def test_with_fixture(mock_client):
    """Test using a fixture"""
    response = mock_client.get("/users")
    assert response is not None

Async Tests

@pytest.mark.asyncio
async def test_async_feature(mock_async_client):
    """Test async feature"""
    response = await mock_async_client.get("/users")
    assert response.success

Mocking

from unittest.mock import Mock, patch

@patch('core.request.RequestHandler.request')
def test_with_mock(mock_request):
    """Test with mocked request"""
    mock_request.return_value = ApiResponse(success=True, data=[])
    # Test code here

🐛 Debugging Tests

Run Single Test with Output

pytest tests/test_client.py::TestFlowfullClient::test_get_request -v -s

Run with Python Debugger

pytest --pdb

Run with Detailed Traceback

pytest --tb=long

✅ Best Practices

  1. Test Isolation - Each test should be independent
  2. Clear Names - Use descriptive test names
  3. AAA Pattern - Arrange, Act, Assert
  4. Mock External Calls - Don't make real API calls
  5. Test Edge Cases - Test error conditions and edge cases
  6. Use Fixtures - Reuse common test setup
  7. Document Tests - Add docstrings to test methods

📄 License

All test files are licensed under AGPL-3.0-or-later.

Copyright (C) 2024 Pubflow Team