Skip to content

Commit 68230c2

Browse files
committed
test: Data Classes str()
Add tests for DictWrapper str() functionality, including Data Classes with: - no properties - single property - blacklisted property - recursive properties (Data Classes inside Data Classes)
1 parent 37dfc71 commit 68230c2

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

tests/functional/test_data_classes.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,97 @@ class DataClassSample(DictWrapper):
126126
assert event_source.items() == data.items()
127127

128128

129+
def test_dict_wrapper_str_no_property():
130+
class DataClassSample(DictWrapper):
131+
attribute = None
132+
133+
def function(self):
134+
pass
135+
136+
event_source = DataClassSample({})
137+
assert event_source._properties() == ["raw_event"]
138+
assert event_source._str_helper() == {"raw_event": "[SENSITIVE]"}
139+
assert event_source.__str__() == "{'raw_event': '[SENSITIVE]'}"
140+
assert str(event_source) == "{'raw_event': '[SENSITIVE]'}"
141+
142+
143+
def test_dict_wrapper_str_single_property():
144+
class DataClassSample(DictWrapper):
145+
attribute = None
146+
147+
def function(self):
148+
pass
149+
150+
@property
151+
def data_property(self):
152+
return "value"
153+
154+
event_source = DataClassSample({})
155+
assert event_source._properties() == ["data_property", "raw_event"]
156+
assert event_source._str_helper() == {"data_property": "value", "raw_event": "[SENSITIVE]"}
157+
assert event_source.__str__() == "{'data_property': 'value', 'raw_event': '[SENSITIVE]'}"
158+
assert str(event_source) == "{'data_property': 'value', 'raw_event': '[SENSITIVE]'}"
159+
160+
161+
def test_dict_wrapper_str_recursive_property():
162+
class DataClassTerminal(DictWrapper):
163+
attribute = None
164+
165+
def function(self):
166+
pass
167+
168+
@property
169+
def terminal_property(self):
170+
return "end-recursion"
171+
172+
class DataClassRecursive(DictWrapper):
173+
attribute = None
174+
175+
def function(self):
176+
pass
177+
178+
@property
179+
def data_property(self):
180+
return DataClassTerminal({})
181+
182+
event_source = DataClassRecursive({})
183+
assert event_source._properties() == ["data_property", "raw_event"]
184+
assert event_source._str_helper() == {
185+
"data_property": {"raw_event": "[SENSITIVE]", "terminal_property": "end-recursion"},
186+
"raw_event": "[SENSITIVE]",
187+
}
188+
assert (
189+
event_source.__str__()
190+
== "{'data_property': {'raw_event': '[SENSITIVE]', 'terminal_property': 'end-recursion'},"
191+
+ " 'raw_event': '[SENSITIVE]'}"
192+
)
193+
assert (
194+
str(event_source)
195+
== "{'data_property': {'raw_event': '[SENSITIVE]', 'terminal_property': 'end-recursion'},"
196+
+ " 'raw_event': '[SENSITIVE]'}"
197+
)
198+
199+
200+
def test_dict_wrapper_str_sensitive_data_property():
201+
class DataClassSample(DictWrapper):
202+
attribute = None
203+
204+
def function(self):
205+
pass
206+
207+
_str_sensitive_data = ["data_property"]
208+
209+
@property
210+
def data_property(self):
211+
return "value"
212+
213+
event_source = DataClassSample({})
214+
assert event_source._properties() == ["data_property", "raw_event"]
215+
assert event_source._str_helper() == {"data_property": "[SENSITIVE]", "raw_event": "[SENSITIVE]"}
216+
assert event_source.__str__() == "{'data_property': '[SENSITIVE]', 'raw_event': '[SENSITIVE]'}"
217+
assert str(event_source) == "{'data_property': '[SENSITIVE]', 'raw_event': '[SENSITIVE]'}"
218+
219+
129220
def test_cloud_watch_dashboard_event():
130221
event = CloudWatchDashboardCustomWidgetEvent(load_event("cloudWatchDashboardEvent.json"))
131222
assert event.describe is False

0 commit comments

Comments
 (0)