Skip to content

Commit 77d951d

Browse files
tmgbeduclaude
andcommitted
style: apply ruff formatting to tests/ and add format check to bin/test.sh
Format 25 test files that were missed in the initial formatting pass. Also add `ruff format --check` alongside `ruff check` in bin/test.sh so CI catches both lint and formatting violations. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 8f2ed9e commit 77d951d

26 files changed

Lines changed: 149 additions & 216 deletions

bin/test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
77
echo "============================================================"
88
echo " Running: ruff lint checks"
99
echo "============================================================"
10+
(cd "$ROOT/fastapi_startkit" && uv run ruff format --check src/ tests/)
1011
(cd "$ROOT/fastapi_startkit" && uv run ruff check src/ tests/)
1112

1213
# ── Start MySQL via Docker Compose ────────────────────────────────────────────

fastapi_startkit/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
@pytest.fixture(scope="session", autouse=True)
66
def init_app():
7-
Application(env="testing")
7+
Application(env="testing")

fastapi_startkit/tests/inertia/test_inertia.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import unittest
22
from fastapi_startkit.inertia.inertia import Inertia, ResponseFactory, InertiaResponse
33

4+
45
class TestInertia(unittest.TestCase):
56
def setUp(self):
67
# Reset the singleton instance before each test
@@ -31,7 +32,7 @@ def test_factory_render_returns_response(self):
3132
factory = ResponseFactory()
3233
factory.share("auth", {"user": None})
3334
response = factory.render("Dashboard", {"count": 10})
34-
35+
3536
self.assertIsInstance(response, InertiaResponse)
3637
self.assertEqual(response.component, "Dashboard")
3738
self.assertEqual(response.props, {"count": 10})
@@ -45,9 +46,9 @@ def test_facade_singleton(self):
4546
def test_facade_proxies_to_instance(self):
4647
Inertia.share("foo", "bar")
4748
self.assertEqual(Inertia.instance().shared_props["foo"], "bar")
48-
49+
4950
Inertia.version("v1")
5051
self.assertEqual(Inertia.get_version(), "v1")
51-
52+
5253
Inertia.set_root_view("app.html")
5354
self.assertEqual(Inertia.instance().root_view, "app.html")

fastapi_startkit/tests/inertia/test_inertia_response.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from fastapi_startkit.inertia.inertia import InertiaResponse, OptionalProp
66
from fastapi_startkit.inertia.constant import Header
77

8+
89
class TestInertiaResponse(unittest.IsolatedAsyncioTestCase):
910
def setUp(self):
1011
self.mock_request = MagicMock(spec=Request)
@@ -13,19 +14,16 @@ def setUp(self):
1314

1415
async def test_inertia_response_to_json_on_inertia_request(self):
1516
self.mock_request.headers = {Header.INERTIA: "true"}
16-
17+
1718
response = InertiaResponse(
18-
component="User/Index",
19-
shared_props={"app": "Test"},
20-
props={"users": []},
21-
version="v1"
19+
component="User/Index", shared_props={"app": "Test"}, props={"users": []}, version="v1"
2220
)
23-
21+
2422
actual_response = await response.to_response(self.mock_request)
25-
23+
2624
self.assertEqual(actual_response.status_code, 200)
2725
self.assertEqual(actual_response.headers[Header.INERTIA], "true")
28-
26+
2927
content = json.loads(actual_response.body)
3028
self.assertEqual(content["component"], "User/Index")
3129
self.assertEqual(content["props"], {"app": "Test", "users": []})
@@ -36,18 +34,18 @@ async def test_inertia_response_partial_reload(self):
3634
self.mock_request.headers = {
3735
Header.INERTIA: "true",
3836
Header.INERTIA_PARTIAL_COMPONENT: "User/Index",
39-
"X-Inertia-Partial-Data": "users"
37+
"X-Inertia-Partial-Data": "users",
4038
}
41-
39+
4240
response = InertiaResponse(
4341
component="User/Index",
4442
shared_props={"app": "Test"},
4543
props={"users": ["user1"], "stats": {"likes": 10}},
4644
)
47-
45+
4846
actual_response = await response.to_response(self.mock_request)
4947
data = json.loads(actual_response.body)
50-
48+
5149
# Should only include "users", exclude "app" and "stats"
5250
self.assertIn("users", data["props"])
5351
self.assertNotIn("app", data["props"])
@@ -56,8 +54,9 @@ async def test_inertia_response_partial_reload(self):
5654
async def test_inertia_response_optional_props(self):
5755
# 1. Normal request - optional prop should be excluded
5856
self.mock_request.headers = {Header.INERTIA: "true"}
59-
57+
6058
lazy_called = False
59+
6160
def get_lazy():
6261
nonlocal lazy_called
6362
lazy_called = True
@@ -68,7 +67,7 @@ def get_lazy():
6867
shared_props={},
6968
props={"regular": "data", "lazy": OptionalProp(get_lazy)},
7069
)
71-
70+
7271
actual_response = await response.to_response(self.mock_request)
7372
data = json.loads(actual_response.body)
7473
self.assertEqual(data["props"], {"regular": "data"})
@@ -78,17 +77,17 @@ def get_lazy():
7877
self.mock_request.headers = {
7978
Header.INERTIA: "true",
8079
Header.INERTIA_PARTIAL_COMPONENT: "User/Index",
81-
"X-Inertia-Partial-Data": "lazy"
80+
"X-Inertia-Partial-Data": "lazy",
8281
}
83-
82+
8483
actual_response = await response.to_response(self.mock_request)
8584
data = json.loads(actual_response.body)
8685
self.assertEqual(data["props"], {"lazy": "lazy data"})
8786
self.assertTrue(lazy_called)
8887

8988
async def test_inertia_response_resolves_callable_props(self):
9089
self.mock_request.headers = {Header.INERTIA: "true"}
91-
90+
9291
async def get_async_data():
9392
return "async result"
9493

@@ -97,7 +96,7 @@ async def get_async_data():
9796
shared_props={"sync": lambda: "sync result"},
9897
props={"async": get_async_data},
9998
)
100-
99+
101100
actual_response = await response.to_response(self.mock_request)
102101
data = json.loads(actual_response.body)
103102
self.assertEqual(data["props"]["sync"], "sync result")
@@ -106,9 +105,9 @@ async def get_async_data():
106105
async def test_inertia_response_initial_render_raises_if_no_templates(self):
107106
# Standard request (no X-Inertia header)
108107
self.mock_request.headers = {}
109-
108+
110109
response = InertiaResponse(component="Test", shared_props={}, props={})
111-
110+
112111
# This should fail because we haven't mocked the application container
113112
with self.assertRaisesRegex(RuntimeError, "Inertia requires 'templates' to be bound"):
114113
await response.to_response(self.mock_request)

fastapi_startkit/tests/inertia/test_middleware.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,32 @@
66
from fastapi_startkit.inertia.constant import Header
77
from fastapi_startkit.inertia.inertia import Inertia
88

9+
910
class TestInertiaMiddleware(unittest.IsolatedAsyncioTestCase):
1011
def setUp(self):
1112
self.app = FastAPI()
1213
self.app.add_middleware(InertiaMiddleware)
13-
14+
1415
@self.app.get("/test")
1516
async def test_route():
1617
return {"message": "ok"}
17-
18+
1819
@self.app.post("/redirect")
1920
async def test_redirect():
2021
from fastapi.responses import RedirectResponse
22+
2123
return RedirectResponse(url="/test", status_code=302)
2224

2325
@self.app.put("/redirect-put")
2426
async def test_redirect_put():
2527
from fastapi.responses import RedirectResponse
28+
2629
return RedirectResponse(url="/test", status_code=302)
2730

2831
@self.app.get("/fragment-redirect")
2932
async def test_fragment_redirect():
3033
from fastapi.responses import RedirectResponse
34+
3135
return RedirectResponse(url="/test#section", status_code=302)
3236

3337
self.client = TestClient(self.app)
@@ -43,34 +47,31 @@ def test_middleware_version_conflict(self, mock_app_getter):
4347
# Setup mock container
4448
mock_container = MagicMock()
4549
mock_app_getter.return_value = mock_container
46-
50+
4751
# Mock Vite version
4852
mock_vite = MagicMock()
4953
mock_vite.manifest_hash.return_value = "v2"
5054
mock_container.has.side_effect = lambda k: k == "vite"
5155
mock_container.make.side_effect = lambda k: mock_vite if k == "vite" else None
52-
56+
5357
# Request with old version
54-
response = self.client.get("/test", headers={
55-
Header.INERTIA: "true",
56-
Header.INERTIA_VERSION: "v1"
57-
})
58-
58+
response = self.client.get("/test", headers={Header.INERTIA: "true", Header.INERTIA_VERSION: "v1"})
59+
5960
self.assertEqual(response.status_code, 409)
6061
self.assertEqual(response.headers[Header.INERTIA_LOCATION], "http://testserver/test")
6162

6263
def test_middleware_changes_302_to_303_on_put_patch_delete(self):
6364
# POST stays 302
6465
response = self.client.post("/redirect", follow_redirects=False)
6566
self.assertEqual(response.status_code, 302)
66-
67+
6768
# PUT changes to 303
6869
response = self.client.put("/redirect-put", follow_redirects=False, headers={Header.INERTIA: "true"})
6970
self.assertEqual(response.status_code, 303)
7071

7172
def test_middleware_redirect_with_fragment(self):
7273
response = self.client.get("/fragment-redirect", headers={Header.INERTIA: "true"})
73-
74+
7475
self.assertEqual(response.status_code, 409)
7576
self.assertEqual(response.headers[Header.INERTIA_REDIRECT], "/test#section")
7677

@@ -79,16 +80,16 @@ def test_middleware_resolves_validation_errors_from_session(self, mock_app_gette
7980
# We need a fresh app and session-enabled middleware
8081
from fastapi import Request
8182
from starlette.middleware.sessions import SessionMiddleware
82-
83+
8384
app = FastAPI()
8485
app.add_middleware(InertiaMiddleware)
8586
app.add_middleware(SessionMiddleware, secret_key="secret")
86-
87+
8788
@app.get("/set-errors")
8889
def set_errors(request: Request):
8990
request.session["errors"] = {"email": "Required"}
9091
return "ok"
91-
92+
9293
@app.get("/check-errors")
9394
def check_errors(request: Request):
9495
# Middleware should have shared the errors from the session
@@ -99,15 +100,15 @@ def check_errors(request: Request):
99100
mock_container = MagicMock()
100101
mock_app_getter.return_value = mock_container
101102
mock_container.has.return_value = False
102-
103+
103104
client = TestClient(app)
104-
105+
105106
# Reset Inertia singleton for this specific test
106107
Inertia._instance = None
107108

108109
# 1. First request sets the errors in session
109110
client.get("/set-errors")
110-
111+
111112
# 2. Second request should have errors shared by middleware
112113
response = client.get("/check-errors")
113114
self.assertEqual(response.json(), {"email": "Required"})

fastapi_startkit/tests/masoniteorm/collection/test_collection.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,7 @@ def test_count(self):
240240
collection = Collection([1, 1, 2, 4])
241241
self.assertEqual(collection.count(), 4)
242242

243-
collection = Collection(
244-
[{"name": "Corentin All", "age": 1}, {"name": "Corentin All", "age": 2}]
245-
)
243+
collection = Collection([{"name": "Corentin All", "age": 1}, {"name": "Corentin All", "age": 2}])
246244
self.assertEqual(collection.count(), 2)
247245

248246
def test_chunk(self):
@@ -364,9 +362,7 @@ def test_reject(self):
364362
collection.reject(lambda x: x if x["age"] > 2 else None)
365363

366364
self.assertEqual(
367-
Collection(
368-
[{"name": "Corentin All", "age": 3}, {"name": "Corentin All", "age": 4}]
369-
),
365+
Collection([{"name": "Corentin All", "age": 3}, {"name": "Corentin All", "age": 4}]),
370366
collection.all(),
371367
)
372368

@@ -507,9 +503,7 @@ def test_implode(self):
507503
result = collection.implode("-")
508504
self.assertEqual(result, "1-2-3-4")
509505

510-
collection = Collection(
511-
[{"name": "Corentin"}, {"name": "Joe"}, {"name": "Marlysson"}]
512-
)
506+
collection = Collection([{"name": "Corentin"}, {"name": "Joe"}, {"name": "Marlysson"}])
513507
result = collection.implode(key="name")
514508
self.assertEqual(result, "Corentin,Joe,Marlysson")
515509

@@ -524,9 +518,7 @@ def __eq__(self, other):
524518
return self.code == other.code
525519

526520
currencies = collection.map_into(Currency)
527-
self.assertEqual(
528-
currencies.all(), [Currency("USD"), Currency("EUR"), Currency("GBP")]
529-
)
521+
self.assertEqual(currencies.all(), [Currency("USD"), Currency("EUR"), Currency("GBP")])
530522

531523
def test_map(self):
532524
collection = Collection([1, 2, 3, 4])

fastapi_startkit/tests/masoniteorm/commands/fixtures/app.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@ def create_app() -> Application:
1212
return Application(
1313
base_path=BASE_DIR,
1414
providers=[
15-
(DatabaseProvider, {
16-
"default": "sqlite",
17-
"connections": {
18-
"sqlite": SQLiteConfig(
19-
driver="sqlite",
20-
url=f"sqlite+aiosqlite:///{DB_PATH}",
21-
options=None,
22-
),
23-
}
24-
}),
15+
(
16+
DatabaseProvider,
17+
{
18+
"default": "sqlite",
19+
"connections": {
20+
"sqlite": SQLiteConfig(
21+
driver="sqlite",
22+
url=f"sqlite+aiosqlite:///{DB_PATH}",
23+
options=None,
24+
),
25+
},
26+
},
27+
),
2528
],
2629
)

fastapi_startkit/tests/masoniteorm/commands/fixtures/databases/migrations/2026_01_01_000001_add_body_to_posts_table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ async def up(self):
88

99
async def down(self):
1010
async with await self.schema.table("posts") as table:
11-
table.drop_column("body")
11+
table.drop_column("body")

fastapi_startkit/tests/masoniteorm/commands/test_shell.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,7 @@ def test_for_mssql(self):
6363
"full_details": {"driver": "mssql"},
6464
}
6565
command, _ = self.command.get_command(config)
66-
assert (
67-
command
68-
== "sqlcmd -d orm -U root -P secretpostgres -S tcp:db.masonite.com,1234"
69-
)
66+
assert command == "sqlcmd -d orm -U root -P secretpostgres -S tcp:db.masonite.com,1234"
7067

7168
@skip("ShellCommand.handle() uses legacy load_config() not available in new framework")
7269
def test_running_command_with_sqlite(self):
@@ -86,6 +83,4 @@ def test_hiding_sensitive_options(self):
8683
}
8784
command, _ = self.command.get_command(config)
8885
cleaned_command = self.command.hide_sensitive_options(config, command)
89-
assert (
90-
cleaned_command == "mysql orm --host localhost --user root --password ***"
91-
)
86+
assert cleaned_command == "mysql orm --host localhost --user root --password ***"

fastapi_startkit/tests/masoniteorm/configurations/test_config_merge.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ def test_merge_with_file_path(self):
3434
config.set("testkey", {"existing": "orig"})
3535

3636
# Mock Loader to return params from file
37-
with patch(
38-
"fastapi_startkit.configuration.Configuration.Loader"
39-
) as MockLoaderClass:
37+
with patch("fastapi_startkit.configuration.Configuration.Loader") as MockLoaderClass:
4038
mock_loader = MockLoaderClass.return_value
4139
mock_loader.get_parameters.return_value = {
4240
"New": "from_file",

0 commit comments

Comments
 (0)