mockly-driver 0.4.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.
@@ -0,0 +1,56 @@
1
+ # Binaries
2
+ /mockly
3
+ /mockly.exe
4
+ dist/
5
+
6
+ # UI build
7
+ ui/dist/
8
+ ui/node_modules/
9
+
10
+ # Assets (built by make)
11
+ assets/dist/
12
+
13
+ # Go
14
+ *.test
15
+ *.out
16
+ vendor/
17
+ coverage.txt
18
+
19
+ # IDE
20
+ .idea/
21
+ .vscode/
22
+ *.swp
23
+
24
+ # OS
25
+ .DS_Store
26
+ Thumbs.db
27
+
28
+ # Config (user-specific, not example)
29
+ mockly.yaml
30
+
31
+ # Node client
32
+ clients/node/node_modules/
33
+ clients/node/dist/
34
+ clients/node/bin/
35
+
36
+ # Python client
37
+ clients/python/.pytest_cache/
38
+ clients/python/__pycache__/
39
+ clients/python/src/**/__pycache__/
40
+ clients/python/*.egg-info/
41
+ clients/python/dist/
42
+ clients/python/.venv/
43
+
44
+ # Python cache (all locations)
45
+ **/__pycache__/
46
+ **/*.pyc
47
+
48
+ # Java client
49
+ clients/java/target/
50
+
51
+ # .NET client
52
+ clients/dotnet/**/bin/
53
+ clients/dotnet/**/obj/
54
+
55
+ # Rust client
56
+ clients/rust/target/
@@ -0,0 +1,30 @@
1
+ # Changelog
2
+
3
+ All notable changes to **mockly-driver** will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ---
9
+
10
+ ## [0.1.0] - 2024-01-01
11
+
12
+ ### Added
13
+
14
+ - `MocklyServer.create()` — start a Mockly server using an already-installed binary; retries up to 3× on port conflicts.
15
+ - `MocklyServer.ensure()` — download binary if needed, then start the server.
16
+ - `MocklyServer.stop()` — kill the Mockly process and clean up the temp config file.
17
+ - `MocklyServer.add_mock()` — register a dynamic HTTP mock at runtime.
18
+ - `MocklyServer.delete_mock()` — remove a mock by ID.
19
+ - `MocklyServer.reset()` — remove all dynamic mocks, deactivate scenarios, and clear faults.
20
+ - `MocklyServer.activate_scenario()` / `deactivate_scenario()` — toggle pre-configured scenarios.
21
+ - `MocklyServer.set_fault()` / `clear_fault()` — inject latency, status overrides, and error rates.
22
+ - `install()` — download the platform-correct Mockly binary with proxy and mirror support.
23
+ - `get_binary_path()` — locate an existing binary via `MOCKLY_BINARY_PATH`, explicit dir, or `./bin/`.
24
+ - `mockly-install` CLI entry point for one-step binary setup.
25
+ - Dataclasses: `Mock`, `MockRequest`, `MockResponse`, `Scenario`, `ScenarioPatch`, `FaultConfig`.
26
+ - Environment variable support: `MOCKLY_BINARY_PATH`, `MOCKLY_VERSION`, `MOCKLY_DOWNLOAD_BASE_URL`, `MOCKLY_NO_INSTALL`, `HTTPS_PROXY`, `HTTP_PROXY`.
27
+ - Stdlib-only runtime — no third-party dependencies.
28
+ - pytest unit tests covering port allocation, binary discovery, and install guards.
29
+
30
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 dever-labs
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.
@@ -0,0 +1,239 @@
1
+ Metadata-Version: 2.4
2
+ Name: mockly-driver
3
+ Version: 0.4.3
4
+ Summary: Python client for Mockly — start/stop servers and manage HTTP mocks in tests
5
+ Project-URL: Homepage, https://github.com/dever-labs/mockly/tree/main/clients/python
6
+ Project-URL: Repository, https://github.com/dever-labs/mockly
7
+ Project-URL: Issues, https://github.com/dever-labs/mockly/issues
8
+ License: MIT
9
+ License-File: LICENSE
10
+ Keywords: http,integration-test,mock,mockly,testing
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Software Development :: Testing
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+
17
+ # mockly-driver
18
+
19
+ Python client for [Mockly](https://github.com/dever-labs/mockly) — download, start, and control a Mockly mock HTTP server from your Python/pytest test suite.
20
+
21
+ ---
22
+
23
+ ## Table of Contents
24
+
25
+ - [Installation](#installation)
26
+ - [Quick Start](#quick-start)
27
+ - [API Reference](#api-reference)
28
+ - [Environment Variables](#environment-variables)
29
+ - [Proxy / Artifactory / Air-gap](#proxy--artifactory--air-gap)
30
+ - [CLI](#cli)
31
+
32
+ ---
33
+
34
+ ## Installation
35
+
36
+ ```bash
37
+ pip install mockly-driver
38
+ ```
39
+
40
+ Then download the Mockly binary once:
41
+
42
+ ```bash
43
+ mockly-install
44
+ # binary is placed in ./bin/mockly (or ./bin/mockly.exe on Windows)
45
+ ```
46
+
47
+ ---
48
+
49
+ ## Quick Start
50
+
51
+ ### pytest fixture
52
+
53
+ ```python
54
+ import pytest
55
+ from mockly_driver import MocklyServer, Mock, MockRequest, MockResponse
56
+
57
+ @pytest.fixture(scope="session")
58
+ def mockly():
59
+ # Downloads binary if needed, then starts the server
60
+ server = MocklyServer.ensure()
61
+ yield server
62
+ server.stop()
63
+
64
+ def test_my_service(mockly):
65
+ mockly.add_mock(Mock(
66
+ id="get-users",
67
+ request=MockRequest(method="GET", path="/users"),
68
+ response=MockResponse(status=200, body='[{"id":1}]',
69
+ headers={"Content-Type": "application/json"}),
70
+ ))
71
+
72
+ # Your service under test talks to mockly.http_base
73
+ import urllib.request
74
+ with urllib.request.urlopen(f"{mockly.http_base}/users") as resp:
75
+ assert resp.status == 200
76
+
77
+ mockly.reset()
78
+ ```
79
+
80
+ ### Scenarios
81
+
82
+ ```python
83
+ from mockly_driver import Scenario, ScenarioPatch
84
+
85
+ server = MocklyServer.ensure(
86
+ scenarios=[
87
+ Scenario(
88
+ id="slow-api",
89
+ name="Slow API",
90
+ patches=[ScenarioPatch(mock_id="get-users", delay="2s")],
91
+ )
92
+ ]
93
+ )
94
+
95
+ server.activate_scenario("slow-api")
96
+ # ... run slow-path tests ...
97
+ server.deactivate_scenario("slow-api")
98
+ ```
99
+
100
+ ### Faults
101
+
102
+ ```python
103
+ from mockly_driver import FaultConfig
104
+
105
+ server.set_fault(FaultConfig(enabled=True, status_override=503, error_rate=0.5))
106
+ # ... run fault-tolerance tests ...
107
+ server.clear_fault()
108
+ ```
109
+
110
+ ---
111
+
112
+ ## API Reference
113
+
114
+ ### `MocklyServer.ensure(scenarios=None, **install_kwargs) -> MocklyServer`
115
+
116
+ Downloads the binary (if not already present) and starts the server.
117
+ `install_kwargs` are forwarded to `install()` — see below.
118
+
119
+ ### `MocklyServer.create(scenarios=None) -> MocklyServer`
120
+
121
+ Starts the server using an already-installed binary.
122
+ Raises `RuntimeError` if no binary is found.
123
+
124
+ ### `server.stop() -> None`
125
+
126
+ Kills the Mockly process and removes the temp config file.
127
+
128
+ ### `server.add_mock(mock: Mock) -> None`
129
+
130
+ Registers a new HTTP mock at runtime.
131
+
132
+ ```python
133
+ Mock(
134
+ id="my-mock",
135
+ request=MockRequest(method="POST", path="/echo",
136
+ headers={"X-Api-Key": "secret"}),
137
+ response=MockResponse(status=201, body='{"ok":true}',
138
+ headers={"Content-Type": "application/json"},
139
+ delay="10ms"),
140
+ )
141
+ ```
142
+
143
+ ### `server.delete_mock(mock_id: str) -> None`
144
+
145
+ Removes a previously registered mock by ID.
146
+
147
+ ### `server.reset() -> None`
148
+
149
+ Removes all dynamic mocks, deactivates all scenarios, and clears any active fault.
150
+
151
+ ### `server.activate_scenario(scenario_id: str) -> None`
152
+
153
+ Activates a pre-configured scenario.
154
+
155
+ ### `server.deactivate_scenario(scenario_id: str) -> None`
156
+
157
+ Deactivates a scenario.
158
+
159
+ ### `server.set_fault(config: FaultConfig) -> None`
160
+
161
+ Enables a fault injection policy.
162
+
163
+ ```python
164
+ FaultConfig(
165
+ enabled=True,
166
+ delay="200ms", # add latency to all responses
167
+ status_override=503, # force every response to 503
168
+ error_rate=0.3, # randomly fail 30% of requests
169
+ )
170
+ ```
171
+
172
+ ### `server.clear_fault() -> None`
173
+
174
+ Removes the active fault policy.
175
+
176
+ ### `install(version=None, base_url=None, bin_dir=None, force=False) -> str`
177
+
178
+ Downloads the Mockly binary for the current platform. Returns the path.
179
+
180
+ ### `get_binary_path(bin_dir=None) -> str | None`
181
+
182
+ Returns the path to an existing binary, or `None` if not found.
183
+
184
+ ---
185
+
186
+ ## Environment Variables
187
+
188
+ | Variable | Description | Default |
189
+ |---|---|---|
190
+ | `MOCKLY_BINARY_PATH` | Absolute path to a pre-staged binary — skips all download logic | — |
191
+ | `MOCKLY_VERSION` | Binary version to download | `v0.1.0` |
192
+ | `MOCKLY_DOWNLOAD_BASE_URL` | Override the GitHub releases base URL (for mirrors/Artifactory) | `https://github.com/dever-labs/mockly/releases/download` |
193
+ | `MOCKLY_NO_INSTALL` | If set, `install()` raises `RuntimeError` instead of downloading | — |
194
+ | `HTTPS_PROXY` / `HTTP_PROXY` | Route downloads through an HTTP proxy | — |
195
+
196
+ ---
197
+
198
+ ## Proxy / Artifactory / Air-gap
199
+
200
+ ### HTTP/HTTPS proxy
201
+
202
+ ```bash
203
+ export HTTPS_PROXY=http://proxy.corp.example.com:3128
204
+ mockly-install
205
+ ```
206
+
207
+ ### Internal mirror / Artifactory
208
+
209
+ Set `MOCKLY_DOWNLOAD_BASE_URL` to your internal artifact repository:
210
+
211
+ ```bash
212
+ export MOCKLY_DOWNLOAD_BASE_URL=https://artifactory.corp.example.com/mockly/releases/download
213
+ mockly-install
214
+ ```
215
+
216
+ ### Air-gap / pre-staged binary
217
+
218
+ Copy the binary for your platform to a known location and set:
219
+
220
+ ```bash
221
+ export MOCKLY_BINARY_PATH=/opt/mockly/mockly
222
+ export MOCKLY_NO_INSTALL=1 # optional: prevents accidental downloads
223
+ ```
224
+
225
+ ---
226
+
227
+ ## CLI
228
+
229
+ ```
230
+ mockly-install [--version VERSION] [--base-url URL] [--bin-dir DIR] [--force]
231
+ ```
232
+
233
+ Downloads the platform binary to `<bin-dir>/mockly[.exe]` (default: `./bin/`).
234
+
235
+ ---
236
+
237
+ ## License
238
+
239
+ MIT © dever-labs
@@ -0,0 +1,223 @@
1
+ # mockly-driver
2
+
3
+ Python client for [Mockly](https://github.com/dever-labs/mockly) — download, start, and control a Mockly mock HTTP server from your Python/pytest test suite.
4
+
5
+ ---
6
+
7
+ ## Table of Contents
8
+
9
+ - [Installation](#installation)
10
+ - [Quick Start](#quick-start)
11
+ - [API Reference](#api-reference)
12
+ - [Environment Variables](#environment-variables)
13
+ - [Proxy / Artifactory / Air-gap](#proxy--artifactory--air-gap)
14
+ - [CLI](#cli)
15
+
16
+ ---
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ pip install mockly-driver
22
+ ```
23
+
24
+ Then download the Mockly binary once:
25
+
26
+ ```bash
27
+ mockly-install
28
+ # binary is placed in ./bin/mockly (or ./bin/mockly.exe on Windows)
29
+ ```
30
+
31
+ ---
32
+
33
+ ## Quick Start
34
+
35
+ ### pytest fixture
36
+
37
+ ```python
38
+ import pytest
39
+ from mockly_driver import MocklyServer, Mock, MockRequest, MockResponse
40
+
41
+ @pytest.fixture(scope="session")
42
+ def mockly():
43
+ # Downloads binary if needed, then starts the server
44
+ server = MocklyServer.ensure()
45
+ yield server
46
+ server.stop()
47
+
48
+ def test_my_service(mockly):
49
+ mockly.add_mock(Mock(
50
+ id="get-users",
51
+ request=MockRequest(method="GET", path="/users"),
52
+ response=MockResponse(status=200, body='[{"id":1}]',
53
+ headers={"Content-Type": "application/json"}),
54
+ ))
55
+
56
+ # Your service under test talks to mockly.http_base
57
+ import urllib.request
58
+ with urllib.request.urlopen(f"{mockly.http_base}/users") as resp:
59
+ assert resp.status == 200
60
+
61
+ mockly.reset()
62
+ ```
63
+
64
+ ### Scenarios
65
+
66
+ ```python
67
+ from mockly_driver import Scenario, ScenarioPatch
68
+
69
+ server = MocklyServer.ensure(
70
+ scenarios=[
71
+ Scenario(
72
+ id="slow-api",
73
+ name="Slow API",
74
+ patches=[ScenarioPatch(mock_id="get-users", delay="2s")],
75
+ )
76
+ ]
77
+ )
78
+
79
+ server.activate_scenario("slow-api")
80
+ # ... run slow-path tests ...
81
+ server.deactivate_scenario("slow-api")
82
+ ```
83
+
84
+ ### Faults
85
+
86
+ ```python
87
+ from mockly_driver import FaultConfig
88
+
89
+ server.set_fault(FaultConfig(enabled=True, status_override=503, error_rate=0.5))
90
+ # ... run fault-tolerance tests ...
91
+ server.clear_fault()
92
+ ```
93
+
94
+ ---
95
+
96
+ ## API Reference
97
+
98
+ ### `MocklyServer.ensure(scenarios=None, **install_kwargs) -> MocklyServer`
99
+
100
+ Downloads the binary (if not already present) and starts the server.
101
+ `install_kwargs` are forwarded to `install()` — see below.
102
+
103
+ ### `MocklyServer.create(scenarios=None) -> MocklyServer`
104
+
105
+ Starts the server using an already-installed binary.
106
+ Raises `RuntimeError` if no binary is found.
107
+
108
+ ### `server.stop() -> None`
109
+
110
+ Kills the Mockly process and removes the temp config file.
111
+
112
+ ### `server.add_mock(mock: Mock) -> None`
113
+
114
+ Registers a new HTTP mock at runtime.
115
+
116
+ ```python
117
+ Mock(
118
+ id="my-mock",
119
+ request=MockRequest(method="POST", path="/echo",
120
+ headers={"X-Api-Key": "secret"}),
121
+ response=MockResponse(status=201, body='{"ok":true}',
122
+ headers={"Content-Type": "application/json"},
123
+ delay="10ms"),
124
+ )
125
+ ```
126
+
127
+ ### `server.delete_mock(mock_id: str) -> None`
128
+
129
+ Removes a previously registered mock by ID.
130
+
131
+ ### `server.reset() -> None`
132
+
133
+ Removes all dynamic mocks, deactivates all scenarios, and clears any active fault.
134
+
135
+ ### `server.activate_scenario(scenario_id: str) -> None`
136
+
137
+ Activates a pre-configured scenario.
138
+
139
+ ### `server.deactivate_scenario(scenario_id: str) -> None`
140
+
141
+ Deactivates a scenario.
142
+
143
+ ### `server.set_fault(config: FaultConfig) -> None`
144
+
145
+ Enables a fault injection policy.
146
+
147
+ ```python
148
+ FaultConfig(
149
+ enabled=True,
150
+ delay="200ms", # add latency to all responses
151
+ status_override=503, # force every response to 503
152
+ error_rate=0.3, # randomly fail 30% of requests
153
+ )
154
+ ```
155
+
156
+ ### `server.clear_fault() -> None`
157
+
158
+ Removes the active fault policy.
159
+
160
+ ### `install(version=None, base_url=None, bin_dir=None, force=False) -> str`
161
+
162
+ Downloads the Mockly binary for the current platform. Returns the path.
163
+
164
+ ### `get_binary_path(bin_dir=None) -> str | None`
165
+
166
+ Returns the path to an existing binary, or `None` if not found.
167
+
168
+ ---
169
+
170
+ ## Environment Variables
171
+
172
+ | Variable | Description | Default |
173
+ |---|---|---|
174
+ | `MOCKLY_BINARY_PATH` | Absolute path to a pre-staged binary — skips all download logic | — |
175
+ | `MOCKLY_VERSION` | Binary version to download | `v0.1.0` |
176
+ | `MOCKLY_DOWNLOAD_BASE_URL` | Override the GitHub releases base URL (for mirrors/Artifactory) | `https://github.com/dever-labs/mockly/releases/download` |
177
+ | `MOCKLY_NO_INSTALL` | If set, `install()` raises `RuntimeError` instead of downloading | — |
178
+ | `HTTPS_PROXY` / `HTTP_PROXY` | Route downloads through an HTTP proxy | — |
179
+
180
+ ---
181
+
182
+ ## Proxy / Artifactory / Air-gap
183
+
184
+ ### HTTP/HTTPS proxy
185
+
186
+ ```bash
187
+ export HTTPS_PROXY=http://proxy.corp.example.com:3128
188
+ mockly-install
189
+ ```
190
+
191
+ ### Internal mirror / Artifactory
192
+
193
+ Set `MOCKLY_DOWNLOAD_BASE_URL` to your internal artifact repository:
194
+
195
+ ```bash
196
+ export MOCKLY_DOWNLOAD_BASE_URL=https://artifactory.corp.example.com/mockly/releases/download
197
+ mockly-install
198
+ ```
199
+
200
+ ### Air-gap / pre-staged binary
201
+
202
+ Copy the binary for your platform to a known location and set:
203
+
204
+ ```bash
205
+ export MOCKLY_BINARY_PATH=/opt/mockly/mockly
206
+ export MOCKLY_NO_INSTALL=1 # optional: prevents accidental downloads
207
+ ```
208
+
209
+ ---
210
+
211
+ ## CLI
212
+
213
+ ```
214
+ mockly-install [--version VERSION] [--base-url URL] [--bin-dir DIR] [--force]
215
+ ```
216
+
217
+ Downloads the platform binary to `<bin-dir>/mockly[.exe]` (default: `./bin/`).
218
+
219
+ ---
220
+
221
+ ## License
222
+
223
+ MIT © dever-labs
@@ -0,0 +1,32 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "mockly-driver"
7
+ version = "0.4.3"
8
+ description = "Python client for Mockly — start/stop servers and manage HTTP mocks in tests"
9
+ readme = "README.md"
10
+ license = { text = "MIT" }
11
+ requires-python = ">=3.10"
12
+ keywords = ["mock", "testing", "http", "integration-test", "mockly"]
13
+ classifiers = [
14
+ "Programming Language :: Python :: 3",
15
+ "License :: OSI Approved :: MIT License",
16
+ "Topic :: Software Development :: Testing",
17
+ ]
18
+ dependencies = [] # stdlib only
19
+
20
+ [project.urls]
21
+ Homepage = "https://github.com/dever-labs/mockly/tree/main/clients/python"
22
+ Repository = "https://github.com/dever-labs/mockly"
23
+ Issues = "https://github.com/dever-labs/mockly/issues"
24
+
25
+ [project.scripts]
26
+ mockly-install = "mockly_driver._install:main"
27
+
28
+ [tool.hatch.build.targets.wheel]
29
+ packages = ["src/mockly_driver"]
30
+
31
+ [tool.pytest.ini_options]
32
+ testpaths = ["tests"]
@@ -0,0 +1,24 @@
1
+ """mockly-driver — Python client for Mockly mock server."""
2
+
3
+ from ._install import get_binary_path, install
4
+ from ._server import MocklyServer
5
+ from ._types import (
6
+ FaultConfig,
7
+ Mock,
8
+ MockRequest,
9
+ MockResponse,
10
+ Scenario,
11
+ ScenarioPatch,
12
+ )
13
+
14
+ __all__ = [
15
+ "MocklyServer",
16
+ "install",
17
+ "get_binary_path",
18
+ "Mock",
19
+ "MockRequest",
20
+ "MockResponse",
21
+ "Scenario",
22
+ "ScenarioPatch",
23
+ "FaultConfig",
24
+ ]