Skip to content

Commit 2abaf50

Browse files
committed
feat: wip
1 parent 22b06ad commit 2abaf50

31 files changed

Lines changed: 836 additions & 200 deletions

File tree

.github/workflows/test.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: ["**"]
6+
pull_request:
7+
branches: ["**"]
8+
9+
jobs:
10+
pytest:
11+
name: Pytest
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Install uv
17+
uses: astral-sh/setup-uv@v5
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: "3.12"
23+
24+
- name: Install dependencies
25+
working-directory: example/config-app
26+
run: uv sync
27+
28+
- name: Run tests
29+
working-directory: example/config-app
30+
run: uv run pytest tests/ -v

example/config-app/.env.production

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
REDIS_HOST=host.production
2+
REDIS_PORT=1111
3+
REDIS_DB=1

example/config-app/.env.testing

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
REDIS_HOST=host.testing
2+
REDIS_PORT=2222
3+
REDIS_DB=2

example/config-app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.venv

example/config-app/artisan

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env python3
2+
3+
import sys
4+
from bootstrap.application import app
5+
6+
if __name__ == "__main__":
7+
status = app.handle_command()
8+
sys.exit(status if isinstance(status, int) else 0)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from pathlib import Path
2+
3+
from fastapi_startkit import Application
4+
5+
app: Application = Application(
6+
base_path=Path(__file__).parent.parent,
7+
)

example/config-app/config/redis.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from dataclasses import dataclass, field
2+
3+
from fastapi_startkit.environment import env
4+
5+
6+
@dataclass
7+
class RedisConfig:
8+
host: str = field(default_factory=lambda: env('REDIS_HOST'))
9+
port: int = field(default_factory=lambda: env('REDIS_PORT'))
10+
db: int = field(default_factory=lambda: env('REDIS_DB'))
11+
12+
options: dict = field(default_factory=lambda: {
13+
'decode_responses': True
14+
})

example/config-app/pyproject.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[project]
2+
name = "console-app"
3+
version = "0.1.0"
4+
description = "A simple application to demonstrate the console application."
5+
readme = "README.md"
6+
requires-python = ">=3.13"
7+
dependencies = [
8+
"fastapi-startkit",
9+
]
10+
11+
[tool.uv.sources]
12+
fastapi-startkit = { path = "../../fastapi_startkit", editable=true }
13+
14+
[dependency-groups]
15+
dev = [
16+
"dumpdie>=1.5.0",
17+
"pytest>=8.0.0",
18+
]
19+
20+
[tool.pytest.ini_options]
21+
pythonpath = ["."]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
import unittest
3+
4+
from config.redis import RedisConfig
5+
6+
7+
class TestCase(unittest.TestCase):
8+
def setUp(self):
9+
os.environ.pop('PYTEST_CURRENT_TEST', None)
10+
from bootstrap.application import app
11+
self.app = app
12+
13+
def test_app_loads_env_data(self):
14+
self.assertEqual(RedisConfig().host, "host.default")
15+
self.assertEqual(RedisConfig().port, 0000)
16+
self.assertEqual(RedisConfig().db, 0)
17+
18+
self.app.set_environment('testing')
19+
self.app.load_environment()
20+
self.assertEqual(RedisConfig().host, "host.testing")
21+
self.assertEqual(RedisConfig().port, 2222)
22+
self.assertEqual(RedisConfig().db, 2)
23+
24+
self.app.set_environment('production')
25+
self.app.load_environment()
26+
27+
self.assertEqual(RedisConfig().host, "host.production")
28+
self.assertEqual(RedisConfig().port, 1111)
29+
self.assertEqual(RedisConfig().db, 1)

example/config-app/uv.lock

Lines changed: 512 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)