-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from dknowles2/diagnostics
Add support for returning redacted diagnostics
- Loading branch information
Showing
4 changed files
with
222 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
import pytest | ||
|
||
from pyschlage import common | ||
|
||
|
||
@pytest.fixture | ||
def json_dict() -> dict[Any, Any]: | ||
return { | ||
"a": "foo", | ||
"b": 1, | ||
"c": { | ||
"c0": "foo", | ||
"c1": 1, | ||
"c2": { | ||
"c20": "foo", | ||
}, | ||
"c3": ["foo"], | ||
}, | ||
"d": ["foo"], | ||
} | ||
|
||
|
||
def test_redact_allow_asterisk(json_dict: dict[Any, Any]): | ||
assert common.redact(json_dict, allowed=["*"]) == json_dict | ||
|
||
|
||
def test_redact_allow_all(json_dict: dict[Any, Any]): | ||
assert common.redact(json_dict, allowed=["a", "b", "c.*", "d"]) == json_dict | ||
assert ( | ||
common.redact( | ||
json_dict, allowed=["a", "b", "c.c0", "c.c1", "c.c2", "c.c3", "d"] | ||
) | ||
== json_dict | ||
) | ||
assert common.redact(json_dict, allowed=["a", "b", "c", "d"]) == json_dict | ||
|
||
|
||
def test_redact_all(json_dict: dict[Any, Any]): | ||
want = { | ||
"a": "<REDACTED>", | ||
"b": "<REDACTED>", | ||
"c": { | ||
"c0": "<REDACTED>", | ||
"c1": "<REDACTED>", | ||
"c2": { | ||
"c20": "<REDACTED>", | ||
}, | ||
"c3": ["<REDACTED>"], | ||
}, | ||
"d": ["<REDACTED>"], | ||
} | ||
assert common.redact(json_dict, allowed=[]) == want | ||
|
||
|
||
def test_redact_partial(json_dict: dict[Any, Any]): | ||
want = { | ||
"a": "foo", | ||
"b": 1, | ||
"c": { | ||
"c0": "foo", | ||
"c1": "<REDACTED>", | ||
"c2": { | ||
"c20": "<REDACTED>", | ||
}, | ||
"c3": ["<REDACTED>"], | ||
}, | ||
"d": ["<REDACTED>"], | ||
} | ||
assert common.redact(json_dict, allowed=["a", "b", "c.c0"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters