apexdevkit 1.8.1__tar.gz → 1.8.3__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.
Files changed (35) hide show
  1. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/PKG-INFO +1 -1
  2. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/http/fake.py +4 -1
  3. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/http/fluent.py +4 -1
  4. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/http/httpx.py +6 -1
  5. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/testing/rest.py +52 -46
  6. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/pyproject.toml +1 -1
  7. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/LICENSE +0 -0
  8. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/README.md +0 -0
  9. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/__init__.py +0 -0
  10. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/annotation/__init__.py +0 -0
  11. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/annotation/deprecate.py +0 -0
  12. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/error.py +0 -0
  13. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/fastapi/__init__.py +0 -0
  14. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/fastapi/builder.py +0 -0
  15. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/fastapi/dependable.py +0 -0
  16. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/fastapi/docs.py +0 -0
  17. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/fastapi/resource.py +0 -0
  18. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/fastapi/response.py +0 -0
  19. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/fastapi/router.py +0 -0
  20. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/fastapi/schema.py +0 -0
  21. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/fastapi/service.py +0 -0
  22. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/formatter.py +0 -0
  23. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/http/__init__.py +0 -0
  24. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/http/json.py +0 -0
  25. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/http/url.py +0 -0
  26. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/py.typed +0 -0
  27. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/repository/__init__.py +0 -0
  28. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/repository/base.py +0 -0
  29. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/repository/connector.py +0 -0
  30. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/repository/database.py +0 -0
  31. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/repository/in_memory.py +0 -0
  32. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/repository/interface.py +0 -0
  33. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/testing/__init__.py +0 -0
  34. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/testing/database.py +0 -0
  35. {apexdevkit-1.8.1 → apexdevkit-1.8.3}/apexdevkit/testing/fake.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: apexdevkit
3
- Version: 1.8.1
3
+ Version: 1.8.3
4
4
  Summary: Apex Development Tools for python.
5
5
  Author: Apex Dev
6
6
  Author-email: dev@apex.ge
@@ -48,6 +48,9 @@ class FakeHttp:
48
48
 
49
49
  _request: InterceptedRequest = field(init=False)
50
50
 
51
+ def with_endpoint(self, value: str) -> Self: # pragma: no cover
52
+ raise NotImplementedError
53
+
51
54
  def with_header(self, key: str, value: str) -> Self:
52
55
  self.headers[key] = value
53
56
 
@@ -63,7 +66,7 @@ class FakeHttp:
63
66
 
64
67
  return self
65
68
 
66
- def request(self, method: HttpMethod, endpoint: str) -> HttpResponse:
69
+ def request(self, method: HttpMethod, endpoint: str = "") -> HttpResponse:
67
70
  self._request = InterceptedRequest(method, endpoint)
68
71
 
69
72
  return self.response
@@ -8,6 +8,9 @@ from apexdevkit.http.json import JsonDict
8
8
 
9
9
 
10
10
  class Http(Protocol): # pragma: no cover
11
+ def with_endpoint(self, value: str) -> Http:
12
+ pass
13
+
11
14
  def with_header(self, key: str, value: str) -> Http:
12
15
  pass
13
16
 
@@ -17,7 +20,7 @@ class Http(Protocol): # pragma: no cover
17
20
  def with_json(self, value: JsonDict) -> Http:
18
21
  pass
19
22
 
20
- def request(self, method: HttpMethod, endpoint: str) -> HttpResponse:
23
+ def request(self, method: HttpMethod, endpoint: str = "") -> HttpResponse:
21
24
  pass
22
25
 
23
26
 
@@ -24,6 +24,11 @@ class Httpx:
24
24
  def create_for(cls, url: str) -> Self:
25
25
  return cls(Client(base_url=url), HttpxConfig())
26
26
 
27
+ def with_endpoint(self, value: str) -> Httpx:
28
+ self.client.base_url = self.client.base_url.join(value)
29
+
30
+ return self
31
+
27
32
  def with_header(self, key: str, value: str) -> Httpx:
28
33
  return Httpx(self.client, self.config.with_header(key, value))
29
34
 
@@ -33,7 +38,7 @@ class Httpx:
33
38
  def with_json(self, value: JsonDict) -> Httpx:
34
39
  return Httpx(self.client, self.config.with_json(value))
35
40
 
36
- def request(self, method: HttpMethod, endpoint: str) -> HttpResponse:
41
+ def request(self, method: HttpMethod, endpoint: str = "") -> HttpResponse:
37
42
  return _HttpxResponse(self.client.request(method.name, endpoint, **self.config))
38
43
 
39
44
 
@@ -6,7 +6,6 @@ from typing import Any, Iterable, Self
6
6
 
7
7
  from apexdevkit.http import Http, HttpUrl, JsonDict
8
8
  from apexdevkit.http.fluent import HttpMethod, HttpResponse
9
- from apexdevkit.http.httpx import Httpx
10
9
 
11
10
 
12
11
  @dataclass
@@ -17,86 +16,95 @@ class RestResource:
17
16
  def create_one(self) -> RestRequest:
18
17
  return RestRequest(
19
18
  self.name,
20
- HttpRequest(HttpMethod.post, self.http).with_endpoint(self.name.plural),
19
+ HttpRequest(
20
+ HttpMethod.post,
21
+ self.http.with_endpoint(self.name.plural),
22
+ ),
21
23
  )
22
24
 
23
25
  def create_many(self) -> RestRequest:
24
26
  return RestRequest(
25
27
  self.name,
26
- request=(
27
- HttpRequest(HttpMethod.post, self.http)
28
- .with_endpoint(self.name.plural)
29
- .with_endpoint("batch")
28
+ HttpRequest(
29
+ HttpMethod.post,
30
+ self.http.with_endpoint(self.name.plural).with_endpoint("batch"),
30
31
  ),
31
32
  )
32
33
 
33
34
  def read_one(self) -> RestRequest:
34
35
  return RestRequest(
35
36
  self.name,
36
- HttpRequest(HttpMethod.get, self.http).with_endpoint(self.name.plural),
37
+ HttpRequest(
38
+ HttpMethod.get,
39
+ self.http.with_endpoint(self.name.plural),
40
+ ),
37
41
  )
38
42
 
39
43
  def read_all(self) -> RestRequest:
40
44
  return RestRequest(
41
45
  self.name,
42
- HttpRequest(HttpMethod.get, self.http).with_endpoint(self.name.plural),
46
+ HttpRequest(
47
+ HttpMethod.get,
48
+ self.http.with_endpoint(self.name.plural),
49
+ ),
43
50
  )
44
51
 
45
52
  def update_one(self) -> RestRequest:
46
53
  return RestRequest(
47
54
  self.name,
48
- HttpRequest(HttpMethod.patch, self.http).with_endpoint(self.name.plural),
55
+ HttpRequest(
56
+ HttpMethod.patch,
57
+ self.http.with_endpoint(self.name.plural),
58
+ ),
49
59
  )
50
60
 
51
61
  def update_many(self) -> RestRequest:
52
62
  return RestRequest(
53
63
  self.name,
54
- HttpRequest(HttpMethod.patch, self.http).with_endpoint(self.name.plural),
64
+ HttpRequest(
65
+ HttpMethod.patch,
66
+ self.http.with_endpoint(self.name.plural),
67
+ ),
55
68
  )
56
69
 
57
70
  def replace_one(self) -> RestRequest:
58
71
  return RestRequest(
59
72
  self.name,
60
- HttpRequest(HttpMethod.put, self.http).with_endpoint(self.name.plural),
73
+ HttpRequest(
74
+ HttpMethod.put,
75
+ self.http.with_endpoint(self.name.plural),
76
+ ),
61
77
  )
62
78
 
63
79
  def replace_many(self) -> RestRequest:
64
80
  return RestRequest(
65
81
  self.name,
66
- request=(
67
- HttpRequest(HttpMethod.put, self.http)
68
- .with_endpoint(self.name.plural)
69
- .with_endpoint("batch")
82
+ HttpRequest(
83
+ HttpMethod.put,
84
+ self.http.with_endpoint(self.name.plural).with_endpoint("batch"),
70
85
  ),
71
86
  )
72
87
 
73
88
  def delete_one(self) -> RestRequest:
74
89
  return RestRequest(
75
90
  self.name,
76
- HttpRequest(HttpMethod.delete, self.http).with_endpoint(self.name.plural),
91
+ HttpRequest(
92
+ HttpMethod.delete,
93
+ self.http.with_endpoint(self.name.plural),
94
+ ),
77
95
  )
78
96
 
79
97
 
80
98
  @dataclass
81
99
  class RestCollection(RestResource):
82
100
  def sub_resource(self, name: str) -> RestItem:
83
- assert isinstance(self.http, Httpx), "sub resource only works with Httpx"
84
-
85
- client = self.http.client
86
- client.base_url = client.base_url.join(self.name.plural)
87
-
88
- return RestItem(self.http, RestfulName(name))
101
+ return RestItem(self.http.with_endpoint(self.name.plural), RestfulName(name))
89
102
 
90
103
 
91
104
  @dataclass
92
105
  class RestItem(RestResource):
93
106
  def sub_resource(self, name: str) -> RestItem:
94
- assert isinstance(self.http, Httpx), "sub resource only works with Httpx"
95
-
96
- client = self.http.client
97
- client.base_url = client.base_url.join(self.name.singular)
98
-
99
- return RestItem(self.http, RestfulName(name))
107
+ return RestItem(self.http.with_endpoint(self.name.singular), RestfulName(name))
100
108
 
101
109
 
102
110
  @dataclass
@@ -113,20 +121,20 @@ class RestfulName:
113
121
 
114
122
 
115
123
  def as_plural(singular: str) -> str:
116
- if singular.endswith("y"):
117
- return singular[:-1] + "ies"
118
-
119
- if singular.endswith("ch") or singular.endswith("sh") or singular.endswith("ss"):
120
- return singular[:-2] + "es"
121
-
122
- if singular.endswith("s") or singular.endswith("z") or singular.endswith("x"):
123
- return singular[:-1] + "es"
124
-
125
- if singular.endswith("fe"):
126
- return singular[:-2] + "ves"
127
-
128
- if singular.endswith("f"):
129
- return singular[:-1] + "ves"
124
+ suffixes = {
125
+ "y": "ies",
126
+ "ch": "ches",
127
+ "sh": "shes",
128
+ "s": "ses",
129
+ "z": "zes",
130
+ "x": "xes",
131
+ "fe": "ves",
132
+ "f": "ves",
133
+ }
134
+
135
+ for singular_suffix, plural_suffix in suffixes.items():
136
+ if singular.endswith(singular_suffix):
137
+ return singular.removesuffix(singular_suffix) + plural_suffix
130
138
 
131
139
  return singular + "s"
132
140
 
@@ -136,10 +144,8 @@ class HttpRequest:
136
144
  method: HttpMethod
137
145
  http: Http
138
146
 
139
- endpoint: str = ""
140
-
141
147
  def with_endpoint(self, value: Any) -> HttpRequest:
142
- self.endpoint = HttpUrl(self.endpoint) + str(value)
148
+ self.http = self.http.with_endpoint(str(value))
143
149
 
144
150
  return self
145
151
 
@@ -154,7 +160,7 @@ class HttpRequest:
154
160
  return self
155
161
 
156
162
  def __call__(self) -> HttpResponse:
157
- return self.http.request(method=self.method, endpoint=self.endpoint)
163
+ return self.http.request(self.method)
158
164
 
159
165
 
160
166
  @dataclass
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "apexdevkit"
3
- version = "1.8.1"
3
+ version = "1.8.3"
4
4
  description = "Apex Development Tools for python."
5
5
  authors = ["Apex Dev <dev@apex.ge>"]
6
6
  readme = "README.md"
File without changes
File without changes