mockarty 0.1.0__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.
- mockarty-0.1.0/.gitignore +29 -0
- mockarty-0.1.0/LICENSE +21 -0
- mockarty-0.1.0/PKG-INFO +232 -0
- mockarty-0.1.0/README.md +195 -0
- mockarty-0.1.0/pyproject.toml +61 -0
- mockarty-0.1.0/src/mockarty/__init__.py +207 -0
- mockarty-0.1.0/src/mockarty/_base_client.py +122 -0
- mockarty-0.1.0/src/mockarty/api/__init__.py +73 -0
- mockarty-0.1.0/src/mockarty/api/_base.py +75 -0
- mockarty-0.1.0/src/mockarty/api/agent_tasks.py +105 -0
- mockarty-0.1.0/src/mockarty/api/collections.py +86 -0
- mockarty-0.1.0/src/mockarty/api/contracts.py +328 -0
- mockarty-0.1.0/src/mockarty/api/environments.py +117 -0
- mockarty-0.1.0/src/mockarty/api/folders.py +92 -0
- mockarty-0.1.0/src/mockarty/api/fuzzing.py +436 -0
- mockarty-0.1.0/src/mockarty/api/generator.py +101 -0
- mockarty-0.1.0/src/mockarty/api/health.py +64 -0
- mockarty-0.1.0/src/mockarty/api/imports.py +66 -0
- mockarty-0.1.0/src/mockarty/api/mocks.py +396 -0
- mockarty-0.1.0/src/mockarty/api/namespace_settings.py +207 -0
- mockarty-0.1.0/src/mockarty/api/namespaces.py +80 -0
- mockarty-0.1.0/src/mockarty/api/perf.py +296 -0
- mockarty-0.1.0/src/mockarty/api/proxy.py +47 -0
- mockarty-0.1.0/src/mockarty/api/recorder.py +333 -0
- mockarty-0.1.0/src/mockarty/api/stats.py +57 -0
- mockarty-0.1.0/src/mockarty/api/stores.py +125 -0
- mockarty-0.1.0/src/mockarty/api/tags.py +48 -0
- mockarty-0.1.0/src/mockarty/api/templates.py +76 -0
- mockarty-0.1.0/src/mockarty/api/testruns.py +82 -0
- mockarty-0.1.0/src/mockarty/api/undefined.py +85 -0
- mockarty-0.1.0/src/mockarty/async_client.py +310 -0
- mockarty-0.1.0/src/mockarty/builders/__init__.py +7 -0
- mockarty-0.1.0/src/mockarty/builders/mock_builder.py +461 -0
- mockarty-0.1.0/src/mockarty/client.py +312 -0
- mockarty-0.1.0/src/mockarty/errors.py +56 -0
- mockarty-0.1.0/src/mockarty/models/__init__.py +120 -0
- mockarty-0.1.0/src/mockarty/models/admin.py +136 -0
- mockarty-0.1.0/src/mockarty/models/common.py +131 -0
- mockarty-0.1.0/src/mockarty/models/condition.py +50 -0
- mockarty-0.1.0/src/mockarty/models/contexts.py +180 -0
- mockarty-0.1.0/src/mockarty/models/contract.py +78 -0
- mockarty-0.1.0/src/mockarty/models/folders.py +23 -0
- mockarty-0.1.0/src/mockarty/models/fuzzing.py +45 -0
- mockarty-0.1.0/src/mockarty/models/generator.py +39 -0
- mockarty-0.1.0/src/mockarty/models/imports.py +20 -0
- mockarty-0.1.0/src/mockarty/models/mock.py +223 -0
- mockarty-0.1.0/src/mockarty/models/recorder.py +36 -0
- mockarty-0.1.0/src/mockarty/models/store.py +28 -0
- mockarty-0.1.0/src/mockarty/models/tags.py +21 -0
- mockarty-0.1.0/src/mockarty/models/templates.py +19 -0
- mockarty-0.1.0/src/mockarty/models/testrun.py +26 -0
- mockarty-0.1.0/src/mockarty/models/undefined.py +26 -0
- mockarty-0.1.0/src/mockarty/testing/__init__.py +7 -0
- mockarty-0.1.0/src/mockarty/testing/fixtures.py +73 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.egg-info/
|
|
6
|
+
dist/
|
|
7
|
+
build/
|
|
8
|
+
.eggs/
|
|
9
|
+
|
|
10
|
+
# Virtual environments
|
|
11
|
+
.venv/
|
|
12
|
+
venv/
|
|
13
|
+
env/
|
|
14
|
+
|
|
15
|
+
# Testing
|
|
16
|
+
.pytest_cache/
|
|
17
|
+
.coverage
|
|
18
|
+
htmlcov/
|
|
19
|
+
.tox/
|
|
20
|
+
|
|
21
|
+
# IDE
|
|
22
|
+
.idea/
|
|
23
|
+
.vscode/
|
|
24
|
+
*.swp
|
|
25
|
+
*.swo
|
|
26
|
+
|
|
27
|
+
# OS
|
|
28
|
+
.DS_Store
|
|
29
|
+
Thumbs.db
|
mockarty-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 Mockarty
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
mockarty-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mockarty
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official Python SDK for Mockarty — multi-protocol mock server for HTTP, gRPC, MCP, GraphQL, SOAP, SSE, Kafka, RabbitMQ, SMTP
|
|
5
|
+
Project-URL: Homepage, https://mockarty.ru
|
|
6
|
+
Project-URL: Documentation, https://mockarty.ru/docs
|
|
7
|
+
Project-URL: Repository, https://github.com/mockarty/py-sdk
|
|
8
|
+
Project-URL: Issues, https://github.com/mockarty/py-sdk/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/mockarty/py-sdk/releases
|
|
10
|
+
Author-email: Mockarty <info@mockarty.ru>
|
|
11
|
+
License: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: api,api-testing,contract-testing,fuzzing,graphql,grpc,kafka,mcp,mock,mock-server,performance-testing,rabbitmq,smtp,soap,sse,test-automation,testing,websocket
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Framework :: Pytest
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Topic :: Software Development :: Testing
|
|
25
|
+
Classifier: Topic :: Software Development :: Testing :: Mocking
|
|
26
|
+
Classifier: Typing :: Typed
|
|
27
|
+
Requires-Python: >=3.9
|
|
28
|
+
Requires-Dist: httpx>=0.24
|
|
29
|
+
Requires-Dist: pydantic>=2.0
|
|
30
|
+
Provides-Extra: async
|
|
31
|
+
Requires-Dist: httpx[http2]; extra == 'async'
|
|
32
|
+
Provides-Extra: test
|
|
33
|
+
Requires-Dist: pytest-asyncio>=0.21; extra == 'test'
|
|
34
|
+
Requires-Dist: pytest>=7.0; extra == 'test'
|
|
35
|
+
Requires-Dist: respx>=0.21; extra == 'test'
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
<p align="center">
|
|
39
|
+
<img src="logo.svg" alt="Mockarty" width="400">
|
|
40
|
+
</p>
|
|
41
|
+
|
|
42
|
+
<h1 align="center">Python SDK</h1>
|
|
43
|
+
|
|
44
|
+
<p align="center">
|
|
45
|
+
Official Python client library for <a href="https://mockarty.ru">Mockarty</a> — a multi-protocol mock server for HTTP, gRPC, MCP, GraphQL, SOAP, SSE, WebSocket, Kafka, RabbitMQ, and SMTP.
|
|
46
|
+
</p>
|
|
47
|
+
|
|
48
|
+
<p align="center">
|
|
49
|
+
<a href="https://pypi.org/project/mockarty/"><img src="https://img.shields.io/pypi/v/mockarty" alt="PyPI"></a>
|
|
50
|
+
<a href="https://pypi.org/project/mockarty/"><img src="https://img.shields.io/pypi/pyversions/mockarty" alt="Python"></a>
|
|
51
|
+
<a href="https://github.com/mockarty/py-sdk/blob/main/LICENSE"><img src="https://img.shields.io/github/license/mockarty/py-sdk" alt="License"></a>
|
|
52
|
+
</p>
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install mockarty
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
For async HTTP/2 support:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install mockarty[async]
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Quick Start
|
|
67
|
+
|
|
68
|
+
### Synchronous Client
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from mockarty import MockartyClient, MockBuilder, AssertAction
|
|
72
|
+
|
|
73
|
+
# Create a client
|
|
74
|
+
client = MockartyClient(
|
|
75
|
+
base_url="http://localhost:5770",
|
|
76
|
+
api_key="your-api-key",
|
|
77
|
+
namespace="sandbox",
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
# Create a mock using the builder
|
|
81
|
+
mock = (
|
|
82
|
+
MockBuilder.http("/api/users/:id", "GET")
|
|
83
|
+
.id("user-get")
|
|
84
|
+
.respond(200, body={"id": "$.pathParam.id", "name": "$.fake.FirstName"})
|
|
85
|
+
.ttl(3600)
|
|
86
|
+
.build()
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
result = client.mocks.create(mock)
|
|
90
|
+
print(f"Created mock: {result.mock.id}")
|
|
91
|
+
|
|
92
|
+
# List mocks
|
|
93
|
+
page = client.mocks.list(namespace="sandbox", limit=10)
|
|
94
|
+
for m in page.items:
|
|
95
|
+
print(f" {m.id}")
|
|
96
|
+
|
|
97
|
+
# Health check
|
|
98
|
+
health = client.health.check()
|
|
99
|
+
print(f"Status: {health.status}")
|
|
100
|
+
|
|
101
|
+
client.close()
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Async Client
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
import asyncio
|
|
108
|
+
from mockarty import AsyncMockartyClient, MockBuilder
|
|
109
|
+
|
|
110
|
+
async def main():
|
|
111
|
+
async with AsyncMockartyClient(base_url="http://localhost:5770") as client:
|
|
112
|
+
mock = MockBuilder.http("/api/hello", "GET").respond(200, body={"msg": "hello"}).build()
|
|
113
|
+
result = await client.mocks.create(mock)
|
|
114
|
+
print(f"Created: {result.mock.id}")
|
|
115
|
+
|
|
116
|
+
asyncio.run(main())
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Context Manager
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
with MockartyClient() as client:
|
|
123
|
+
client.mocks.create(mock)
|
|
124
|
+
# client.close() is called automatically
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Mock Builder
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
from mockarty import MockBuilder, AssertAction
|
|
131
|
+
|
|
132
|
+
# HTTP mock with conditions
|
|
133
|
+
mock = (
|
|
134
|
+
MockBuilder.http("/api/orders", "POST")
|
|
135
|
+
.id("create-order")
|
|
136
|
+
.namespace("production")
|
|
137
|
+
.tags("orders", "v2")
|
|
138
|
+
.priority(10)
|
|
139
|
+
.condition("$.body.amount", AssertAction.NOT_EMPTY)
|
|
140
|
+
.header_condition("Authorization", AssertAction.NOT_EMPTY)
|
|
141
|
+
.respond(201, body={
|
|
142
|
+
"orderId": "$.fake.UUID",
|
|
143
|
+
"amount": "$.req.amount",
|
|
144
|
+
"status": "created",
|
|
145
|
+
})
|
|
146
|
+
.callback("https://webhook.site/test", method="POST", body={"event": "order.created"})
|
|
147
|
+
.ttl(7200)
|
|
148
|
+
.build()
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
# gRPC mock
|
|
152
|
+
grpc_mock = (
|
|
153
|
+
MockBuilder.grpc("user.UserService", "GetUser")
|
|
154
|
+
.id("grpc-get-user")
|
|
155
|
+
.condition("$.id", AssertAction.NOT_EMPTY)
|
|
156
|
+
.respond(200, body={"id": "$.req.id", "name": "$.fake.FirstName"})
|
|
157
|
+
.build()
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
# MCP mock
|
|
161
|
+
mcp_mock = (
|
|
162
|
+
MockBuilder.mcp("get_weather")
|
|
163
|
+
.id("mcp-weather")
|
|
164
|
+
.respond(200, body={"temperature": 22, "city": "$.req.city"})
|
|
165
|
+
.build()
|
|
166
|
+
)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Working with Stores
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
with MockartyClient() as client:
|
|
173
|
+
# Global store
|
|
174
|
+
client.stores.global_set("counter", 0)
|
|
175
|
+
data = client.stores.global_get()
|
|
176
|
+
print(data) # {"counter": 0}
|
|
177
|
+
|
|
178
|
+
# Chain store
|
|
179
|
+
client.stores.chain_set("order-flow", "orderId", "abc-123")
|
|
180
|
+
chain_data = client.stores.chain_get("order-flow")
|
|
181
|
+
print(chain_data) # {"orderId": "abc-123"}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Error Handling
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
from mockarty import MockartyClient
|
|
188
|
+
from mockarty.errors import MockartyNotFoundError, MockartyAPIError
|
|
189
|
+
|
|
190
|
+
client = MockartyClient()
|
|
191
|
+
try:
|
|
192
|
+
mock = client.mocks.get("non-existent")
|
|
193
|
+
except MockartyNotFoundError:
|
|
194
|
+
print("Mock not found")
|
|
195
|
+
except MockartyAPIError as e:
|
|
196
|
+
print(f"API error {e.status_code}: {e.message}")
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## Configuration
|
|
200
|
+
|
|
201
|
+
The client reads these environment variables as defaults:
|
|
202
|
+
|
|
203
|
+
| Variable | Description | Default |
|
|
204
|
+
|---|---|---|
|
|
205
|
+
| `MOCKARTY_BASE_URL` | Mockarty server URL | `http://localhost:5770` |
|
|
206
|
+
| `MOCKARTY_API_KEY` | API authentication key | `None` |
|
|
207
|
+
|
|
208
|
+
## pytest Integration
|
|
209
|
+
|
|
210
|
+
Install the test extras:
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
pip install mockarty[test]
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Use the provided fixtures in your tests:
|
|
217
|
+
|
|
218
|
+
```python
|
|
219
|
+
# conftest.py
|
|
220
|
+
pytest_plugins = ["mockarty.testing.fixtures"]
|
|
221
|
+
|
|
222
|
+
# test_example.py
|
|
223
|
+
def test_create_mock(mock_cleanup):
|
|
224
|
+
from mockarty import MockBuilder
|
|
225
|
+
mock = MockBuilder.http("/test", "GET").respond(200, body="ok").build()
|
|
226
|
+
created = mock_cleanup(mock)
|
|
227
|
+
assert created.id is not None
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## License
|
|
231
|
+
|
|
232
|
+
MIT
|
mockarty-0.1.0/README.md
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="logo.svg" alt="Mockarty" width="400">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">Python SDK</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
Official Python client library for <a href="https://mockarty.ru">Mockarty</a> — a multi-protocol mock server for HTTP, gRPC, MCP, GraphQL, SOAP, SSE, WebSocket, Kafka, RabbitMQ, and SMTP.
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://pypi.org/project/mockarty/"><img src="https://img.shields.io/pypi/v/mockarty" alt="PyPI"></a>
|
|
13
|
+
<a href="https://pypi.org/project/mockarty/"><img src="https://img.shields.io/pypi/pyversions/mockarty" alt="Python"></a>
|
|
14
|
+
<a href="https://github.com/mockarty/py-sdk/blob/main/LICENSE"><img src="https://img.shields.io/github/license/mockarty/py-sdk" alt="License"></a>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install mockarty
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
For async HTTP/2 support:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install mockarty[async]
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
### Synchronous Client
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from mockarty import MockartyClient, MockBuilder, AssertAction
|
|
35
|
+
|
|
36
|
+
# Create a client
|
|
37
|
+
client = MockartyClient(
|
|
38
|
+
base_url="http://localhost:5770",
|
|
39
|
+
api_key="your-api-key",
|
|
40
|
+
namespace="sandbox",
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
# Create a mock using the builder
|
|
44
|
+
mock = (
|
|
45
|
+
MockBuilder.http("/api/users/:id", "GET")
|
|
46
|
+
.id("user-get")
|
|
47
|
+
.respond(200, body={"id": "$.pathParam.id", "name": "$.fake.FirstName"})
|
|
48
|
+
.ttl(3600)
|
|
49
|
+
.build()
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
result = client.mocks.create(mock)
|
|
53
|
+
print(f"Created mock: {result.mock.id}")
|
|
54
|
+
|
|
55
|
+
# List mocks
|
|
56
|
+
page = client.mocks.list(namespace="sandbox", limit=10)
|
|
57
|
+
for m in page.items:
|
|
58
|
+
print(f" {m.id}")
|
|
59
|
+
|
|
60
|
+
# Health check
|
|
61
|
+
health = client.health.check()
|
|
62
|
+
print(f"Status: {health.status}")
|
|
63
|
+
|
|
64
|
+
client.close()
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Async Client
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
import asyncio
|
|
71
|
+
from mockarty import AsyncMockartyClient, MockBuilder
|
|
72
|
+
|
|
73
|
+
async def main():
|
|
74
|
+
async with AsyncMockartyClient(base_url="http://localhost:5770") as client:
|
|
75
|
+
mock = MockBuilder.http("/api/hello", "GET").respond(200, body={"msg": "hello"}).build()
|
|
76
|
+
result = await client.mocks.create(mock)
|
|
77
|
+
print(f"Created: {result.mock.id}")
|
|
78
|
+
|
|
79
|
+
asyncio.run(main())
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Context Manager
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
with MockartyClient() as client:
|
|
86
|
+
client.mocks.create(mock)
|
|
87
|
+
# client.close() is called automatically
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Mock Builder
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from mockarty import MockBuilder, AssertAction
|
|
94
|
+
|
|
95
|
+
# HTTP mock with conditions
|
|
96
|
+
mock = (
|
|
97
|
+
MockBuilder.http("/api/orders", "POST")
|
|
98
|
+
.id("create-order")
|
|
99
|
+
.namespace("production")
|
|
100
|
+
.tags("orders", "v2")
|
|
101
|
+
.priority(10)
|
|
102
|
+
.condition("$.body.amount", AssertAction.NOT_EMPTY)
|
|
103
|
+
.header_condition("Authorization", AssertAction.NOT_EMPTY)
|
|
104
|
+
.respond(201, body={
|
|
105
|
+
"orderId": "$.fake.UUID",
|
|
106
|
+
"amount": "$.req.amount",
|
|
107
|
+
"status": "created",
|
|
108
|
+
})
|
|
109
|
+
.callback("https://webhook.site/test", method="POST", body={"event": "order.created"})
|
|
110
|
+
.ttl(7200)
|
|
111
|
+
.build()
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
# gRPC mock
|
|
115
|
+
grpc_mock = (
|
|
116
|
+
MockBuilder.grpc("user.UserService", "GetUser")
|
|
117
|
+
.id("grpc-get-user")
|
|
118
|
+
.condition("$.id", AssertAction.NOT_EMPTY)
|
|
119
|
+
.respond(200, body={"id": "$.req.id", "name": "$.fake.FirstName"})
|
|
120
|
+
.build()
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
# MCP mock
|
|
124
|
+
mcp_mock = (
|
|
125
|
+
MockBuilder.mcp("get_weather")
|
|
126
|
+
.id("mcp-weather")
|
|
127
|
+
.respond(200, body={"temperature": 22, "city": "$.req.city"})
|
|
128
|
+
.build()
|
|
129
|
+
)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Working with Stores
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
with MockartyClient() as client:
|
|
136
|
+
# Global store
|
|
137
|
+
client.stores.global_set("counter", 0)
|
|
138
|
+
data = client.stores.global_get()
|
|
139
|
+
print(data) # {"counter": 0}
|
|
140
|
+
|
|
141
|
+
# Chain store
|
|
142
|
+
client.stores.chain_set("order-flow", "orderId", "abc-123")
|
|
143
|
+
chain_data = client.stores.chain_get("order-flow")
|
|
144
|
+
print(chain_data) # {"orderId": "abc-123"}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Error Handling
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
from mockarty import MockartyClient
|
|
151
|
+
from mockarty.errors import MockartyNotFoundError, MockartyAPIError
|
|
152
|
+
|
|
153
|
+
client = MockartyClient()
|
|
154
|
+
try:
|
|
155
|
+
mock = client.mocks.get("non-existent")
|
|
156
|
+
except MockartyNotFoundError:
|
|
157
|
+
print("Mock not found")
|
|
158
|
+
except MockartyAPIError as e:
|
|
159
|
+
print(f"API error {e.status_code}: {e.message}")
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Configuration
|
|
163
|
+
|
|
164
|
+
The client reads these environment variables as defaults:
|
|
165
|
+
|
|
166
|
+
| Variable | Description | Default |
|
|
167
|
+
|---|---|---|
|
|
168
|
+
| `MOCKARTY_BASE_URL` | Mockarty server URL | `http://localhost:5770` |
|
|
169
|
+
| `MOCKARTY_API_KEY` | API authentication key | `None` |
|
|
170
|
+
|
|
171
|
+
## pytest Integration
|
|
172
|
+
|
|
173
|
+
Install the test extras:
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
pip install mockarty[test]
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Use the provided fixtures in your tests:
|
|
180
|
+
|
|
181
|
+
```python
|
|
182
|
+
# conftest.py
|
|
183
|
+
pytest_plugins = ["mockarty.testing.fixtures"]
|
|
184
|
+
|
|
185
|
+
# test_example.py
|
|
186
|
+
def test_create_mock(mock_cleanup):
|
|
187
|
+
from mockarty import MockBuilder
|
|
188
|
+
mock = MockBuilder.http("/test", "GET").respond(200, body="ok").build()
|
|
189
|
+
created = mock_cleanup(mock)
|
|
190
|
+
assert created.id is not None
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## License
|
|
194
|
+
|
|
195
|
+
MIT
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "mockarty"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Official Python SDK for Mockarty — multi-protocol mock server for HTTP, gRPC, MCP, GraphQL, SOAP, SSE, Kafka, RabbitMQ, SMTP"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
authors = [{name = "Mockarty", email = "info@mockarty.ru"}]
|
|
13
|
+
keywords = [
|
|
14
|
+
"mock", "testing", "api", "grpc", "mcp", "graphql", "soap",
|
|
15
|
+
"kafka", "rabbitmq", "smtp", "sse", "websocket",
|
|
16
|
+
"contract-testing", "fuzzing", "performance-testing",
|
|
17
|
+
"api-testing", "mock-server", "test-automation",
|
|
18
|
+
]
|
|
19
|
+
classifiers = [
|
|
20
|
+
"Development Status :: 4 - Beta",
|
|
21
|
+
"Intended Audience :: Developers",
|
|
22
|
+
"License :: OSI Approved :: MIT License",
|
|
23
|
+
"Programming Language :: Python :: 3",
|
|
24
|
+
"Programming Language :: Python :: 3.9",
|
|
25
|
+
"Programming Language :: Python :: 3.10",
|
|
26
|
+
"Programming Language :: Python :: 3.11",
|
|
27
|
+
"Programming Language :: Python :: 3.12",
|
|
28
|
+
"Programming Language :: Python :: 3.13",
|
|
29
|
+
"Topic :: Software Development :: Testing",
|
|
30
|
+
"Topic :: Software Development :: Testing :: Mocking",
|
|
31
|
+
"Framework :: Pytest",
|
|
32
|
+
"Typing :: Typed",
|
|
33
|
+
]
|
|
34
|
+
dependencies = [
|
|
35
|
+
"httpx>=0.24",
|
|
36
|
+
"pydantic>=2.0",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[project.optional-dependencies]
|
|
40
|
+
async = ["httpx[http2]"]
|
|
41
|
+
test = ["pytest>=7.0", "pytest-asyncio>=0.21", "respx>=0.21"]
|
|
42
|
+
|
|
43
|
+
[project.urls]
|
|
44
|
+
Homepage = "https://mockarty.ru"
|
|
45
|
+
Documentation = "https://mockarty.ru/docs"
|
|
46
|
+
Repository = "https://github.com/mockarty/py-sdk"
|
|
47
|
+
Issues = "https://github.com/mockarty/py-sdk/issues"
|
|
48
|
+
Changelog = "https://github.com/mockarty/py-sdk/releases"
|
|
49
|
+
|
|
50
|
+
[project.entry-points.pytest11]
|
|
51
|
+
mockarty = "mockarty.testing.fixtures"
|
|
52
|
+
|
|
53
|
+
[tool.hatch.build.targets.wheel]
|
|
54
|
+
packages = ["src/mockarty"]
|
|
55
|
+
|
|
56
|
+
[tool.hatch.build.targets.sdist]
|
|
57
|
+
include = ["src/mockarty", "LICENSE", "README.md"]
|
|
58
|
+
|
|
59
|
+
[tool.pytest.ini_options]
|
|
60
|
+
testpaths = ["tests"]
|
|
61
|
+
asyncio_mode = "auto"
|