asyncly 0.3.0__tar.gz → 0.3.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: asyncly
3
- Version: 0.3.0
3
+ Version: 0.3.3
4
4
  Summary: Simple HTTP client and server for your integrations based on aiohttp
5
5
  Home-page: https://github.com/andy-takker/asyncly
6
6
  License: MIT
@@ -35,7 +35,7 @@ Requires-Dist: aiohttp (>=3.9.5,<4.0.0)
35
35
  Requires-Dist: msgspec (>=0.18.6,<0.19.0) ; extra == "msgspec"
36
36
  Requires-Dist: orjson (>=3.10.6,<4.0.0) ; extra == "orjson"
37
37
  Requires-Dist: pydantic (>=2.8.2,<3.0.0) ; extra == "pydantic"
38
- Project-URL: Bug Tracker, https://github.com/andy-takker/v/issues
38
+ Project-URL: Bug Tracker, https://github.com/andy-takker/asyncly/issues
39
39
  Project-URL: Source, https://github.com/andy-takker/asyncly
40
40
  Description-Content-Type: text/x-rst
41
41
 
@@ -46,14 +46,14 @@ Asyncly
46
46
  :target: https://pypi.python.org/pypi/asyncly/
47
47
  :alt: Latest Version
48
48
 
49
- .. image:: https://img.shields.io/pypi/wheel/base-http-client.svg
50
- :target: https://pypi.python.org/pypi/base-http-client/
49
+ .. image:: https://img.shields.io/pypi/wheel/asyncly.svg
50
+ :target: https://pypi.python.org/pypi/asyncly/
51
51
 
52
- .. image:: https://img.shields.io/pypi/pyversions/base-http-client.svg
53
- :target: https://pypi.python.org/pypi/base-http-client/
52
+ .. image:: https://img.shields.io/pypi/pyversions/asyncly.svg
53
+ :target: https://pypi.python.org/pypi/asyncly/
54
54
 
55
- .. image:: https://img.shields.io/pypi/l/base-http-client.svg
56
- :target: https://pypi.python.org/pypi/base-http-client/
55
+ .. image:: https://img.shields.io/pypi/l/asyncly.svg
56
+ :target: https://pypi.python.org/pypi/asyncly/
57
57
 
58
58
  Simple HTTP client and server for your integrations based on aiohttp_.
59
59
 
@@ -88,7 +88,7 @@ Complete table of extras below:
88
88
 
89
89
  +-------------------------------------+----------------------------------+
90
90
  | example | description |
91
- +========================================================================+
91
+ +=====================================+==================================+
92
92
  | ``pip install "asyncly[msgspec]"`` | For using msgspec_ structs |
93
93
  +-------------------------------------+----------------------------------+
94
94
  | ``pip install "asyncly[orjson]"`` | For fast parsing json by orjson_ |
@@ -99,20 +99,16 @@ Complete table of extras below:
99
99
  Quick start guide
100
100
  -----------------
101
101
 
102
- BaseHttpClient
102
+ HttpClient
103
103
  ~~~~~~~~~~~~~~
104
104
 
105
105
  Simple HTTP Client for `https://catfact.ninja`. See full example in `examples/catfact_client.py`_
106
106
 
107
107
  .. code-block:: python
108
108
 
109
- from base_http_client.client import (
110
- DEFAULT_TIMEOUT,
111
- BaseHttpClient,
112
- ResponseHandlersType,
113
- )
114
- from base_http_client.handlers.pydantic import parse_model
115
- from base_http_client.timeout import TimeoutType
109
+ from asyncly import DEFAULT_TIMEOUT, BaseHttpClient, ResponseHandlersType
110
+ from asyncly.client.handlers.pydantic import parse_model
111
+ from asyncly.client.timeout import TimeoutType
116
112
 
117
113
 
118
114
  class CatfactClient(BaseHttpClient):
@@ -133,7 +129,69 @@ Simple HTTP Client for `https://catfact.ninja`. See full example in `examples/ca
133
129
  timeout=timeout,
134
130
  )
135
131
 
132
+ Test Async Server for client
133
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
134
+
135
+ For the HTTP client, we create a server to which he will go and simulate real
136
+ responses. You can dynamically change the responses from the server in
137
+ a specific test.
138
+
139
+ Let's prepare the fixtures:
140
+
141
+ .. code-block:: python
142
+
143
+ @pytest.fixture
144
+ async def catafact_service() -> AsyncIterator[MockService]:
145
+ routes = [
146
+ MockRoute("GET", "/fact", "random_catfact"),
147
+ ]
148
+ async with start_service(routes) as service:
149
+ service.register(
150
+ "random_catfact",
151
+ JsonResponse({"fact": "test", "length": 4}),
152
+ )
153
+ yield service
154
+
155
+
156
+ @pytest.fixture
157
+ def catfact_url(catafact_service: MockService) -> URL:
158
+ return catafact_service.url
159
+
160
+
161
+ @pytest.fixture
162
+ async def catfact_client(catfact_url: URL) -> AsyncIterator[CatfactClient]:
163
+ async with ClientSession() as session:
164
+ client = CatfactClient(
165
+ client_name="catfact",
166
+ session=session,
167
+ url=catfact_url,
168
+ )
169
+ yield client
170
+
171
+ Now we can use them in tests. See full example in `examples/test_catfact_client.py`_
172
+
173
+ .. code-block:: python
174
+
175
+ async def test_fetch_random_catfact(catfact_client: CatfactClient) -> None:
176
+ # use default registered handler
177
+ fact = await catfact_client.fetch_random_cat_fact()
178
+ assert fact == CatfactSchema(fact="test", length=4)
179
+
136
180
 
181
+ async def test_fetch_random_catfact_timeout(
182
+ catfact_client: CatfactClient,
183
+ catafact_service: MockService,
184
+ ) -> None:
185
+ # change default registered handler to time error handler
186
+ catafact_service.register(
187
+ "random_catfact",
188
+ LatencyResponse(
189
+ wrapped=JsonResponse({"fact": "test", "length": 4}),
190
+ latency=1.5,
191
+ ),
192
+ )
193
+ with pytest.raises(asyncio.TimeoutError):
194
+ await catfact_client.fetch_random_cat_fact(timeout=1)
137
195
 
138
196
 
139
197
  .. _PyPI: https://pypi.org/
@@ -143,3 +201,4 @@ Simple HTTP Client for `https://catfact.ninja`. See full example in `examples/ca
143
201
  .. _pydantic: https://github.com/pydantic/pydantic
144
202
 
145
203
  .. _examples/catfact_client.py: https://github.com/andy-takker/asyncly/blob/master/examples/catfact_client.py
204
+ .. _examples/test_catfact_client.py: https://github.com/andy-takker/asyncly/blob/master/examples/test_catfact_client.py
@@ -0,0 +1,163 @@
1
+ Asyncly
2
+ =======
3
+
4
+ .. image:: https://img.shields.io/pypi/v/asyncly.svg
5
+ :target: https://pypi.python.org/pypi/asyncly/
6
+ :alt: Latest Version
7
+
8
+ .. image:: https://img.shields.io/pypi/wheel/asyncly.svg
9
+ :target: https://pypi.python.org/pypi/asyncly/
10
+
11
+ .. image:: https://img.shields.io/pypi/pyversions/asyncly.svg
12
+ :target: https://pypi.python.org/pypi/asyncly/
13
+
14
+ .. image:: https://img.shields.io/pypi/l/asyncly.svg
15
+ :target: https://pypi.python.org/pypi/asyncly/
16
+
17
+ Simple HTTP client and server for your integrations based on aiohttp_.
18
+
19
+ Installation
20
+ ------------
21
+
22
+ Installation is possible in standard ways, such as PyPI or
23
+ installation from a git repository directly.
24
+
25
+ Installing from PyPI_:
26
+
27
+ .. code-block:: bash
28
+
29
+ pip install asyncly
30
+
31
+ Installing from github.com:
32
+
33
+ .. code-block:: bash
34
+
35
+ pip install git+https://github.com/andy-takker/asyncly
36
+
37
+ The package contains several extras and you can install additional dependencies
38
+ if you specify them in this way.
39
+
40
+ For example, with msgspec_:
41
+
42
+ .. code-block:: bash
43
+
44
+ pip install "asyncly[msgspec]"
45
+
46
+ Complete table of extras below:
47
+
48
+ +-------------------------------------+----------------------------------+
49
+ | example | description |
50
+ +=====================================+==================================+
51
+ | ``pip install "asyncly[msgspec]"`` | For using msgspec_ structs |
52
+ +-------------------------------------+----------------------------------+
53
+ | ``pip install "asyncly[orjson]"`` | For fast parsing json by orjson_ |
54
+ +-------------------------------------+----------------------------------+
55
+ | ``pip install "asyncly[pydantic]"`` | For using pydantic_ models |
56
+ +-------------------------------------+----------------------------------+
57
+
58
+ Quick start guide
59
+ -----------------
60
+
61
+ HttpClient
62
+ ~~~~~~~~~~~~~~
63
+
64
+ Simple HTTP Client for `https://catfact.ninja`. See full example in `examples/catfact_client.py`_
65
+
66
+ .. code-block:: python
67
+
68
+ from asyncly import DEFAULT_TIMEOUT, BaseHttpClient, ResponseHandlersType
69
+ from asyncly.client.handlers.pydantic import parse_model
70
+ from asyncly.client.timeout import TimeoutType
71
+
72
+
73
+ class CatfactClient(BaseHttpClient):
74
+ RANDOM_CATFACT_HANDLERS: ResponseHandlersType = MappingProxyType(
75
+ {
76
+ HTTPStatus.OK: parse_model(CatfactSchema),
77
+ }
78
+ )
79
+
80
+ async def fetch_random_cat_fact(
81
+ self,
82
+ timeout: TimeoutType = DEFAULT_TIMEOUT,
83
+ ) -> CatfactSchema:
84
+ return await self._make_req(
85
+ method=hdrs.METH_GET,
86
+ url=self._url / "fact",
87
+ handlers=self.RANDOM_CATFACT_HANDLERS,
88
+ timeout=timeout,
89
+ )
90
+
91
+ Test Async Server for client
92
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
93
+
94
+ For the HTTP client, we create a server to which he will go and simulate real
95
+ responses. You can dynamically change the responses from the server in
96
+ a specific test.
97
+
98
+ Let's prepare the fixtures:
99
+
100
+ .. code-block:: python
101
+
102
+ @pytest.fixture
103
+ async def catafact_service() -> AsyncIterator[MockService]:
104
+ routes = [
105
+ MockRoute("GET", "/fact", "random_catfact"),
106
+ ]
107
+ async with start_service(routes) as service:
108
+ service.register(
109
+ "random_catfact",
110
+ JsonResponse({"fact": "test", "length": 4}),
111
+ )
112
+ yield service
113
+
114
+
115
+ @pytest.fixture
116
+ def catfact_url(catafact_service: MockService) -> URL:
117
+ return catafact_service.url
118
+
119
+
120
+ @pytest.fixture
121
+ async def catfact_client(catfact_url: URL) -> AsyncIterator[CatfactClient]:
122
+ async with ClientSession() as session:
123
+ client = CatfactClient(
124
+ client_name="catfact",
125
+ session=session,
126
+ url=catfact_url,
127
+ )
128
+ yield client
129
+
130
+ Now we can use them in tests. See full example in `examples/test_catfact_client.py`_
131
+
132
+ .. code-block:: python
133
+
134
+ async def test_fetch_random_catfact(catfact_client: CatfactClient) -> None:
135
+ # use default registered handler
136
+ fact = await catfact_client.fetch_random_cat_fact()
137
+ assert fact == CatfactSchema(fact="test", length=4)
138
+
139
+
140
+ async def test_fetch_random_catfact_timeout(
141
+ catfact_client: CatfactClient,
142
+ catafact_service: MockService,
143
+ ) -> None:
144
+ # change default registered handler to time error handler
145
+ catafact_service.register(
146
+ "random_catfact",
147
+ LatencyResponse(
148
+ wrapped=JsonResponse({"fact": "test", "length": 4}),
149
+ latency=1.5,
150
+ ),
151
+ )
152
+ with pytest.raises(asyncio.TimeoutError):
153
+ await catfact_client.fetch_random_cat_fact(timeout=1)
154
+
155
+
156
+ .. _PyPI: https://pypi.org/
157
+ .. _aiohttp: https://pypi.org/project/aiohttp/
158
+ .. _msgspec: https://github.com/jcrist/msgspec
159
+ .. _orjson: https://github.com/ijl/orjson
160
+ .. _pydantic: https://github.com/pydantic/pydantic
161
+
162
+ .. _examples/catfact_client.py: https://github.com/andy-takker/asyncly/blob/master/examples/catfact_client.py
163
+ .. _examples/test_catfact_client.py: https://github.com/andy-takker/asyncly/blob/master/examples/test_catfact_client.py
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "asyncly"
3
- version = "0.3.0"
3
+ version = "0.3.3"
4
4
  description = "Simple HTTP client and server for your integrations based on aiohttp"
5
5
  authors = ["Sergey Natalenko <sergey.natalenko@mail.ru>"]
6
6
  license = "MIT"
@@ -34,7 +34,7 @@ packages = [
34
34
 
35
35
  [tool.poetry.urls]
36
36
  "Source" = "https://github.com/andy-takker/asyncly"
37
- "Bug Tracker" = "https://github.com/andy-takker/v/issues"
37
+ "Bug Tracker" = "https://github.com/andy-takker/asyncly/issues"
38
38
 
39
39
  [tool.poetry.dependencies]
40
40
  python = "^3.10"
@@ -51,11 +51,12 @@ orjson = ["orjson"]
51
51
  [tool.poetry.group.dev.dependencies]
52
52
  pre-commit = ">=3.7.1,<5.0.0"
53
53
  mypy = "^1.10.1"
54
- ruff = ">=0.5.2,<0.8.0"
54
+ ruff = ">=0.5.2,<0.9.0"
55
55
  restructuredtext-lint = "^1.4.0"
56
56
  pygments = "^2.18.0"
57
57
  pytest = "^8.3.3"
58
58
  pytest-asyncio = "^0.24.0"
59
+ pytest-cov = "^6.0.0"
59
60
 
60
61
  [build-system]
61
62
  requires = ["poetry-core"]
asyncly-0.3.0/README.rst DELETED
@@ -1,104 +0,0 @@
1
- Asyncly
2
- =======
3
-
4
- .. image:: https://img.shields.io/pypi/v/asyncly.svg
5
- :target: https://pypi.python.org/pypi/asyncly/
6
- :alt: Latest Version
7
-
8
- .. image:: https://img.shields.io/pypi/wheel/base-http-client.svg
9
- :target: https://pypi.python.org/pypi/base-http-client/
10
-
11
- .. image:: https://img.shields.io/pypi/pyversions/base-http-client.svg
12
- :target: https://pypi.python.org/pypi/base-http-client/
13
-
14
- .. image:: https://img.shields.io/pypi/l/base-http-client.svg
15
- :target: https://pypi.python.org/pypi/base-http-client/
16
-
17
- Simple HTTP client and server for your integrations based on aiohttp_.
18
-
19
- Installation
20
- ------------
21
-
22
- Installation is possible in standard ways, such as PyPI or
23
- installation from a git repository directly.
24
-
25
- Installing from PyPI_:
26
-
27
- .. code-block:: bash
28
-
29
- pip install asyncly
30
-
31
- Installing from github.com:
32
-
33
- .. code-block:: bash
34
-
35
- pip install git+https://github.com/andy-takker/asyncly
36
-
37
- The package contains several extras and you can install additional dependencies
38
- if you specify them in this way.
39
-
40
- For example, with msgspec_:
41
-
42
- .. code-block:: bash
43
-
44
- pip install "asyncly[msgspec]"
45
-
46
- Complete table of extras below:
47
-
48
- +-------------------------------------+----------------------------------+
49
- | example | description |
50
- +========================================================================+
51
- | ``pip install "asyncly[msgspec]"`` | For using msgspec_ structs |
52
- +-------------------------------------+----------------------------------+
53
- | ``pip install "asyncly[orjson]"`` | For fast parsing json by orjson_ |
54
- +-------------------------------------+----------------------------------+
55
- | ``pip install "asyncly[pydantic]"`` | For using pydantic_ models |
56
- +-------------------------------------+----------------------------------+
57
-
58
- Quick start guide
59
- -----------------
60
-
61
- BaseHttpClient
62
- ~~~~~~~~~~~~~~
63
-
64
- Simple HTTP Client for `https://catfact.ninja`. See full example in `examples/catfact_client.py`_
65
-
66
- .. code-block:: python
67
-
68
- from base_http_client.client import (
69
- DEFAULT_TIMEOUT,
70
- BaseHttpClient,
71
- ResponseHandlersType,
72
- )
73
- from base_http_client.handlers.pydantic import parse_model
74
- from base_http_client.timeout import TimeoutType
75
-
76
-
77
- class CatfactClient(BaseHttpClient):
78
- RANDOM_CATFACT_HANDLERS: ResponseHandlersType = MappingProxyType(
79
- {
80
- HTTPStatus.OK: parse_model(CatfactSchema),
81
- }
82
- )
83
-
84
- async def fetch_random_cat_fact(
85
- self,
86
- timeout: TimeoutType = DEFAULT_TIMEOUT,
87
- ) -> CatfactSchema:
88
- return await self._make_req(
89
- method=hdrs.METH_GET,
90
- url=self._url / "fact",
91
- handlers=self.RANDOM_CATFACT_HANDLERS,
92
- timeout=timeout,
93
- )
94
-
95
-
96
-
97
-
98
- .. _PyPI: https://pypi.org/
99
- .. _aiohttp: https://pypi.org/project/aiohttp/
100
- .. _msgspec: https://github.com/jcrist/msgspec
101
- .. _orjson: https://github.com/ijl/orjson
102
- .. _pydantic: https://github.com/pydantic/pydantic
103
-
104
- .. _examples/catfact_client.py: https://github.com/andy-takker/asyncly/blob/master/examples/catfact_client.py
File without changes
File without changes
File without changes