Skip to content

turlapati/crud_template_test

Repository files navigation

Products CRUD API Test Suite

A comprehensive test suite for the Products CRUD API using httpx for parallel test execution.

Features

  • Async/Parallel Testing: Uses httpx for concurrent HTTP requests
  • Comprehensive Coverage: Happy path, edge cases, error handling, and more
  • Modular Structure: Organized by test categories for easy maintenance
  • Automatic Cleanup: Test fixtures handle resource cleanup automatically
  • Faker Integration: Generates realistic test data

Test Categories

Happy Path Tests (Implemented)

  • Product creation with all field combinations
  • Product retrieval with pagination scenarios
  • Product updates (partial and complete)
  • Product deletion
  • Root endpoint access
  • Parallel operations testing

Upcoming Test Categories

  • Input Validation Tests
  • Edge Case Tests
  • Error Handling Tests
  • Business Logic Tests
  • Security Tests
  • Performance Tests
  • Integration Tests

Setup

  1. Install test dependencies:
pip install -r requirements-test.txt
  1. Configure your API base URL in tests/conftest.py:
BASE_URL = "http://localhost:8000"  # Update this to match your API server

Running Tests

Using the Test Runner Script

# Install dependencies
python run_tests.py install

# Run happy path tests only
python run_tests.py happy

# Run all tests
python run_tests.py all

# Run tests with coverage report
python run_tests.py coverage

# Run tests in parallel
python run_tests.py parallel

Using pytest Directly

# Run happy path tests
pytest tests/test_happy_path.py -v -m happy_path

# Run all tests
pytest tests/ -v

# Run tests in parallel with auto CPU detection
pytest tests/ -n auto

# Run with coverage
pytest tests/ --cov=. --cov-report=html

Test Structure

tests/
├── conftest.py              # Test fixtures and configuration
├── test_happy_path.py       # Happy path test scenarios
└── (more test files to be added)

Key Features of the Happy Path Tests

Parallel Execution

Tests are designed to run concurrently using httpx.AsyncClient, significantly reducing execution time.

Automatic Resource Management

  • Products created during tests are automatically cleaned up
  • Fixtures handle setup and teardown
  • No manual cleanup required

Comprehensive Scenarios

  • Product Creation: All field combinations, boundary values
  • Product Retrieval: Pagination scenarios, individual product access
  • Product Updates: Partial and complete updates
  • Product Deletion: With verification
  • Parallel Operations: Concurrent create/read operations

Test Data Generation

Uses Faker library to generate realistic test data, ensuring tests don't rely on hardcoded values.

Configuration

pytest.ini

  • Configures async test mode
  • Sets test discovery patterns
  • Defines custom markers

conftest.py

  • HTTP client fixture with proper timeout and headers
  • Sample data generators
  • Resource cleanup utilities
  • Created product fixtures for easy testing

Next Steps

The test suite is designed for incremental implementation. After running the happy path tests successfully, you can implement additional test categories:

  1. Input Validation Tests
  2. Edge Case Tests
  3. Error Handling Tests
  4. Business Logic Tests
  5. Security Tests
  6. Performance Tests
  7. Integration Tests

Each category will follow the same async/parallel pattern established in the happy path tests.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages