Skip to content
Snippets Groups Projects
Commit d21a0f94 authored by supersonicwisd1's avatar supersonicwisd1
Browse files

added testing readme

Signed-off-by: supersonicwisd1 <supersonicwisd1>
parent 5827e0cc
No related branches found
No related tags found
No related merge requests found
...@@ -31,15 +31,13 @@ async def handle_create(activity: APActivity): ...@@ -31,15 +31,13 @@ async def handle_create(activity: APActivity):
await federation.store_object(activity.object) await federation.store_object(activity.object)
``` ```
#### Run Example Usage
- [Server to Server Example](examples/README.md)
#### Documentation #### Documentation
- [Getting Started](documentation/getting-started.md) - [Getting Started](docs/getting-started.md)
- [Configuration Guide](documentation/configuration.md) - [Configuration Guide](docs/configuration.md)
- [Architecture Overview](documentation/architecture.md) - [Architecture Overview](docs/architecture.md)
- [Security Guide](documentation/security.md) - [Security Guide](docs/security.md)
- [API Reference](documentation/api/) - [API Reference](docs/api/)
- [Testing Guide](tests/README.md)
#### Requirements #### Requirements
- Python 3.9+ - Python 3.9+
......
...@@ -43,6 +43,7 @@ pymongo==4.9.2 ...@@ -43,6 +43,7 @@ pymongo==4.9.2
pytest==8.3.3 pytest==8.3.3
pytest-aiohttp==1.0.5 pytest-aiohttp==1.0.5
pytest-asyncio==0.24.0 pytest-asyncio==0.24.0
pytest-cov==4.1.0
python-dateutil==2.9.0.post0 python-dateutil==2.9.0.post0
PyYAML==6.0.2 PyYAML==6.0.2
redis==5.2.0 redis==5.2.0
......
# PyFed Tests
This directory contains the test suite for the PyFed library. The tests are written using pytest and are organized into different categories.
## Directory Structure
```
tests/
├── unit_tests/ # Unit tests for individual components
│ ├── models/ # Tests for ActivityPub models
│ ├── serializers/ # Tests for serialization/deserialization
└── pytest.ini # Pytest configuration
```
## Running Tests
### Prerequisites
- Python 3.9+
- pytest
- pytest-asyncio
- pytest-cov
### Installation
```bash
pip install . # Install packages
```
### Running All Tests
From the project root directory:
```bash
pytest
```
### Running Specific Test Categories
```bash
pytest tests/unit_tests/models/ # Run model tests only
pytest tests/unit_tests/serializers/ # Run serializer tests only
pytest tests/integration_tests/ # Run integration tests only
```
### Running with Coverage
```bash
pytest --cov=pyfed tests/
```
### Test Configuration
The test suite uses the following configuration from `pytest.ini`:
- `asyncio_mode = auto`: Enables automatic async test detection
- `pythonpath = ../src`: Adds source directory to Python path
- `addopts = --import-mode=importlib`: Uses importlib for imports
## Writing Tests
### Test Organization
- Place unit tests in the appropriate subdirectory under `unit_tests/`
- Use descriptive test names that indicate what is being tested
- Follow the pattern: `test_<what>_<expected_behavior>`
### Example Test
```python
def test_serialize_note():
"""Test serialization of a basic Note object."""
note = APNote(
id="https://example.com/notes/123",
content="Hello, World!"
)
serialized = note.serialize()
assert serialized["type"] == "Note"
assert serialized["content"] == "Hello, World!"
```
## Debugging Tests
- Use `pytest -v` for verbose output
- Use `pytest -s` to see print statements
- Use `pytest --pdb` to drop into debugger on failures
## Adding New Tests
1. Create test files in the appropriate directory
2. Follow existing naming conventions
3. Add necessary imports and fixtures
4. Document test purpose with docstrings
\ No newline at end of file
...@@ -65,7 +65,3 @@ def test_can_import_activities(): ...@@ -65,7 +65,3 @@ def test_can_import_activities():
def test_can_import_serializer(): def test_can_import_serializer():
"""Test that the serializer can be imported.""" """Test that the serializer can be imported."""
assert ActivityPubSerializer assert ActivityPubSerializer
# def test_can_import_plugin_manager():
# """Test that the plugin manager can be imported."""
# assert plugin_manager
...@@ -48,14 +48,12 @@ def test_serialize_nested_objects(): ...@@ -48,14 +48,12 @@ def test_serialize_nested_objects():
"""Test serialization of objects with nested objects.""" """Test serialization of objects with nested objects."""
author = APPerson( author = APPerson(
id="https://example.com/users/alice", id="https://example.com/users/alice",
type="Person",
name="Alice", name="Alice",
inbox="https://example.com/users/alice/inbox", inbox="https://example.com/users/alice/inbox",
outbox="https://example.com/users/alice/outbox" outbox="https://example.com/users/alice/outbox"
) )
note = APNote( note = APNote(
id="https://example.com/notes/123", id="https://example.com/notes/123",
type="Note",
content="Hello, World!", content="Hello, World!",
attributed_to=author attributed_to=author
) )
...@@ -71,13 +69,11 @@ def test_serialize_collection(): ...@@ -71,13 +69,11 @@ def test_serialize_collection():
items = [ items = [
APNote( APNote(
id=f"https://example.com/notes/{i}", id=f"https://example.com/notes/{i}",
type="Note",
content=f"Note {i}" content=f"Note {i}"
).serialize() for i in range(3) ).serialize() for i in range(3)
] ]
collection = APCollection( collection = APCollection(
id="https://example.com/collection/1", id="https://example.com/collection/1",
type="Collection",
total_items=len(items), total_items=len(items),
items=items items=items
) )
...@@ -93,12 +89,10 @@ def test_serialize_activity(): ...@@ -93,12 +89,10 @@ def test_serialize_activity():
"""Test serialization of activities.""" """Test serialization of activities."""
note = APNote( note = APNote(
id="https://example.com/notes/123", id="https://example.com/notes/123",
type="Note",
content="Hello, World!" content="Hello, World!"
).serialize() ).serialize()
create = APCreate( create = APCreate(
id="https://example.com/activities/1", id="https://example.com/activities/1",
type="Create",
actor="https://example.com/users/alice", actor="https://example.com/users/alice",
object=note object=note
) )
...@@ -156,7 +150,6 @@ def test_serialize_deserialize_complex_object(): ...@@ -156,7 +150,6 @@ def test_serialize_deserialize_complex_object():
"""Test round-trip serialization and deserialization.""" """Test round-trip serialization and deserialization."""
original = APNote( original = APNote(
id="https://example.com/notes/123", id="https://example.com/notes/123",
type="Note",
content="Test content", content="Test content",
to=["https://example.com/users/bob"], to=["https://example.com/users/bob"],
cc=["https://www.w3.org/ns/activitystreams#Public"] cc=["https://www.w3.org/ns/activitystreams#Public"]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment