django-bolt 0.1.0__cp310-abi3-win_amd64.whl → 0.1.2__cp310-abi3-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of django-bolt might be problematic. Click here for more details.
- django_bolt/__init__.py +2 -2
- django_bolt/_core.pyd +0 -0
- django_bolt/_json.py +169 -0
- django_bolt/admin/static_routes.py +15 -21
- django_bolt/api.py +181 -61
- django_bolt/auth/__init__.py +2 -2
- django_bolt/decorators.py +15 -3
- django_bolt/dependencies.py +30 -24
- django_bolt/error_handlers.py +2 -1
- django_bolt/openapi/plugins.py +3 -2
- django_bolt/openapi/schema_generator.py +65 -20
- django_bolt/pagination.py +2 -1
- django_bolt/responses.py +3 -2
- django_bolt/serialization.py +5 -4
- {django_bolt-0.1.0.dist-info → django_bolt-0.1.2.dist-info}/METADATA +181 -201
- {django_bolt-0.1.0.dist-info → django_bolt-0.1.2.dist-info}/RECORD +18 -55
- django_bolt/auth/README.md +0 -464
- django_bolt/auth/REVOCATION_EXAMPLE.md +0 -391
- django_bolt/tests/__init__.py +0 -0
- django_bolt/tests/admin_tests/__init__.py +0 -1
- django_bolt/tests/admin_tests/conftest.py +0 -6
- django_bolt/tests/admin_tests/test_admin_with_django.py +0 -278
- django_bolt/tests/admin_tests/urls.py +0 -9
- django_bolt/tests/cbv/__init__.py +0 -0
- django_bolt/tests/cbv/test_class_views.py +0 -570
- django_bolt/tests/cbv/test_class_views_django_orm.py +0 -703
- django_bolt/tests/cbv/test_class_views_features.py +0 -1173
- django_bolt/tests/cbv/test_class_views_with_client.py +0 -622
- django_bolt/tests/conftest.py +0 -165
- django_bolt/tests/test_action_decorator.py +0 -399
- django_bolt/tests/test_auth_secret_key.py +0 -83
- django_bolt/tests/test_decorator_syntax.py +0 -159
- django_bolt/tests/test_error_handling.py +0 -481
- django_bolt/tests/test_file_response.py +0 -192
- django_bolt/tests/test_global_cors.py +0 -172
- django_bolt/tests/test_guards_auth.py +0 -441
- django_bolt/tests/test_guards_integration.py +0 -303
- django_bolt/tests/test_health.py +0 -283
- django_bolt/tests/test_integration_validation.py +0 -400
- django_bolt/tests/test_json_validation.py +0 -536
- django_bolt/tests/test_jwt_auth.py +0 -327
- django_bolt/tests/test_jwt_token.py +0 -458
- django_bolt/tests/test_logging.py +0 -837
- django_bolt/tests/test_logging_merge.py +0 -419
- django_bolt/tests/test_middleware.py +0 -492
- django_bolt/tests/test_middleware_server.py +0 -230
- django_bolt/tests/test_model_viewset.py +0 -323
- django_bolt/tests/test_models.py +0 -24
- django_bolt/tests/test_pagination.py +0 -1258
- django_bolt/tests/test_parameter_validation.py +0 -178
- django_bolt/tests/test_syntax.py +0 -626
- django_bolt/tests/test_testing_utilities.py +0 -163
- django_bolt/tests/test_testing_utilities_simple.py +0 -123
- django_bolt/tests/test_viewset_unified.py +0 -346
- {django_bolt-0.1.0.dist-info → django_bolt-0.1.2.dist-info}/WHEEL +0 -0
- {django_bolt-0.1.0.dist-info → django_bolt-0.1.2.dist-info}/entry_points.txt +0 -0
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Test parameter validation and inference system.
|
|
3
|
-
"""
|
|
4
|
-
import pytest
|
|
5
|
-
import msgspec
|
|
6
|
-
from django_bolt import BoltAPI
|
|
7
|
-
from django_bolt.params import Query, Body
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class UserCreate(msgspec.Struct):
|
|
11
|
-
name: str
|
|
12
|
-
email: str
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def test_get_with_body_param_raises_error():
|
|
16
|
-
"""Test that GET endpoints with body parameters raise TypeError."""
|
|
17
|
-
api = BoltAPI()
|
|
18
|
-
|
|
19
|
-
with pytest.raises(TypeError) as exc_info:
|
|
20
|
-
@api.get("/users")
|
|
21
|
-
async def create_user(user: UserCreate):
|
|
22
|
-
return {"id": 1}
|
|
23
|
-
|
|
24
|
-
error_msg = str(exc_info.value)
|
|
25
|
-
assert "GET /users cannot have body parameters" in error_msg
|
|
26
|
-
assert "user" in error_msg
|
|
27
|
-
assert "Change HTTP method to POST/PUT/PATCH" in error_msg
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
def test_head_with_body_param_raises_error():
|
|
31
|
-
"""Test that HEAD endpoints cannot have body parameters."""
|
|
32
|
-
# Note: BoltAPI doesn't have @api.head() decorator yet, but we test the principle
|
|
33
|
-
# This would be the expected behavior if we add HEAD support
|
|
34
|
-
pass
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def test_delete_with_body_param_raises_error():
|
|
38
|
-
"""Test that DELETE endpoints with body parameters raise TypeError."""
|
|
39
|
-
api = BoltAPI()
|
|
40
|
-
|
|
41
|
-
with pytest.raises(TypeError) as exc_info:
|
|
42
|
-
@api.delete("/users/{user_id}")
|
|
43
|
-
async def delete_user(user_id: int, data: UserCreate):
|
|
44
|
-
return {"deleted": True}
|
|
45
|
-
|
|
46
|
-
error_msg = str(exc_info.value)
|
|
47
|
-
assert "DELETE" in error_msg
|
|
48
|
-
assert "cannot have body parameters" in error_msg
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
def test_post_with_body_param_works():
|
|
52
|
-
"""Test that POST endpoints with body parameters work fine."""
|
|
53
|
-
api = BoltAPI()
|
|
54
|
-
|
|
55
|
-
# This should NOT raise an error
|
|
56
|
-
@api.post("/users")
|
|
57
|
-
async def create_user(user: UserCreate):
|
|
58
|
-
return {"id": 1}
|
|
59
|
-
|
|
60
|
-
# Verify the route was registered
|
|
61
|
-
assert len(api._routes) == 1
|
|
62
|
-
assert api._routes[0][0] == "POST"
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
def test_get_with_explicit_query_marker_works():
|
|
66
|
-
"""Test that GET with explicit Query() marker works."""
|
|
67
|
-
api = BoltAPI()
|
|
68
|
-
|
|
69
|
-
@api.get("/users")
|
|
70
|
-
async def list_users(name: str = Query()):
|
|
71
|
-
return {"users": []}
|
|
72
|
-
|
|
73
|
-
assert len(api._routes) == 1
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
def test_get_with_simple_types_inferred_as_query():
|
|
77
|
-
"""Test that simple types are auto-inferred as query parameters."""
|
|
78
|
-
api = BoltAPI()
|
|
79
|
-
|
|
80
|
-
@api.get("/users")
|
|
81
|
-
async def list_users(page: int = 1, limit: int = 10, search: str = ""):
|
|
82
|
-
return {"users": []}
|
|
83
|
-
|
|
84
|
-
assert len(api._routes) == 1
|
|
85
|
-
|
|
86
|
-
# Check that parameters were inferred as query params
|
|
87
|
-
handler = api._routes[0][3]
|
|
88
|
-
meta = api._handler_meta[handler]
|
|
89
|
-
|
|
90
|
-
for field in meta["fields"]:
|
|
91
|
-
if field["name"] in ("page", "limit", "search"):
|
|
92
|
-
assert field["source"] == "query", f"{field['name']} should be query param"
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
def test_post_with_struct_inferred_as_body():
|
|
96
|
-
"""Test that msgspec.Struct is auto-inferred as body parameter."""
|
|
97
|
-
api = BoltAPI()
|
|
98
|
-
|
|
99
|
-
@api.post("/users")
|
|
100
|
-
async def create_user(user: UserCreate):
|
|
101
|
-
return {"id": 1}
|
|
102
|
-
|
|
103
|
-
handler = api._routes[0][3]
|
|
104
|
-
meta = api._handler_meta[handler]
|
|
105
|
-
|
|
106
|
-
user_field = next(f for f in meta["fields"] if f["name"] == "user")
|
|
107
|
-
assert user_field["source"] == "body"
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
def test_path_params_inferred_correctly():
|
|
111
|
-
"""Test that path parameters are correctly inferred."""
|
|
112
|
-
api = BoltAPI()
|
|
113
|
-
|
|
114
|
-
@api.get("/users/{user_id}/posts/{post_id}")
|
|
115
|
-
async def get_post(user_id: int, post_id: int):
|
|
116
|
-
return {"user_id": user_id, "post_id": post_id}
|
|
117
|
-
|
|
118
|
-
handler = api._routes[0][3]
|
|
119
|
-
meta = api._handler_meta[handler]
|
|
120
|
-
|
|
121
|
-
user_id_field = next(f for f in meta["fields"] if f["name"] == "user_id")
|
|
122
|
-
post_id_field = next(f for f in meta["fields"] if f["name"] == "post_id")
|
|
123
|
-
|
|
124
|
-
assert user_id_field["source"] == "path"
|
|
125
|
-
assert post_id_field["source"] == "path"
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
def test_mixed_params_inference():
|
|
129
|
-
"""Test mixed parameter types with auto-inference."""
|
|
130
|
-
api = BoltAPI()
|
|
131
|
-
|
|
132
|
-
@api.get("/users/{user_id}")
|
|
133
|
-
async def get_user(user_id: int, include_posts: bool = False):
|
|
134
|
-
return {"user_id": user_id, "include_posts": include_posts}
|
|
135
|
-
|
|
136
|
-
handler = api._routes[0][3]
|
|
137
|
-
meta = api._handler_meta[handler]
|
|
138
|
-
|
|
139
|
-
user_id_field = next(f for f in meta["fields"] if f["name"] == "user_id")
|
|
140
|
-
include_posts_field = next(f for f in meta["fields"] if f["name"] == "include_posts")
|
|
141
|
-
|
|
142
|
-
assert user_id_field["source"] == "path"
|
|
143
|
-
assert include_posts_field["source"] == "query"
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
def test_explicit_body_marker_with_post():
|
|
147
|
-
"""Test explicit Body() marker works with POST."""
|
|
148
|
-
api = BoltAPI()
|
|
149
|
-
|
|
150
|
-
@api.post("/users")
|
|
151
|
-
async def create_user(user: UserCreate = Body()):
|
|
152
|
-
return {"id": 1}
|
|
153
|
-
|
|
154
|
-
handler = api._routes[0][3]
|
|
155
|
-
meta = api._handler_meta[handler]
|
|
156
|
-
|
|
157
|
-
user_field = next(f for f in meta["fields"] if f["name"] == "user")
|
|
158
|
-
assert user_field["source"] == "body"
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
def test_error_message_clarity():
|
|
162
|
-
"""Test that error messages are clear and helpful."""
|
|
163
|
-
api = BoltAPI()
|
|
164
|
-
|
|
165
|
-
with pytest.raises(TypeError) as exc_info:
|
|
166
|
-
@api.get("/items")
|
|
167
|
-
async def bad_handler(item: UserCreate):
|
|
168
|
-
pass
|
|
169
|
-
|
|
170
|
-
error_msg = str(exc_info.value)
|
|
171
|
-
# Check all parts of the error message
|
|
172
|
-
assert "bad_handler" in error_msg
|
|
173
|
-
assert "GET /items" in error_msg
|
|
174
|
-
assert "cannot have body parameters" in error_msg
|
|
175
|
-
assert "['item']" in error_msg
|
|
176
|
-
assert "Solutions:" in error_msg
|
|
177
|
-
assert "POST/PUT/PATCH" in error_msg
|
|
178
|
-
assert "Query()" in error_msg
|