apexdevkit 1.7.1__tar.gz → 1.7.2__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.1 → apexdevkit-1.7.2}/PKG-INFO +1 -1
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/testing/rest.py +105 -126
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/pyproject.toml +1 -1
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/LICENSE +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/README.md +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/__init__.py +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/annotation/__init__.py +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/annotation/deprecate.py +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/error.py +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/fastapi/__init__.py +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/fastapi/builder.py +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/fastapi/dependable.py +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/fastapi/docs.py +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/fastapi/resource.py +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/fastapi/response.py +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/fastapi/router.py +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/fastapi/schema.py +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/fastapi/service.py +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/formatter.py +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/http/__init__.py +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/http/fake.py +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/http/fluent.py +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/http/httpx.py +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/http/json.py +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/http/url.py +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/py.typed +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/repository/__init__.py +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/repository/base.py +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/repository/connector.py +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/repository/database.py +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/repository/in_memory.py +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/repository/interface.py +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/testing/__init__.py +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/testing/database.py +0 -0
- {apexdevkit-1.7.1 → apexdevkit-1.7.2}/apexdevkit/testing/fake.py +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from abc import abstractmethod
|
|
4
3
|
from dataclasses import dataclass, field
|
|
5
4
|
from functools import cached_property
|
|
6
5
|
from typing import Any, Iterable, Self
|
|
7
6
|
|
|
8
7
|
from fastapi.testclient import TestClient
|
|
9
8
|
|
|
9
|
+
from apexdevkit.annotation import deprecated
|
|
10
10
|
from apexdevkit.http import Http, HttpUrl, JsonDict
|
|
11
11
|
from apexdevkit.http.fluent import HttpMethod, HttpResponse
|
|
12
12
|
from apexdevkit.http.httpx import Httpx
|
|
@@ -27,32 +27,32 @@ class RestResource:
|
|
|
27
27
|
|
|
28
28
|
return self.http
|
|
29
29
|
|
|
30
|
-
def create_one(self) ->
|
|
31
|
-
return
|
|
30
|
+
def create_one(self) -> RestRequest:
|
|
31
|
+
return RestRequest(self.name, self._http, method=HttpMethod.post)
|
|
32
32
|
|
|
33
33
|
def create_many(self) -> CreateMany:
|
|
34
34
|
return CreateMany(self.name, self._http)
|
|
35
35
|
|
|
36
|
-
def read_one(self) ->
|
|
37
|
-
return
|
|
36
|
+
def read_one(self) -> RestRequest:
|
|
37
|
+
return RestRequest(self.name, self._http, method=HttpMethod.get)
|
|
38
38
|
|
|
39
|
-
def read_all(self) ->
|
|
40
|
-
return
|
|
39
|
+
def read_all(self) -> RestRequest:
|
|
40
|
+
return RestRequest(self.name, self._http, method=HttpMethod.get)
|
|
41
41
|
|
|
42
|
-
def update_one(self) ->
|
|
43
|
-
return
|
|
42
|
+
def update_one(self) -> RestRequest:
|
|
43
|
+
return RestRequest(self.name, self._http, method=HttpMethod.patch)
|
|
44
44
|
|
|
45
45
|
def update_many(self) -> UpdateMany:
|
|
46
46
|
return UpdateMany(self.name, self._http)
|
|
47
47
|
|
|
48
|
-
def replace_one(self) ->
|
|
49
|
-
return
|
|
48
|
+
def replace_one(self) -> RestRequest:
|
|
49
|
+
return RestRequest(self.name, self._http, method=HttpMethod.put)
|
|
50
50
|
|
|
51
51
|
def replace_many(self) -> ReplaceMany:
|
|
52
52
|
return ReplaceMany(self.name, self._http)
|
|
53
53
|
|
|
54
|
-
def delete_one(self) ->
|
|
55
|
-
return
|
|
54
|
+
def delete_one(self) -> RestRequest:
|
|
55
|
+
return RestRequest(self.name, self._http, method=HttpMethod.delete)
|
|
56
56
|
|
|
57
57
|
|
|
58
58
|
@dataclass
|
|
@@ -114,118 +114,57 @@ class RestRequest:
|
|
|
114
114
|
resource: RestfulName
|
|
115
115
|
http: Http
|
|
116
116
|
|
|
117
|
-
|
|
118
|
-
@cached_property
|
|
119
|
-
def response(self) -> HttpResponse: # pragma: no cover
|
|
120
|
-
pass
|
|
121
|
-
|
|
122
|
-
def unpack(self) -> JsonDict:
|
|
123
|
-
return JsonDict(self.response.json()["data"][self.resource.singular])
|
|
124
|
-
|
|
125
|
-
def unpack_many(self) -> Iterable[JsonDict]:
|
|
126
|
-
items = self.response.json()["data"][self.resource.plural]
|
|
127
|
-
|
|
128
|
-
return [JsonDict(item) for item in items]
|
|
129
|
-
|
|
130
|
-
def ensure(self) -> RestResponse:
|
|
131
|
-
return RestResponse(
|
|
132
|
-
resource=self.resource,
|
|
133
|
-
json=JsonDict(self.response.json()),
|
|
134
|
-
http_code=self.response.code(),
|
|
135
|
-
)
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
@dataclass
|
|
139
|
-
class CreateOne(RestRequest):
|
|
140
|
-
data: JsonDict = field(init=False)
|
|
141
|
-
|
|
142
|
-
def from_data(self, value: JsonDict) -> Self:
|
|
143
|
-
self.data = value
|
|
144
|
-
|
|
145
|
-
return self
|
|
146
|
-
|
|
147
|
-
@cached_property
|
|
148
|
-
def response(self) -> HttpResponse:
|
|
149
|
-
return self.http.with_json(self.data).request(
|
|
150
|
-
method=HttpMethod.post,
|
|
151
|
-
endpoint=self.resource + "",
|
|
152
|
-
)
|
|
153
|
-
|
|
117
|
+
method: HttpMethod = field(default=HttpMethod.delete)
|
|
154
118
|
|
|
155
|
-
|
|
156
|
-
class ReadOne(RestRequest):
|
|
157
|
-
item_id: str = field(init=False)
|
|
119
|
+
_endpoint: str = field(init=False, default_factory=str)
|
|
158
120
|
|
|
159
|
-
@
|
|
160
|
-
def
|
|
161
|
-
return self.
|
|
162
|
-
method=HttpMethod.get,
|
|
163
|
-
endpoint=self.resource + str(self.item_id),
|
|
164
|
-
)
|
|
121
|
+
@property
|
|
122
|
+
def endpoint(self) -> str:
|
|
123
|
+
return self.resource + self._endpoint
|
|
165
124
|
|
|
166
125
|
def with_id(self, value: Any) -> Self:
|
|
167
|
-
self.
|
|
126
|
+
self._endpoint = str(value)
|
|
168
127
|
|
|
169
128
|
return self
|
|
170
129
|
|
|
130
|
+
def and_data(self, value: JsonDict) -> Self:
|
|
131
|
+
return self.with_data(value)
|
|
171
132
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
params: dict[str, Any] = field(init=False, default_factory=dict)
|
|
175
|
-
|
|
176
|
-
@cached_property
|
|
177
|
-
def response(self) -> HttpResponse:
|
|
178
|
-
http = self.http
|
|
179
|
-
for param, value in self.params.items():
|
|
180
|
-
http = http.with_param(param, value)
|
|
181
|
-
|
|
182
|
-
return http.request(method=HttpMethod.get, endpoint=self.resource + "")
|
|
133
|
+
def from_data(self, value: JsonDict) -> Self:
|
|
134
|
+
return self.with_data(value)
|
|
183
135
|
|
|
184
|
-
def
|
|
185
|
-
self.
|
|
136
|
+
def with_data(self, value: JsonDict) -> Self:
|
|
137
|
+
self.http = self.http.with_json(value)
|
|
186
138
|
|
|
187
139
|
return self
|
|
188
140
|
|
|
141
|
+
def and_param(self, name: str, value: Any) -> Self:
|
|
142
|
+
return self.with_param(name, value)
|
|
189
143
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
item_id: str = field(init=False)
|
|
193
|
-
data: JsonDict = field(init=False)
|
|
194
|
-
|
|
195
|
-
@cached_property
|
|
196
|
-
def response(self) -> HttpResponse:
|
|
197
|
-
return self.http.with_json(self.data).request(
|
|
198
|
-
method=HttpMethod.patch,
|
|
199
|
-
endpoint=self.resource + str(self.item_id),
|
|
200
|
-
)
|
|
201
|
-
|
|
202
|
-
def with_id(self, value: Any) -> Self:
|
|
203
|
-
self.item_id = str(value)
|
|
144
|
+
def with_param(self, name: str, value: Any) -> Self:
|
|
145
|
+
self.http = self.http.with_param(name, str(value))
|
|
204
146
|
|
|
205
147
|
return self
|
|
206
148
|
|
|
207
|
-
|
|
208
|
-
|
|
149
|
+
@cached_property
|
|
150
|
+
def response(self) -> HttpResponse: # pragma: no cover
|
|
151
|
+
return self.http.request(method=self.method, endpoint=self.endpoint)
|
|
209
152
|
|
|
210
|
-
|
|
153
|
+
def unpack(self) -> JsonDict:
|
|
154
|
+
return JsonDict(self.response.json()["data"][self.resource.singular])
|
|
211
155
|
|
|
156
|
+
def unpack_many(self) -> Iterable[JsonDict]:
|
|
157
|
+
items = self.response.json()["data"][self.resource.plural]
|
|
212
158
|
|
|
213
|
-
|
|
214
|
-
class ReplaceOne(RestRequest):
|
|
215
|
-
data: JsonDict = field(init=False)
|
|
159
|
+
return [JsonDict(item) for item in items]
|
|
216
160
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
161
|
+
def ensure(self) -> RestResponse:
|
|
162
|
+
return RestResponse(
|
|
163
|
+
resource=self.resource,
|
|
164
|
+
json=JsonDict(self.response.json()),
|
|
165
|
+
http_code=self.response.code(),
|
|
222
166
|
)
|
|
223
167
|
|
|
224
|
-
def from_data(self, value: JsonDict) -> Self:
|
|
225
|
-
self.data = value
|
|
226
|
-
|
|
227
|
-
return self
|
|
228
|
-
|
|
229
168
|
|
|
230
169
|
@dataclass
|
|
231
170
|
class CreateMany(RestRequest):
|
|
@@ -233,18 +172,37 @@ class CreateMany(RestRequest):
|
|
|
233
172
|
|
|
234
173
|
@cached_property
|
|
235
174
|
def response(self) -> HttpResponse:
|
|
236
|
-
|
|
175
|
+
if self.data:
|
|
176
|
+
return self.from_collection(self.data).http.request(
|
|
177
|
+
method=HttpMethod.post,
|
|
178
|
+
endpoint=self.resource + "batch",
|
|
179
|
+
)
|
|
237
180
|
|
|
238
|
-
return self.http.
|
|
181
|
+
return self.http.request(
|
|
239
182
|
method=HttpMethod.post,
|
|
240
183
|
endpoint=self.resource + "batch",
|
|
241
184
|
)
|
|
242
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
|
+
)
|
|
243
196
|
def from_data(self, value: JsonDict) -> Self:
|
|
244
197
|
self.data.append(value)
|
|
245
198
|
|
|
246
199
|
return self
|
|
247
200
|
|
|
201
|
+
@deprecated(
|
|
202
|
+
"""
|
|
203
|
+
.and_data is deprecated, use .from_collection instead
|
|
204
|
+
"""
|
|
205
|
+
)
|
|
248
206
|
def and_data(self, value: JsonDict) -> Self:
|
|
249
207
|
return self.from_data(value)
|
|
250
208
|
|
|
@@ -255,18 +213,37 @@ class UpdateMany(RestRequest):
|
|
|
255
213
|
|
|
256
214
|
@cached_property
|
|
257
215
|
def response(self) -> HttpResponse:
|
|
258
|
-
|
|
216
|
+
if self.data:
|
|
217
|
+
return self.from_collection(self.data).http.request(
|
|
218
|
+
method=HttpMethod.patch,
|
|
219
|
+
endpoint=self.resource + "",
|
|
220
|
+
)
|
|
259
221
|
|
|
260
|
-
return self.http.
|
|
222
|
+
return self.http.request(
|
|
261
223
|
method=HttpMethod.patch,
|
|
262
224
|
endpoint=self.resource + "",
|
|
263
225
|
)
|
|
264
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
|
+
)
|
|
265
237
|
def from_data(self, value: JsonDict) -> Self:
|
|
266
238
|
self.data.append(value)
|
|
267
239
|
|
|
268
240
|
return self
|
|
269
241
|
|
|
242
|
+
@deprecated(
|
|
243
|
+
"""
|
|
244
|
+
.and_data is deprecated, use .from_collection instead
|
|
245
|
+
"""
|
|
246
|
+
)
|
|
270
247
|
def and_data(self, value: JsonDict) -> Self:
|
|
271
248
|
return self.from_data(value)
|
|
272
249
|
|
|
@@ -277,39 +254,41 @@ class ReplaceMany(RestRequest):
|
|
|
277
254
|
|
|
278
255
|
@cached_property
|
|
279
256
|
def response(self) -> HttpResponse:
|
|
280
|
-
|
|
257
|
+
if self.data:
|
|
258
|
+
return self.from_collection(self.data).http.request(
|
|
259
|
+
method=HttpMethod.put,
|
|
260
|
+
endpoint=self.resource + "batch",
|
|
261
|
+
)
|
|
281
262
|
|
|
282
|
-
return self.http.
|
|
263
|
+
return self.http.request(
|
|
283
264
|
method=HttpMethod.put,
|
|
284
265
|
endpoint=self.resource + "batch",
|
|
285
266
|
)
|
|
286
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
|
+
)
|
|
287
278
|
def from_data(self, value: JsonDict) -> Self:
|
|
288
279
|
self.data.append(value)
|
|
289
280
|
|
|
290
281
|
return self
|
|
291
282
|
|
|
283
|
+
@deprecated(
|
|
284
|
+
"""
|
|
285
|
+
.and_data is deprecated, use .from_collection instead
|
|
286
|
+
"""
|
|
287
|
+
)
|
|
292
288
|
def and_data(self, value: JsonDict) -> Self:
|
|
293
289
|
return self.from_data(value)
|
|
294
290
|
|
|
295
291
|
|
|
296
|
-
@dataclass
|
|
297
|
-
class DeleteOne(RestRequest):
|
|
298
|
-
item_id: str = field(init=False)
|
|
299
|
-
|
|
300
|
-
@cached_property
|
|
301
|
-
def response(self) -> HttpResponse:
|
|
302
|
-
return self.http.request(
|
|
303
|
-
method=HttpMethod.delete,
|
|
304
|
-
endpoint=self.resource + str(self.item_id),
|
|
305
|
-
)
|
|
306
|
-
|
|
307
|
-
def with_id(self, value: Any) -> Self:
|
|
308
|
-
self.item_id = str(value)
|
|
309
|
-
|
|
310
|
-
return self
|
|
311
|
-
|
|
312
|
-
|
|
313
292
|
@dataclass
|
|
314
293
|
class RestResponse:
|
|
315
294
|
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
|