Skip to content
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

Feature/user registration #85

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
838cf75
docs(contributing): add testing and database workflow documentation
gsinghjay Jan 3, 2025
f1c9e3b
fix(tests): disable rate limiting during tests
gsinghjay Jan 3, 2025
7643bd0
chore(ci): temporarily disable mypy in pre-commit
gsinghjay Jan 3, 2025
1312926
feat(tests): add PostgreSQL test configuration
gsinghjay Jan 3, 2025
7d96b67
test(db): update test database configuration
gsinghjay Jan 3, 2025
1479cda
chore: poetry.lock
gsinghjay Jan 3, 2025
5bc1464
fix(api): correct rate limiter import
gsinghjay Jan 3, 2025
bebc837
chore: add type hints and enable mypy
gsinghjay Jan 3, 2025
d1249de
feat(testing): add test infrastructure and configuration
gsinghjay Jan 3, 2025
c6803e9
docs(testing): add comprehensive testing guide
gsinghjay Jan 3, 2025
8baf434
feat(testing): implement test database fixtures
gsinghjay Jan 3, 2025
1a99442
test(auth): add authentication and user registration tests
gsinghjay Jan 3, 2025
a39583c
docs: update documentation with new standards and patterns
gsinghjay Jan 3, 2025
e54499f
feat(middleware): implement rate limiting with FastAPI best practices
gsinghjay Jan 3, 2025
206d503
feat(db): add PostgreSQL configuration and migrations
gsinghjay Jan 3, 2025
e20ad00
feat(auth): add core authentication and schema validation
gsinghjay Jan 3, 2025
7bcc63e
feat(auth): implement user service with Protocol pattern
gsinghjay Jan 3, 2025
ca99381
chore(config): update project configuration and dependencies
gsinghjay Jan 3, 2025
976a4e6
fix(merge): resolve conflicts in user router and contributing docs
gsinghjay Jan 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[run]
source = app
omit =
tests/*
*/__init__.py

[report]
exclude_lines =
pragma: no cover
def __repr__
raise NotImplementedError
if __name__ == .__main__.:
pass
raise ImportError
23 changes: 23 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# PostgreSQL Configuration
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=test_db
POSTGRES_HOST=test-db
POSTGRES_PORT=5432
POSTGRES_EXTENSIONS=uuid-ossp,pgcrypto

# PostgreSQL Performance Tuning
POSTGRES_MAX_CONNECTIONS=1000
POSTGRES_SHARED_BUFFERS=128MB
POSTGRES_FSYNC=off
POSTGRES_SYNCHRONOUS_COMMIT=off
POSTGRES_FULL_PAGE_WRITES=off

# Application Settings
PYTHONPATH=/app
PYTHONUNBUFFERED=1
TESTING=1

# Coverage Settings
COVERAGE_FILE=/app/coverage/.coverage
COVERAGE_REPORT_HTML=/app/coverage/html/
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ htmlcov/
coverage.xml
.coverage.*
coverage/
test-results/

# Logs
*.log
Expand All @@ -55,3 +56,8 @@ __pycache__/
*.db
*.sqlite
*.sqlite3

# Environment variables
.env
.env.*
!.env.example
20 changes: 20 additions & 0 deletions .mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[mypy]
python_version = 3.11
disallow_untyped_defs = false
disallow_incomplete_defs = false
check_untyped_defs = true
disallow_untyped_decorators = false
no_implicit_optional = true
warn_redundant_casts = true
warn_unused_ignores = true
warn_return_any = false
warn_unreachable = true
strict_optional = true
plugins = pydantic.mypy
ignore_missing_imports = true

[mypy.plugins.pydantic.*]
init_forbid_extra = true
init_typed = true
warn_required_dynamic_aliases = true
warn_untyped_fields = true
17 changes: 4 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@ repos:
rev: 24.1.0
hooks:
- id: black
language_version: python3.11
language_version: python3.10

- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
additional_dependencies:
- flake8-docstrings
- flake8-bugbear
- flake8-comprehensions
- flake8-simplify
additional_dependencies: [flake8-docstrings]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
Expand All @@ -25,13 +21,8 @@ repos:
- types-requests
- types-setuptools
- pydantic
args: [--config-file=pyproject.toml]

- repo: https://github.com/commitizen-tools/commitizen
rev: v3.13.0
hooks:
- id: commitizen
stages: [commit-msg]
- slowapi
args: [--config-file=.mypy.ini]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
Expand Down
156 changes: 59 additions & 97 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Thank you for your interest in contributing to our project! This document provid
2. Poetry (for dependency management)
3. Node.js (for commit linting)
4. Git
5. PostgreSQL 14

### Initial Setup

Expand All @@ -22,13 +23,21 @@ Thank you for your interest in contributing to our project! This document provid
2. **Install Dependencies**
```bash
# Install Poetry
pip install poetry==1.8.5
curl -sSL https://install.python-poetry.org | python3 -

# Install project dependencies
poetry install

# Install commit linting tools
npm install

# Install PostgreSQL (required for tests)
# For Ubuntu/Debian:
sudo apt-get update && sudo apt-get install -y postgresql-14 postgresql-server-dev-14
# For macOS:
brew install postgresql@14
# For Windows:
# Download and install from https://www.postgresql.org/download/windows/
```

3. **Set up Pre-commit Hooks**
Expand Down Expand Up @@ -57,6 +66,7 @@ We use several tools to maintain code quality:

3. **MyPy** - Static Type Checking
- Configuration in `pyproject.toml`
- Strict type checking enabled
- Type stub dependencies included
- Pydantic plugin enabled
- Run with: `poetry run mypy`
Expand Down Expand Up @@ -89,7 +99,7 @@ We use several tools to maintain code quality:
poetry run pre-commit run --all-files

# Run tests
poetry run pytest
poetry run pytest -v
```

3. **Commit Changes**
Expand Down Expand Up @@ -134,94 +144,38 @@ We use several tools to maintain code quality:

## 🔍 CI/CD Pipeline

Our CI/CD pipeline automates testing, linting, and release processes. Here's a visual representation of our workflow:

```mermaid
flowchart TD
subgraph "CI/CD Pipeline"
A[Push/PR] --> B{Event Type?}

B --> |PR/Push| C[Setup Python]
C --> D[Install Dependencies]
D --> E[Cache Environment]

E --> F[Lint Check]
E --> G[Test]

F & G --> H{All Checks Pass?}

H -->|No| I[Report Failure]
H -->|Yes & PR| J[Ready for Review]
H -->|Yes & Push to Main| K[Semantic Release]

K --> L[Generate Changelog]
L --> M[Create Release]
M --> N[Publish Assets]

subgraph "Skip Release Conditions"
S1[Skip if]
S2[Commit by github-actions]
S3["Message contains 'skip ci'"]
S4["Message has 'chore(release)'"]
S1 --> S2 & S3 & S4
end
end

classDef trigger fill:#90EE90
classDef setup fill:#FFE4B5
classDef check fill:#FFB6C1
classDef release fill:#ADD8E6
classDef skip fill:#D3D3D3

class A trigger
class C,D,E setup
class F,G,H check
class K,L,M,N release
class S1,S2,S3,S4 skip
```

### Workflow Details

1. **CI Pipeline** (`ci.yml`)
- Orchestrates the entire CI/CD process
- Triggers on pull requests and pushes to main branch
- Coordinates setup, lint, test, and release jobs
- Handles release automation when all checks pass on main branch
- Uses semantic versioning for releases

2. **Setup Environment** (`setup-python.yml`)
- Sets up Python 3.11 environment
- Installs and configures Poetry
- Installs project dependencies
- Creates and caches virtual environment
- Produces a reusable artifact for other workflows

3. **Lint Check** (`lint.yml`)
- Downloads virtual environment artifact
- Runs Black code formatter in check mode
- Validates commit messages using commitlint
- Ensures code style consistency
- Requires GitHub token for PR access

4. **Test Suite** (`test.yml`)
- Downloads virtual environment artifact
- Executes pytest test suite
- Generates code coverage report
- Reports test results
- Writes test results to GitHub Checks

5. **Release Process** (part of `ci.yml`)
- Only runs on main branch after successful checks
- Uses Python Semantic Release
- Creates new version based on commit messages
- Updates CHANGELOG.md
- Creates GitHub release with assets
Our CI/CD pipeline automates testing, linting, and release processes. Here's what happens when you create a PR:

1. **Setup Environment**
- Python 3.11 environment is created
- Poetry and dependencies are installed
- PostgreSQL service is started
- Virtual environment is cached

2. **Quality Checks**
- Black code formatting
- Flake8 style checks
- MyPy type checking
- Pre-commit hooks validation

3. **Testing**
- PostgreSQL database is initialized
- Pytest runs all tests
- Coverage report is generated
- Test results are reported

4. **Release Process** (on main branch)
- Semantic version is determined
- Changelog is updated
- Release is created
- Assets are published

## 📝 Code Style Guidelines

1. **Python Code**
- Follow PEP 8 guidelines
- Use Black for formatting
- Include type hints for all functions
- Include docstrings for public functions/classes
- Maximum line length: 88 characters (Black default)

Expand All @@ -243,10 +197,11 @@ When filing a bug report, please include:

1. Python version
2. Operating system
3. Steps to reproduce
4. Expected vs actual behavior
5. Relevant logs/screenshots
6. Possible fixes (if any)
3. PostgreSQL version
4. Steps to reproduce
5. Expected vs actual behavior
6. Relevant logs/screenshots
7. Possible fixes (if any)

## 🚀 Feature Requests

Expand All @@ -264,6 +219,7 @@ When proposing new features:
- [Poetry Documentation](https://python-poetry.org/docs/)
- [Conventional Commits](https://www.conventionalcommits.org/)
- [Keep a Changelog](https://keepachangelog.com/)
- [pytest-postgresql Documentation](https://pytest-postgresql.readthedocs.io/)

## ⚖️ License

Expand All @@ -274,9 +230,9 @@ By contributing, you agree that your contributions will be licensed under the MI
1. **Unit Tests**
- API endpoint tests
- Database integration tests
- In-memory SQLite for test isolation
- PostgreSQL for test isolation
```bash
poetry run pytest
poetry run pytest -v
```

2. **Test Coverage**
Expand All @@ -286,10 +242,11 @@ By contributing, you agree that your contributions will be licensed under the MI
- Password validation
- Email format validation
- QR code generation tests
- Rate limiting tests
- Health check endpoint tests

3. **Database Testing**
- Tests use in-memory SQLite
- Tests use pytest-postgresql
- Each test gets fresh database
- Automatic cleanup after tests
- Transaction rollback support
Expand All @@ -299,26 +256,31 @@ By contributing, you agree that your contributions will be licensed under the MI
- Request validation testing
- Response schema validation
- Error handling verification
- Rate limit verification

### Database Workflow

1. **Development Database**
```bash
# SQLite database is created automatically at:
./test.db
# PostgreSQL connection settings
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=app
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
```

2. **Test Database**
```bash
# In-memory SQLite is used for tests
# No setup required - handled automatically by pytest
# pytest-postgresql handles test database automatically
# Configuration in pyproject.toml
```

3. **Database Migrations**
- Models defined in `app/models/`
- Tables created automatically on startup
- Development uses SQLite
- Production should use PostgreSQL
- Development uses PostgreSQL
- Tests use pytest-postgresql

4. **Best Practices**
- Use SQLAlchemy 2.0 style
Expand Down
Loading
Loading