Skip to content

Commit 19f270e

Browse files
committed
refactor: adjust indentation across project files for consistency and readability
- Standardize alignment in function parameters, method definitions, and docstrings - Correct inconsistent use of spaces in YAML files and Markdown lists - Improve readability and structure throughout backend services, tests, Alembic migrations, and configuration files
1 parent 17fea88 commit 19f270e

26 files changed

+143
-77
lines changed

.github/workflows/test-backend.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Backend Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
services:
15+
postgres:
16+
image: postgres:16
17+
env:
18+
POSTGRES_USER: postgres
19+
POSTGRES_PASSWORD: postgres
20+
POSTGRES_DB: devbin_test
21+
ports:
22+
- 5433:5432
23+
options: >-
24+
--health-cmd "pg_isready -U postgres"
25+
--health-interval 5s
26+
--health-timeout 5s
27+
--health-retries 5
28+
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v4
32+
33+
- name: Set up Python
34+
uses: actions/setup-python@v5
35+
with:
36+
python-version: '3.13'
37+
38+
- name: Install uv
39+
uses: astral-sh/setup-uv@v4
40+
with:
41+
version: "latest"
42+
43+
- name: Install dependencies
44+
run: uv sync --extra test --extra migration
45+
46+
- name: Run tests
47+
env:
48+
APP_DATABASE_URL: postgresql+asyncpg://postgres:postgres@localhost:5433/devbin_test
49+
APP_BASE_FOLDER_PATH: /tmp/devbin_test_files
50+
APP_DEBUG: "true"
51+
APP_CORS_DOMAINS: '["http://test"]'
52+
APP_ALLOW_CORS_WILDCARD: "false"
53+
run: uv run pytest

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,22 @@ APP_RELOAD=true
140140
APP_SQLALCHEMY_ECHO=true
141141
```
142142

143+
### Tests
144+
145+
### Backend Tests
146+
147+
Run tests with:
148+
149+
```bash
150+
cd backend
151+
uv run pytest
152+
```
153+
154+
> If you modified any of the core API endpoints, make sure to run the tests to ensure they still work as expected. Or if
155+
> you are committing breaking changes, please adjust them and add a note why this breaking change is necessary.
156+
157+
See [Testing](/backend/TESTING.md)
158+
143159
### API Endpoints
144160

145161
- `GET /health` – Health check

backend/TESTING.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ uv sync --extra test
1818
```
1919

2020
This will:
21+
2122
- Start PostgreSQL 16 in Docker on port 5433
2223
- Create the `devbin_test` database
2324
- Wait for the database to be ready
@@ -83,10 +84,10 @@ docker-compose -f docker-compose.test.yml logs -f
8384
Tests use environment variables from `pytest.ini` by default:
8485

8586
```ini
86-
APP_DATABASE_URL=postgresql+asyncpg://postgres:postgres@localhost:5433/devbin_test
87-
APP_BASE_FOLDER_PATH=/tmp/devbin_test_files
88-
APP_DEBUG=true
89-
APP_ALLOW_CORS_WILDCARD=true
87+
APP_DATABASE_URL = postgresql+asyncpg://postgres:postgres@localhost:5433/devbin_test
88+
APP_BASE_FOLDER_PATH = /tmp/devbin_test_files
89+
APP_DEBUG = true
90+
APP_ALLOW_CORS_WILDCARD = true
9091
```
9192

9293
You can override these by setting environment variables before running tests:
@@ -172,9 +173,9 @@ open htmlcov/index.html # or xdg-open on Linux
172173

173174
- Overall: 80%+ (enforced in CI)
174175
- Critical modules: 90%+
175-
- `app/services/paste_service.py`
176-
- `app/utils/token_utils.py`
177-
- `app/api/subroutes/pastes.py`
176+
- `app/services/paste_service.py`
177+
- `app/utils/token_utils.py`
178+
- `app/api/subroutes/pastes.py`
178179

179180
## Troubleshooting
180181

@@ -183,6 +184,7 @@ open htmlcov/index.html # or xdg-open on Linux
183184
**Problem**: `connection refused` or `could not connect to server`
184185

185186
**Solution**:
187+
186188
1. Check if test database is running: `docker ps | grep devbin_test`
187189
2. Start database: `./scripts/setup_test_db.sh`
188190
3. Check database logs: `docker-compose -f docker-compose.test.yml logs`
@@ -192,6 +194,7 @@ open htmlcov/index.html # or xdg-open on Linux
192194
**Problem**: Port 5433 is already in use
193195

194196
**Solution**:
197+
195198
1. Change port in `docker-compose.test.yml`
196199
2. Update `pytest.ini` to match
197200
3. Restart database
@@ -201,6 +204,7 @@ open htmlcov/index.html # or xdg-open on Linux
201204
**Problem**: Tests pass sometimes, fail other times (flaky tests)
202205

203206
**Solution**:
207+
204208
1. Check if tests are properly isolated (no shared state)
205209
2. Verify database cleanup between tests
206210
3. Check for timing issues (use `freezegun` for time-based tests)
@@ -210,6 +214,7 @@ open htmlcov/index.html # or xdg-open on Linux
210214
**Problem**: Tests take too long to run
211215

212216
**Solution**:
217+
213218
1. Run tests in parallel: `pytest -n auto`
214219
2. Run only unit tests: `pytest tests/unit/`
215220
3. Run specific test file instead of entire suite
@@ -240,6 +245,7 @@ open htmlcov/index.html # or xdg-open on Linux
240245
## Continuous Integration
241246

242247
Tests run automatically on:
248+
243249
- Push to `master` or `develop`
244250
- Pull requests
245251

backend/Taskfile.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
version: '3'
44

55
tasks:
6+
api:setup_test:
7+
cmds:
8+
- uv sync --extra test
9+
- ./scripts/setup_test_db.sh
610
api:start:
711
env:
812
APP_DEBUG: true
913
cmd: uv run main.py
1014
api:migrate:
1115
cmd: alembic upgrade head
1216
api:downmigrate:
13-
cmd: alembic downgrade -1
17+
cmd: alembic downgrade -1
18+
api:test:
19+
cmd: uv run pytest

backend/alembic/env.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import os
22
from logging.config import fileConfig
33

4+
from alembic import context
45
from sqlalchemy import engine_from_config, pool
56

6-
from alembic import context
7-
from app.db.base import Base
87
from app.db.models import *
98

109
# this is the Alembic Config object, which provides

backend/alembic/versions/08393764144d_add_delete_edit_tokens_and_deleted_at.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
"""
88
from typing import Sequence, Union
99

10-
from alembic import op
1110
import sqlalchemy as sa
12-
11+
from alembic import op
1312

1413
# revision identifiers, used by Alembic.
1514
revision: str = '08393764144d'

backend/alembic/versions/7c45e2617d61_updated_created_at_and_expires_at_types.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
from typing import Sequence, Union
1010

1111
import sqlalchemy as sa
12-
from sqlalchemy.dialects import postgresql
13-
1412
from alembic import op
13+
from sqlalchemy.dialects import postgresql
1514

1615
# revision identifiers, used by Alembic.
1716
revision: str = "7c45e2617d61"

backend/alembic/versions/9e8ceaeba260_initial_migration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"""
88
from typing import Sequence, Union
99

10-
from alembic import op
1110
import sqlalchemy as sa
11+
from alembic import op
1212

1313
# revision identifiers, used by Alembic.
1414
revision: str = '9e8ceaeba260'

backend/app/api/dto/paste_dto.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from datetime import datetime, timezone
22
from enum import Enum
3-
from uuid import UUID
43

54
from pydantic import UUID4, BaseModel, Field, field_validator
65

backend/app/api/middlewares.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212

1313
class UserMetadataMiddleware(BaseHTTPMiddleware):
1414
def get_ip_address(
15-
self, request: Request
15+
self, request: Request
1616
) -> ipaddress.IPv4Address | ipaddress.IPv6Address | Literal["unknown"]:
1717
# Try X-Forwarded-For first (proxy headers)
1818
forwarded = request.headers.get("X-Forwarded-For")
1919
ip = "unknown"
2020

2121
if (
22-
forwarded
23-
and request.client
24-
and request.client.host
25-
and request.client.host in config.TRUSTED_HOSTS
22+
forwarded
23+
and request.client
24+
and request.client.host
25+
and request.client.host in config.TRUSTED_HOSTS
2626
):
2727
# Get first IP in the list (original client)
2828
split_ip = forwarded.split(",")[0].strip()
@@ -121,8 +121,8 @@ async def dispatch(self, request: Request, call_next):
121121
# Check if request came over HTTPS
122122
# Note: In production behind proxy, check X-Forwarded-Proto header
123123
is_https = (
124-
request.url.scheme == "https"
125-
or request.headers.get("X-Forwarded-Proto") == "https"
124+
request.url.scheme == "https"
125+
or request.headers.get("X-Forwarded-Proto") == "https"
126126
)
127127

128128
if is_https:
@@ -145,8 +145,8 @@ class HTTPSRedirectMiddleware(BaseHTTPMiddleware):
145145
async def dispatch(self, request: Request, call_next):
146146
# Check if request is over HTTPS
147147
is_https = (
148-
request.url.scheme == "https"
149-
or request.headers.get("X-Forwarded-Proto") == "https"
148+
request.url.scheme == "https"
149+
or request.headers.get("X-Forwarded-Proto") == "https"
150150
)
151151

152152
if not is_https:

0 commit comments

Comments
 (0)