apexdevkit 1.7.2__tar.gz → 1.8.1__tar.gz
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.
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/PKG-INFO +1 -1
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/testing/rest.py +84 -162
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/pyproject.toml +1 -1
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/LICENSE +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/README.md +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/__init__.py +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/annotation/__init__.py +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/annotation/deprecate.py +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/error.py +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/fastapi/__init__.py +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/fastapi/builder.py +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/fastapi/dependable.py +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/fastapi/docs.py +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/fastapi/resource.py +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/fastapi/response.py +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/fastapi/router.py +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/fastapi/schema.py +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/fastapi/service.py +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/formatter.py +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/http/__init__.py +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/http/fake.py +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/http/fluent.py +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/http/httpx.py +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/http/json.py +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/http/url.py +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/py.typed +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/repository/__init__.py +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/repository/base.py +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/repository/connector.py +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/repository/database.py +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/repository/in_memory.py +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/repository/interface.py +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/testing/__init__.py +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/testing/database.py +0 -0
- {apexdevkit-1.7.2 → apexdevkit-1.8.1}/apexdevkit/testing/fake.py +0 -0
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from dataclasses import dataclass
|
|
3
|
+
from dataclasses import dataclass
|
|
4
4
|
from functools import cached_property
|
|
5
5
|
from typing import Any, Iterable, Self
|
|
6
6
|
|
|
7
|
-
from fastapi.testclient import TestClient
|
|
8
|
-
|
|
9
|
-
from apexdevkit.annotation import deprecated
|
|
10
7
|
from apexdevkit.http import Http, HttpUrl, JsonDict
|
|
11
8
|
from apexdevkit.http.fluent import HttpMethod, HttpResponse
|
|
12
9
|
from apexdevkit.http.httpx import Httpx
|
|
@@ -14,45 +11,70 @@ from apexdevkit.http.httpx import Httpx
|
|
|
14
11
|
|
|
15
12
|
@dataclass
|
|
16
13
|
class RestResource:
|
|
17
|
-
http:
|
|
14
|
+
http: Http
|
|
18
15
|
name: RestfulName
|
|
19
16
|
|
|
20
|
-
def __post_init__(self) -> None:
|
|
21
|
-
if isinstance(self.http, TestClient):
|
|
22
|
-
self.http = Httpx(self.http)
|
|
23
|
-
|
|
24
|
-
@property
|
|
25
|
-
def _http(self) -> Http:
|
|
26
|
-
assert not isinstance(self.http, TestClient)
|
|
27
|
-
|
|
28
|
-
return self.http
|
|
29
|
-
|
|
30
17
|
def create_one(self) -> RestRequest:
|
|
31
|
-
return RestRequest(
|
|
18
|
+
return RestRequest(
|
|
19
|
+
self.name,
|
|
20
|
+
HttpRequest(HttpMethod.post, self.http).with_endpoint(self.name.plural),
|
|
21
|
+
)
|
|
32
22
|
|
|
33
|
-
def create_many(self) ->
|
|
34
|
-
return
|
|
23
|
+
def create_many(self) -> RestRequest:
|
|
24
|
+
return RestRequest(
|
|
25
|
+
self.name,
|
|
26
|
+
request=(
|
|
27
|
+
HttpRequest(HttpMethod.post, self.http)
|
|
28
|
+
.with_endpoint(self.name.plural)
|
|
29
|
+
.with_endpoint("batch")
|
|
30
|
+
),
|
|
31
|
+
)
|
|
35
32
|
|
|
36
33
|
def read_one(self) -> RestRequest:
|
|
37
|
-
return RestRequest(
|
|
34
|
+
return RestRequest(
|
|
35
|
+
self.name,
|
|
36
|
+
HttpRequest(HttpMethod.get, self.http).with_endpoint(self.name.plural),
|
|
37
|
+
)
|
|
38
38
|
|
|
39
39
|
def read_all(self) -> RestRequest:
|
|
40
|
-
return RestRequest(
|
|
40
|
+
return RestRequest(
|
|
41
|
+
self.name,
|
|
42
|
+
HttpRequest(HttpMethod.get, self.http).with_endpoint(self.name.plural),
|
|
43
|
+
)
|
|
41
44
|
|
|
42
45
|
def update_one(self) -> RestRequest:
|
|
43
|
-
return RestRequest(
|
|
46
|
+
return RestRequest(
|
|
47
|
+
self.name,
|
|
48
|
+
HttpRequest(HttpMethod.patch, self.http).with_endpoint(self.name.plural),
|
|
49
|
+
)
|
|
44
50
|
|
|
45
|
-
def update_many(self) ->
|
|
46
|
-
return
|
|
51
|
+
def update_many(self) -> RestRequest:
|
|
52
|
+
return RestRequest(
|
|
53
|
+
self.name,
|
|
54
|
+
HttpRequest(HttpMethod.patch, self.http).with_endpoint(self.name.plural),
|
|
55
|
+
)
|
|
47
56
|
|
|
48
57
|
def replace_one(self) -> RestRequest:
|
|
49
|
-
return RestRequest(
|
|
58
|
+
return RestRequest(
|
|
59
|
+
self.name,
|
|
60
|
+
HttpRequest(HttpMethod.put, self.http).with_endpoint(self.name.plural),
|
|
61
|
+
)
|
|
50
62
|
|
|
51
|
-
def replace_many(self) ->
|
|
52
|
-
return
|
|
63
|
+
def replace_many(self) -> RestRequest:
|
|
64
|
+
return RestRequest(
|
|
65
|
+
self.name,
|
|
66
|
+
request=(
|
|
67
|
+
HttpRequest(HttpMethod.put, self.http)
|
|
68
|
+
.with_endpoint(self.name.plural)
|
|
69
|
+
.with_endpoint("batch")
|
|
70
|
+
),
|
|
71
|
+
)
|
|
53
72
|
|
|
54
73
|
def delete_one(self) -> RestRequest:
|
|
55
|
-
return RestRequest(
|
|
74
|
+
return RestRequest(
|
|
75
|
+
self.name,
|
|
76
|
+
HttpRequest(HttpMethod.delete, self.http).with_endpoint(self.name.plural),
|
|
77
|
+
)
|
|
56
78
|
|
|
57
79
|
|
|
58
80
|
@dataclass
|
|
@@ -110,23 +132,46 @@ def as_plural(singular: str) -> str:
|
|
|
110
132
|
|
|
111
133
|
|
|
112
134
|
@dataclass
|
|
113
|
-
class
|
|
114
|
-
|
|
135
|
+
class HttpRequest:
|
|
136
|
+
method: HttpMethod
|
|
115
137
|
http: Http
|
|
116
138
|
|
|
117
|
-
|
|
139
|
+
endpoint: str = ""
|
|
140
|
+
|
|
141
|
+
def with_endpoint(self, value: Any) -> HttpRequest:
|
|
142
|
+
self.endpoint = HttpUrl(self.endpoint) + str(value)
|
|
118
143
|
|
|
119
|
-
|
|
144
|
+
return self
|
|
145
|
+
|
|
146
|
+
def with_param(self, name: str, value: Any) -> HttpRequest:
|
|
147
|
+
self.http = self.http.with_param(name, value)
|
|
148
|
+
|
|
149
|
+
return self
|
|
120
150
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
151
|
+
def with_json(self, value: JsonDict) -> HttpRequest:
|
|
152
|
+
self.http = self.http.with_json(value)
|
|
153
|
+
|
|
154
|
+
return self
|
|
155
|
+
|
|
156
|
+
def __call__(self) -> HttpResponse:
|
|
157
|
+
return self.http.request(method=self.method, endpoint=self.endpoint)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
@dataclass
|
|
161
|
+
class RestRequest:
|
|
162
|
+
resource: RestfulName
|
|
163
|
+
request: HttpRequest
|
|
124
164
|
|
|
125
165
|
def with_id(self, value: Any) -> Self:
|
|
126
|
-
self.
|
|
166
|
+
self.request = self.request.with_endpoint(value)
|
|
127
167
|
|
|
128
168
|
return self
|
|
129
169
|
|
|
170
|
+
def from_collection(self, value: list[JsonDict]) -> Self:
|
|
171
|
+
return self.with_data(
|
|
172
|
+
JsonDict({self.resource.plural: [dict(item) for item in value]})
|
|
173
|
+
)
|
|
174
|
+
|
|
130
175
|
def and_data(self, value: JsonDict) -> Self:
|
|
131
176
|
return self.with_data(value)
|
|
132
177
|
|
|
@@ -134,7 +179,7 @@ class RestRequest:
|
|
|
134
179
|
return self.with_data(value)
|
|
135
180
|
|
|
136
181
|
def with_data(self, value: JsonDict) -> Self:
|
|
137
|
-
self.
|
|
182
|
+
self.request = self.request.with_json(value)
|
|
138
183
|
|
|
139
184
|
return self
|
|
140
185
|
|
|
@@ -142,13 +187,13 @@ class RestRequest:
|
|
|
142
187
|
return self.with_param(name, value)
|
|
143
188
|
|
|
144
189
|
def with_param(self, name: str, value: Any) -> Self:
|
|
145
|
-
self.
|
|
190
|
+
self.request = self.request.with_param(name, str(value))
|
|
146
191
|
|
|
147
192
|
return self
|
|
148
193
|
|
|
149
194
|
@cached_property
|
|
150
|
-
def response(self) -> HttpResponse:
|
|
151
|
-
return self.
|
|
195
|
+
def response(self) -> HttpResponse:
|
|
196
|
+
return self.request()
|
|
152
197
|
|
|
153
198
|
def unpack(self) -> JsonDict:
|
|
154
199
|
return JsonDict(self.response.json()["data"][self.resource.singular])
|
|
@@ -166,129 +211,6 @@ class RestRequest:
|
|
|
166
211
|
)
|
|
167
212
|
|
|
168
213
|
|
|
169
|
-
@dataclass
|
|
170
|
-
class CreateMany(RestRequest):
|
|
171
|
-
data: list[JsonDict] = field(default_factory=list)
|
|
172
|
-
|
|
173
|
-
@cached_property
|
|
174
|
-
def response(self) -> HttpResponse:
|
|
175
|
-
if self.data:
|
|
176
|
-
return self.from_collection(self.data).http.request(
|
|
177
|
-
method=HttpMethod.post,
|
|
178
|
-
endpoint=self.resource + "batch",
|
|
179
|
-
)
|
|
180
|
-
|
|
181
|
-
return self.http.request(
|
|
182
|
-
method=HttpMethod.post,
|
|
183
|
-
endpoint=self.resource + "batch",
|
|
184
|
-
)
|
|
185
|
-
|
|
186
|
-
def from_collection(self, value: list[JsonDict]) -> Self:
|
|
187
|
-
return self.with_data(
|
|
188
|
-
JsonDict({self.resource.plural: [dict(item) for item in value]})
|
|
189
|
-
)
|
|
190
|
-
|
|
191
|
-
@deprecated(
|
|
192
|
-
"""
|
|
193
|
-
.from_data is deprecated, use .from_collection instead
|
|
194
|
-
"""
|
|
195
|
-
)
|
|
196
|
-
def from_data(self, value: JsonDict) -> Self:
|
|
197
|
-
self.data.append(value)
|
|
198
|
-
|
|
199
|
-
return self
|
|
200
|
-
|
|
201
|
-
@deprecated(
|
|
202
|
-
"""
|
|
203
|
-
.and_data is deprecated, use .from_collection instead
|
|
204
|
-
"""
|
|
205
|
-
)
|
|
206
|
-
def and_data(self, value: JsonDict) -> Self:
|
|
207
|
-
return self.from_data(value)
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
@dataclass
|
|
211
|
-
class UpdateMany(RestRequest):
|
|
212
|
-
data: list[JsonDict] = field(default_factory=list)
|
|
213
|
-
|
|
214
|
-
@cached_property
|
|
215
|
-
def response(self) -> HttpResponse:
|
|
216
|
-
if self.data:
|
|
217
|
-
return self.from_collection(self.data).http.request(
|
|
218
|
-
method=HttpMethod.patch,
|
|
219
|
-
endpoint=self.resource + "",
|
|
220
|
-
)
|
|
221
|
-
|
|
222
|
-
return self.http.request(
|
|
223
|
-
method=HttpMethod.patch,
|
|
224
|
-
endpoint=self.resource + "",
|
|
225
|
-
)
|
|
226
|
-
|
|
227
|
-
def from_collection(self, value: list[JsonDict]) -> Self:
|
|
228
|
-
return self.with_data(
|
|
229
|
-
JsonDict({self.resource.plural: [dict(item) for item in value]})
|
|
230
|
-
)
|
|
231
|
-
|
|
232
|
-
@deprecated(
|
|
233
|
-
"""
|
|
234
|
-
.from_data is deprecated, use .from_collection instead
|
|
235
|
-
"""
|
|
236
|
-
)
|
|
237
|
-
def from_data(self, value: JsonDict) -> Self:
|
|
238
|
-
self.data.append(value)
|
|
239
|
-
|
|
240
|
-
return self
|
|
241
|
-
|
|
242
|
-
@deprecated(
|
|
243
|
-
"""
|
|
244
|
-
.and_data is deprecated, use .from_collection instead
|
|
245
|
-
"""
|
|
246
|
-
)
|
|
247
|
-
def and_data(self, value: JsonDict) -> Self:
|
|
248
|
-
return self.from_data(value)
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
@dataclass
|
|
252
|
-
class ReplaceMany(RestRequest):
|
|
253
|
-
data: list[JsonDict] = field(default_factory=list)
|
|
254
|
-
|
|
255
|
-
@cached_property
|
|
256
|
-
def response(self) -> HttpResponse:
|
|
257
|
-
if self.data:
|
|
258
|
-
return self.from_collection(self.data).http.request(
|
|
259
|
-
method=HttpMethod.put,
|
|
260
|
-
endpoint=self.resource + "batch",
|
|
261
|
-
)
|
|
262
|
-
|
|
263
|
-
return self.http.request(
|
|
264
|
-
method=HttpMethod.put,
|
|
265
|
-
endpoint=self.resource + "batch",
|
|
266
|
-
)
|
|
267
|
-
|
|
268
|
-
def from_collection(self, value: list[JsonDict]) -> Self:
|
|
269
|
-
return self.with_data(
|
|
270
|
-
JsonDict({self.resource.plural: [dict(item) for item in value]})
|
|
271
|
-
)
|
|
272
|
-
|
|
273
|
-
@deprecated(
|
|
274
|
-
"""
|
|
275
|
-
.from_data is deprecated, use .from_collection instead
|
|
276
|
-
"""
|
|
277
|
-
)
|
|
278
|
-
def from_data(self, value: JsonDict) -> Self:
|
|
279
|
-
self.data.append(value)
|
|
280
|
-
|
|
281
|
-
return self
|
|
282
|
-
|
|
283
|
-
@deprecated(
|
|
284
|
-
"""
|
|
285
|
-
.and_data is deprecated, use .from_collection instead
|
|
286
|
-
"""
|
|
287
|
-
)
|
|
288
|
-
def and_data(self, value: JsonDict) -> Self:
|
|
289
|
-
return self.from_data(value)
|
|
290
|
-
|
|
291
|
-
|
|
292
214
|
@dataclass
|
|
293
215
|
class RestResponse:
|
|
294
216
|
resource: RestfulName
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|