|
2 | 2 |
|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
| 5 | +import json |
| 6 | +from pathlib import Path |
| 7 | + |
5 | 8 | import humps |
6 | 9 | import pytest |
7 | 10 |
|
|
11 | 14 | Definition, |
12 | 15 | Device, |
13 | 16 | EventState, |
| 17 | + Setup, |
14 | 18 | State, |
15 | 19 | StateDefinition, |
16 | 20 | States, |
17 | 21 | ) |
| 22 | +from pyoverkiz.obfuscate import obfuscate_id |
18 | 23 |
|
19 | 24 | RAW_STATES = [ |
20 | 25 | {"name": "core:NameState", "type": 3, "value": "alarm name"}, |
|
71 | 76 | } |
72 | 77 |
|
73 | 78 | STATE = "core:NameState" |
| 79 | +FIXTURES_DIR = Path(__file__).resolve().parent / "fixtures" / "setup" |
| 80 | + |
| 81 | + |
| 82 | +class TestSetup: |
| 83 | + """Tests for setup-level ID parsing and redaction behavior.""" |
| 84 | + |
| 85 | + def test_id_is_raw_but_repr_is_redacted_when_present(self): |
| 86 | + """When API provides `id`, keep raw value but redact it in repr output.""" |
| 87 | + raw_setup = json.loads( |
| 88 | + (FIXTURES_DIR / "setup_tahoma_1.json").read_text(encoding="utf-8") |
| 89 | + ) |
| 90 | + setup = Setup(**humps.decamelize(raw_setup)) |
| 91 | + raw_id = "SETUP-1234-1234-8044" |
| 92 | + redacted_id = obfuscate_id(raw_id) |
| 93 | + |
| 94 | + assert setup.id == raw_id |
| 95 | + assert redacted_id in repr(setup) |
| 96 | + assert raw_id not in repr(setup) |
| 97 | + |
| 98 | + def test_id_is_none_when_missing(self): |
| 99 | + """When API omits `id`, setup.id should stay None.""" |
| 100 | + raw_setup = json.loads( |
| 101 | + (FIXTURES_DIR / "setup_local.json").read_text(encoding="utf-8") |
| 102 | + ) |
| 103 | + setup = Setup(**humps.decamelize(raw_setup)) |
| 104 | + |
| 105 | + assert setup.id is None |
| 106 | + |
| 107 | + def test_id_is_none_without_input_id(self): |
| 108 | + """Constructing setup without an id keeps setup.id as None.""" |
| 109 | + setup = Setup(gateways=[], devices=[]) |
| 110 | + |
| 111 | + assert setup.id is None |
74 | 112 |
|
75 | 113 |
|
76 | 114 | class TestDevice: |
|
0 commit comments