Metadata-Version: 2.4
Name: rapidtest
Version: 0.9.1
Summary: A lightweight library for REST API testing with HTTP, ASGI, and performance testing
Author-email: Hector Rosales <h.rosales01@ufromail.cl>
License: MIT
Project-URL: Homepage, https://github.com/Hector-2710/rapidtest
Project-URL: Documentation, https://rapidtest.readthedocs.io
Project-URL: Bug Tracker, https://github.com/Hector-2710/rapidtest/issues
Project-URL: Source Code, https://github.com/Hector-2710/rapidtest
Keywords: testing,api,rest,http,fastapi,asgi,httptest,performance,load-testing
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Developers
Classifier: Development Status :: 4 - Beta
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.25.1
Requires-Dist: faker>=13.0.0
Dynamic: license-file

![RapidTest Logo](docs/images/RapidTest-logo.png)

# RapidTest

A lightweight library for REST API testing with ASGI/HTTP mode, fake data generation, and performance testing.

[![Python Version](https://img.shields.io/pypi/pyversions/rapidtest)](https://pypi.org/project/rapidtest/)
[![License](https://img.shields.io/pypi/l/rapidtest)](LICENSE)
[![PyPI Version](https://img.shields.io/pypi/v/rapidtest)](https://pypi.org/project/rapidtest/)
[![Downloads](https://img.shields.io/pypi/dm/rapidtest)](https://pypi.org/project/rapidtest/)

## Features

- **ASGI Testing** - Test FastAPI/Starlette apps directly without HTTP server
- **HTTP Testing** - Test external APIs with `GET`, `POST`, `PUT`, `PATCH`, `DELETE`
- Built-in response validation (status, JSON body, required keys)
- Fake data generation with Faker
- Performance testing with concurrent users (`threading` + `requests`)
- Test any endpoint with just one line of code

## Installation

```bash
pip install rapidtest
```

## CLI

Run tests from the tests directory:

```bash
rapidtest run
```

Scan a FastAPI/Starlette app to generate ASGI tests:

```bash
rapidtest scan module:app
```

- **ASGI Testing** - Test FastAPI/Starlette apps directly without HTTP server
- **HTTP Testing** - Test external APIs with `GET`, `POST`, `PUT`, `PATCH`, `DELETE`
- Built-in response validation (status, JSON body, required keys)
- Fake data generation with Faker
- Performance testing with concurrent users (`threading` + `requests`)
- Test any endpoint with just one line of code

## Installation

```bash
pip install rapidtest
```

## CLI

Run tests from the tests directory:

```bash
rapidtest run
```

Scan a FastAPI/Starlette app to generate ASGI tests:

```bash
rapidtest scan module:app
```
## Quick Start (ASGI mode)

Use this when you want to test your ASGI app directly (for example FastAPI) without network overhead.

```python
from backend.main import app
from rapidtest import ASGITest, StatusCode


tester = ASGITest(app=app)

tester.get(
    path="/ping",
    status=StatusCode.OK_200,
    json={"ok": True}
)
```

**Output:**
```
✅ 1. PASSED
time: 0.01 s
```

## Quick Start (HTTP mode)

```python
from rapidtest import HTTPTest, StatusCode

api = HTTPTest(url="http://localhost:8000")

api.get(
    path="/health",
    status=StatusCode.OK_200,
    keys=["message"]
)

payload = {"username": "hector", "password": "secret"}
api.post(
    path="/login",
    json=payload,
    status=StatusCode.OK_200,
    keys=["token"]
)
```

**Output:**
```
✅ 1. PASSED
✅ 2. PASSED
time: 0.05 s
```

## Data Generation

```python
from rapidtest import Data

auth = Data.generate_auth_user()

print(auth)  # {"username": "...", "password": "..."}
```

Useful helpers include:

- `generate_name()`
- `generate_email()`
- And more...

## Performance Testing

```python
from rapidtest import Performance

perf = Performance(
    base_url="http://localhost:8000",
    users=20,
    duration=15,
    timeout=10
)

# Add multiple endpoints with different methods
perf.add_task(endpoint="/health", method="GET")
perf.add_task(endpoint="/login", method="POST", json={"user": "test"})

results = perf.run()
```

Returned metrics:

- `total_requests`
- `successful_requests`
- `failed_requests`
- `success_rate`
- `avg_response_time`
- `min_response_time`
- `max_response_time`
- `requests_per_second`
- `duration`
- `users`

## Requirements

- Python `>=3.10`
- `requests>=2.25.1`
- `faker>=13.0.0`

## Project Info

- Version: `0.9.1`
- Author: Hector Rosales
- License: MIT
- Homepage: https://github.com/hector-2710/rapidtest
- Issues: https://github.com/hector-2710/rapidtest/issues
