ermes-cli 1.2.0__tar.gz → 1.2.1__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.
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/PKG-INFO +1 -1
- ermes_cli-1.2.1/ermes_cli/__init__.py +1 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/client.py +8 -4
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/commands/metrics.py +27 -2
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/commands/projects.py +18 -1
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/commands/templates.py +3 -1
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/commands/write_cmds.py +9 -1
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/pyproject.toml +1 -1
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_client.py +11 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_commands/test_metrics.py +49 -0
- ermes_cli-1.2.1/tests/test_commands/test_projects_list.py +43 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_commands/test_templates.py +17 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_write_cmds.py +10 -0
- ermes_cli-1.2.0/ermes_cli/__init__.py +0 -1
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/.gitignore +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/README.md +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/admin_api.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/auth0.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/commands/__init__.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/commands/auth_cmds.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/commands/campaigns.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/commands/config_cmd.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/commands/data_paths.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/commands/export.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/commands/ingest.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/commands/journeys.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/commands/keys.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/commands/lists.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/commands/providers.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/commands/skill.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/commands/subscriptions.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/commands/tags.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/commands/users.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/config.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/errors.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/export_utils.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/keyring_store.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/main.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/output.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/rules.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/skill/SKILL.md +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/update.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/ermes_cli/write_mode.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/scripts/install-cli.sh +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/__init__.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/conftest.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_admin_api.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_auth0.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_auth_cmds.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_commands/__init__.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_commands/test_campaigns.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_commands/test_data_paths.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_commands/test_export.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_commands/test_ingest.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_commands/test_journeys.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_commands/test_keys.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_commands/test_lists.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_commands/test_projects.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_commands/test_providers.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_commands/test_subscriptions.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_commands/test_tags.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_commands/test_users.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_config.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_export_utils.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_keyring_store.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_output.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_projects_config.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_rules.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_skill_command.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_update.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_version.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_whoami.py +0 -0
- {ermes_cli-1.2.0 → ermes_cli-1.2.1}/tests/test_write_mode.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: ermes-cli
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.1
|
|
4
4
|
Summary: CLI-first access to Ermes marketing automation with Auth0 multi-project auth.
|
|
5
5
|
Project-URL: Homepage, https://ermes.publinker.com
|
|
6
6
|
Project-URL: Repository, https://github.com/Martech-DM/ermes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.2.1"
|
|
@@ -40,21 +40,25 @@ class ErmesClient:
|
|
|
40
40
|
status = response.status_code
|
|
41
41
|
if status in _ERROR_MESSAGES:
|
|
42
42
|
raise ErmesAPIError(_ERROR_MESSAGES[status], status)
|
|
43
|
-
if status
|
|
43
|
+
if status in (400, 422):
|
|
44
44
|
try:
|
|
45
45
|
body = response.json()
|
|
46
46
|
detail = body.get("error") or body.get("message") or str(body)
|
|
47
47
|
except Exception:
|
|
48
48
|
detail = response.text
|
|
49
|
-
|
|
49
|
+
label = "Bad request" if status == 400 else "Validation error"
|
|
50
|
+
raise ErmesAPIError(f"{label}: {detail}", status)
|
|
50
51
|
raise ErmesAPIError(f"Server error: {status}", status)
|
|
51
52
|
|
|
52
53
|
def get(self, path: str, params: dict | None = None) -> Any:
|
|
53
54
|
response = self._client.get(path, params=params)
|
|
54
55
|
return self._handle_response(response)
|
|
55
56
|
|
|
56
|
-
def post(self, path: str, json: dict | None = None) -> Any:
|
|
57
|
-
|
|
57
|
+
def post(self, path: str, json: dict | None = None, *, read_only: bool = False) -> Any:
|
|
58
|
+
# read_only: a POST the server treats as a pure read (e.g. template preview),
|
|
59
|
+
# so the write guard has nothing to protect.
|
|
60
|
+
if not read_only:
|
|
61
|
+
assert_writes_allowed("POST", path)
|
|
58
62
|
response = self._client.post(path, json=json)
|
|
59
63
|
return self._handle_response(response)
|
|
60
64
|
|
|
@@ -36,7 +36,8 @@ just surfaces the frontier so an empty result is legible.
|
|
|
36
36
|
JSON output: `--json` is a **root** flag (`ermes --json metrics …`), NOT an
|
|
37
37
|
option on this command — `ermes metrics --json` exits with `No such option`.
|
|
38
38
|
Per-campaign rows live under **`results`**, not `campaigns`/`rows`, next to
|
|
39
|
-
`channel`, `summary`, `truncated` and `aggregated_through
|
|
39
|
+
`channel`, `summary`, `truncated` and `aggregated_through`, plus the query's
|
|
40
|
+
own `start`, `end` and `type` so a saved file names its window. `--channel all`
|
|
40
41
|
nests instead: `{"channel": "all", "channels": {"email": {…}, "push": {…}}}`,
|
|
41
42
|
so a consumer has to branch on `channel` before reaching for `results`.
|
|
42
43
|
|
|
@@ -317,6 +318,20 @@ def metrics(
|
|
|
317
318
|
)
|
|
318
319
|
raise typer.Exit(code=2)
|
|
319
320
|
|
|
321
|
+
# A malformed date used to reach the API and come back as a bare 400.
|
|
322
|
+
# Normalized because 3.11+ also accepts 20261001 / 2026-W40-1, which would
|
|
323
|
+
# reach the API raw and break the string comparison of the window below.
|
|
324
|
+
def _iso(flag: str, value: Optional[str]) -> Optional[str]:
|
|
325
|
+
if value is None:
|
|
326
|
+
return None
|
|
327
|
+
try:
|
|
328
|
+
return date.fromisoformat(value).isoformat()
|
|
329
|
+
except ValueError:
|
|
330
|
+
typer.echo(f"{flag} must be a date YYYY-MM-DD, got {value!r}", err=True)
|
|
331
|
+
raise typer.Exit(code=2)
|
|
332
|
+
|
|
333
|
+
start, end = _iso("--start", start), _iso("--end", end)
|
|
334
|
+
|
|
320
335
|
# Default windows end yesterday, like the UI: today's row is a partial
|
|
321
336
|
# "so far" number (refreshed hourly) that would dilute the rates.
|
|
322
337
|
today = date.today()
|
|
@@ -333,6 +348,9 @@ def metrics(
|
|
|
333
348
|
end = max(start, yesterday)
|
|
334
349
|
elif start is None:
|
|
335
350
|
start = (date.fromisoformat(end) - timedelta(days=7)).isoformat()
|
|
351
|
+
if start > end:
|
|
352
|
+
typer.echo(f"--start {start} is after --end {end}", err=True)
|
|
353
|
+
raise typer.Exit(code=2)
|
|
336
354
|
|
|
337
355
|
from ermes_cli.main import get_client, state
|
|
338
356
|
|
|
@@ -372,10 +390,17 @@ def metrics(
|
|
|
372
390
|
# and aggregated_through unambiguous instead of silently merging
|
|
373
391
|
# incomparable channels.
|
|
374
392
|
payload: dict = {"channel": "all", "channels": fetched}
|
|
393
|
+
payload.update(start=start, end=end, type=type_)
|
|
375
394
|
else:
|
|
376
395
|
# Response keys first: `channel` is the CLI's own annotation and must win
|
|
377
396
|
# over any same-named key the server might grow later.
|
|
378
|
-
payload = {
|
|
397
|
+
payload = {
|
|
398
|
+
**fetched[channel],
|
|
399
|
+
"channel": channel,
|
|
400
|
+
"start": start,
|
|
401
|
+
"end": end,
|
|
402
|
+
"type": type_,
|
|
403
|
+
}
|
|
379
404
|
if errors:
|
|
380
405
|
payload["errors"] = errors
|
|
381
406
|
typer.echo(json.dumps(payload, indent=2, default=str))
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import json
|
|
5
6
|
import re
|
|
6
7
|
from typing import TYPE_CHECKING, Optional
|
|
7
8
|
from zoneinfo import available_timezones
|
|
@@ -211,14 +212,30 @@ def projects_create(
|
|
|
211
212
|
@projects_app.command("list")
|
|
212
213
|
def projects_list() -> None:
|
|
213
214
|
"""Show all projects cached in ~/.ermes/projects.yml."""
|
|
215
|
+
from ermes_cli.main import state
|
|
216
|
+
|
|
214
217
|
projects = get_projects()
|
|
218
|
+
active = get_active_project_id()
|
|
219
|
+
if state.use_json:
|
|
220
|
+
# Keys stay masked in JSON too: this output gets pasted into chats and logs.
|
|
221
|
+
rows = [
|
|
222
|
+
{
|
|
223
|
+
"id": pid,
|
|
224
|
+
"name": p.get("name"),
|
|
225
|
+
"role": p.get("role"),
|
|
226
|
+
"key": mask_key(p["api_key"]) if p.get("api_key") else None,
|
|
227
|
+
"active": pid == active,
|
|
228
|
+
}
|
|
229
|
+
for pid, p in sorted(projects.items())
|
|
230
|
+
]
|
|
231
|
+
typer.echo(json.dumps(rows, indent=2))
|
|
232
|
+
return
|
|
215
233
|
if not projects:
|
|
216
234
|
console.print(
|
|
217
235
|
"[yellow]No cached projects.[/yellow] Run `ermes login` to discover them."
|
|
218
236
|
)
|
|
219
237
|
raise typer.Exit(code=0)
|
|
220
238
|
|
|
221
|
-
active = get_active_project_id()
|
|
222
239
|
email = get_auth0_email()
|
|
223
240
|
|
|
224
241
|
table = Table(title=f"Projects ({email or 'unknown user'})")
|
|
@@ -114,7 +114,9 @@ def templates_preview(template_id: int = typer.Argument(...), data: Optional[str
|
|
|
114
114
|
typer.echo(f"Invalid JSON: {e}", err=True)
|
|
115
115
|
raise typer.Exit(code=1)
|
|
116
116
|
try:
|
|
117
|
-
result = client.post(
|
|
117
|
+
result = client.post(
|
|
118
|
+
f"/templates/{template_id}/preview", json=body, read_only=True
|
|
119
|
+
)
|
|
118
120
|
render_detail(result, use_json=st.use_json)
|
|
119
121
|
except ErmesAPIError as e:
|
|
120
122
|
typer.echo(str(e), err=True)
|
|
@@ -8,6 +8,8 @@ the underlying state machine.
|
|
|
8
8
|
|
|
9
9
|
from __future__ import annotations
|
|
10
10
|
|
|
11
|
+
import json
|
|
12
|
+
|
|
11
13
|
import typer
|
|
12
14
|
from rich.console import Console
|
|
13
15
|
|
|
@@ -55,7 +57,13 @@ def _print_status(s: dict) -> None:
|
|
|
55
57
|
@write_app.command("status")
|
|
56
58
|
def write_status() -> None:
|
|
57
59
|
"""Show the current write-mode state."""
|
|
58
|
-
|
|
60
|
+
from ermes_cli.main import state
|
|
61
|
+
|
|
62
|
+
s = write_mode.status()
|
|
63
|
+
if state.use_json:
|
|
64
|
+
typer.echo(json.dumps(s))
|
|
65
|
+
return
|
|
66
|
+
_print_status(s)
|
|
59
67
|
|
|
60
68
|
|
|
61
69
|
@write_app.command("allow")
|
|
@@ -5,7 +5,7 @@ build-backend = "hatchling.build"
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "ermes-cli"
|
|
7
7
|
# Keep in lockstep with ermes_cli/__init__.py::__version__ — tests/test_version.py fails if they drift.
|
|
8
|
-
version = "1.2.
|
|
8
|
+
version = "1.2.1"
|
|
9
9
|
description = "CLI-first access to Ermes marketing automation with Auth0 multi-project auth."
|
|
10
10
|
readme = "README.md"
|
|
11
11
|
requires-python = ">=3.10"
|
|
@@ -42,6 +42,17 @@ class TestErrorHandling:
|
|
|
42
42
|
with pytest.raises(ErmesAPIError, match="name is required"):
|
|
43
43
|
client.post("/campaigns", json={})
|
|
44
44
|
|
|
45
|
+
def test_400_shows_the_server_reason(self, client, httpx_mock: HTTPXMock):
|
|
46
|
+
httpx_mock.add_response(status_code=400, json={"error": "start must be a valid date"})
|
|
47
|
+
with pytest.raises(ErmesAPIError, match="Bad request: start must be a valid date"):
|
|
48
|
+
client.get("/metrics")
|
|
49
|
+
|
|
50
|
+
def test_read_only_post_skips_the_write_guard(self, client, httpx_mock: HTTPXMock, monkeypatch, tmp_path):
|
|
51
|
+
monkeypatch.setenv("ERMES_CONFIG_DIR", str(tmp_path / ".ermes"))
|
|
52
|
+
monkeypatch.delenv("ERMES_ALLOW_WRITES", raising=False)
|
|
53
|
+
httpx_mock.add_response(json={"html": "<p>hi</p>"})
|
|
54
|
+
assert client.post("/templates/1/preview", json={}, read_only=True) == {"html": "<p>hi</p>"}
|
|
55
|
+
|
|
45
56
|
def test_500_raises_server_error(self, client, httpx_mock: HTTPXMock):
|
|
46
57
|
httpx_mock.add_response(status_code=500)
|
|
47
58
|
with pytest.raises(ErmesAPIError, match="Server error"):
|
|
@@ -456,3 +456,52 @@ class TestMetricsErrors:
|
|
|
456
456
|
result = invoke(["--json", "metrics", "--channel", "push"])
|
|
457
457
|
assert result.exit_code == 0
|
|
458
458
|
assert json.loads(result.output)["channel"] == "push"
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
class TestMetricsDateValidation:
|
|
462
|
+
@pytest.mark.parametrize("args", [
|
|
463
|
+
["--start", "2026-13-01"],
|
|
464
|
+
["--end", "yesterday"],
|
|
465
|
+
["--start", "2026-10-20", "--end", "2026-10-02x"],
|
|
466
|
+
])
|
|
467
|
+
def test_bad_date_fails_locally(self, invoke, httpx_mock: HTTPXMock, args):
|
|
468
|
+
result = invoke(["metrics", *args])
|
|
469
|
+
assert result.exit_code == 2
|
|
470
|
+
assert "YYYY-MM-DD" in result.output
|
|
471
|
+
assert httpx_mock.get_requests() == []
|
|
472
|
+
|
|
473
|
+
def test_inverted_window_fails_locally(self, invoke, httpx_mock: HTTPXMock):
|
|
474
|
+
result = invoke(["metrics", "--start", "2026-10-20", "--end", "2026-10-10"])
|
|
475
|
+
assert result.exit_code == 2
|
|
476
|
+
assert "is after --end" in result.output
|
|
477
|
+
assert httpx_mock.get_requests() == []
|
|
478
|
+
|
|
479
|
+
def test_compact_date_is_normalized(self, invoke, httpx_mock: HTTPXMock):
|
|
480
|
+
# Python 3.11+ fromisoformat accepts 20261001; raw, it would reach the API
|
|
481
|
+
# and compare as a string ("20261001" > "2026-10-24"), rejecting a valid window.
|
|
482
|
+
_stub_metrics(httpx_mock)
|
|
483
|
+
result = invoke(["--json", "metrics", "--start", "20261001", "--end", "2026-10-24"])
|
|
484
|
+
assert result.exit_code == 0, result.output
|
|
485
|
+
assert json.loads(result.output)["start"] == "2026-10-01"
|
|
486
|
+
assert httpx_mock.get_requests()[0].url.params["start"] == "2026-10-01"
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
class TestMetricsJsonNamesItsWindow:
|
|
490
|
+
def test_single_channel(self, invoke, httpx_mock: HTTPXMock):
|
|
491
|
+
_stub_metrics(httpx_mock, results=[PUSH_ROW])
|
|
492
|
+
result = invoke(["--json", "metrics", "--channel", "push", "--type", "blast",
|
|
493
|
+
"--start", "2026-10-01", "--end", "2026-10-07"])
|
|
494
|
+
assert result.exit_code == 0, result.output
|
|
495
|
+
data = json.loads(result.output)
|
|
496
|
+
assert (data["start"], data["end"], data["type"], data["channel"]) == (
|
|
497
|
+
"2026-10-01", "2026-10-07", "blast", "push")
|
|
498
|
+
|
|
499
|
+
def test_all_channels(self, invoke, httpx_mock: HTTPXMock):
|
|
500
|
+
_stub_metrics(httpx_mock)
|
|
501
|
+
_stub_metrics(httpx_mock, results=[PUSH_ROW])
|
|
502
|
+
result = invoke(["--json", "metrics", "--channel", "all",
|
|
503
|
+
"--start", "2026-10-01", "--end", "2026-10-07"])
|
|
504
|
+
assert result.exit_code == 0, result.output
|
|
505
|
+
data = json.loads(result.output)
|
|
506
|
+
assert (data["start"], data["end"], data["type"]) == ("2026-10-01", "2026-10-07", "trigger")
|
|
507
|
+
assert set(data["channels"]) == {"email", "push"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""`ermes projects list`, table and --json."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
|
|
9
|
+
from ermes_cli.config import save_projects_file
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@pytest.fixture
|
|
13
|
+
def seeded(config_dir):
|
|
14
|
+
save_projects_file({
|
|
15
|
+
"auth0_email": "admin@ermes.local",
|
|
16
|
+
"active_project": 72,
|
|
17
|
+
"projects": {
|
|
18
|
+
120: {"name": "dd_brazil", "role": "admin", "api_key": "sk_120key_secretvalue"},
|
|
19
|
+
72: {"name": "martechdm", "role": "member"},
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_json_masks_keys(seeded, invoke):
|
|
25
|
+
result = invoke(["--json", "projects", "list"])
|
|
26
|
+
assert result.exit_code == 0, result.output
|
|
27
|
+
assert json.loads(result.output) == [
|
|
28
|
+
{"id": 72, "name": "martechdm", "role": "member", "key": None, "active": True},
|
|
29
|
+
{"id": 120, "name": "dd_brazil", "role": "admin", "key": "sk_***lue", "active": False},
|
|
30
|
+
]
|
|
31
|
+
assert "secretvalue" not in result.output
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_json_empty_is_a_list(config_dir, invoke):
|
|
35
|
+
result = invoke(["--json", "projects", "list"])
|
|
36
|
+
assert result.exit_code == 0
|
|
37
|
+
assert json.loads(result.output) == []
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_table_still_renders(seeded, invoke):
|
|
41
|
+
result = invoke(["projects", "list"])
|
|
42
|
+
assert result.exit_code == 0
|
|
43
|
+
assert "martechdm" in result.output and "secretvalue" not in result.output
|
|
@@ -44,3 +44,20 @@ class TestTemplatesProof:
|
|
|
44
44
|
httpx_mock.add_response(json={"success": True})
|
|
45
45
|
result = invoke(["--json", "templates", "proof", "1", "--to", "test@example.com"])
|
|
46
46
|
assert result.exit_code == 0
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class TestTemplatesPreview:
|
|
50
|
+
def test_preview_runs_with_writes_blocked(self, invoke, httpx_mock: HTTPXMock, monkeypatch):
|
|
51
|
+
# Preview only compiles the template server-side, so it must not need a write window.
|
|
52
|
+
monkeypatch.delenv("ERMES_ALLOW_WRITES", raising=False)
|
|
53
|
+
httpx_mock.add_response(json={"html": "<p>hi</p>"})
|
|
54
|
+
result = invoke(["--json", "templates", "preview", "7"])
|
|
55
|
+
assert result.exit_code == 0, result.output
|
|
56
|
+
assert json.loads(result.output)["html"] == "<p>hi</p>"
|
|
57
|
+
assert httpx_mock.get_requests()[0].url.path.endswith("/templates/7/preview")
|
|
58
|
+
|
|
59
|
+
def test_proof_is_still_blocked(self, invoke, httpx_mock: HTTPXMock, monkeypatch):
|
|
60
|
+
monkeypatch.delenv("ERMES_ALLOW_WRITES", raising=False)
|
|
61
|
+
result = invoke(["templates", "proof", "7", "--to", "a@b.test"])
|
|
62
|
+
assert result.exit_code != 0
|
|
63
|
+
assert httpx_mock.get_requests() == []
|
|
@@ -59,3 +59,13 @@ def test_env_override_shows_in_status(invoke, clean_state, monkeypatch):
|
|
|
59
59
|
result = invoke(["write", "status"])
|
|
60
60
|
assert result.exit_code == 0
|
|
61
61
|
assert "env" in result.output.lower() or "ALLOWED" in result.output
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def test_status_json(invoke, clean_state):
|
|
65
|
+
import json
|
|
66
|
+
|
|
67
|
+
result = invoke(["--json", "write", "status"])
|
|
68
|
+
assert result.exit_code == 0
|
|
69
|
+
assert json.loads(result.output) == {
|
|
70
|
+
"allowed": False, "mode": "denied", "until": None, "source": "default",
|
|
71
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "1.2.0"
|
|
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
|
|
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
|