|
15 | 15 | from ldclient.migrations.tracker import MigrationOpEvent |
16 | 16 | from ldclient.impl.events.types import EventInput, EventInputCustom, EventInputEvaluation, EventInputIdentify |
17 | 17 | from ldclient.impl.util import timedelta_millis |
| 18 | +from ldclient.impl.events.event_context_formatter import EventContextFormatter |
18 | 19 |
|
19 | 20 | from testing.builders import * |
20 | 21 | from testing.proxy_test_util import do_proxy_tests |
|
23 | 24 |
|
24 | 25 | default_config = Config("fake_sdk_key") |
25 | 26 | context = Context.builder('userkey').name('Red').build() |
26 | | -filtered_context = context.to_dict() # TODO: implement attribute redaction |
27 | | -filtered_context = { |
28 | | - 'kind': 'user', |
29 | | - 'key': 'userkey', |
30 | | - '_meta': {'redactedAttributes': ['name']} |
31 | | -} |
32 | 27 | flag = FlagBuilder('flagkey').version(2).build() |
33 | 28 | flag_with_0_sampling_ratio = FlagBuilder('flagkey').version(3).sampling_ratio(0).build() |
34 | 29 | flag_excluded_from_summaries = FlagBuilder('flagkey').version(4).exclude_from_summaries(True).build() |
@@ -233,12 +228,13 @@ def test_identify_event_is_queued(): |
233 | 228 |
|
234 | 229 | def test_context_is_filtered_in_identify_event(): |
235 | 230 | with DefaultTestProcessor(all_attributes_private = True) as ep: |
| 231 | + formatter = EventContextFormatter(True, []) |
236 | 232 | e = EventInputIdentify(timestamp, context) |
237 | 233 | ep.send_event(e) |
238 | 234 |
|
239 | 235 | output = flush_and_get_events(ep) |
240 | 236 | assert len(output) == 1 |
241 | | - check_identify_event(output[0], e, filtered_context) |
| 237 | + check_identify_event(output[0], e, formatter.format_context(context)) |
242 | 238 |
|
243 | 239 | def test_individual_feature_event_is_queued_with_index_event(): |
244 | 240 | with DefaultTestProcessor() as ep: |
@@ -275,13 +271,14 @@ def test_exclude_can_keep_feature_event_from_summary(): |
275 | 271 |
|
276 | 272 | def test_context_is_filtered_in_index_event(): |
277 | 273 | with DefaultTestProcessor(all_attributes_private = True) as ep: |
| 274 | + formatter = EventContextFormatter(True, []) |
278 | 275 | e = EventInputEvaluation(timestamp, context, flag.key, flag, 1, 'value', None, 'default', None, True) |
279 | 276 | ep.send_event(e) |
280 | 277 |
|
281 | 278 | output = flush_and_get_events(ep) |
282 | 279 | assert len(output) == 3 |
283 | | - check_index_event(output[0], e, filtered_context) |
284 | | - check_feature_event(output[1], e) |
| 280 | + check_index_event(output[0], e, formatter.format_context(context)) |
| 281 | + check_feature_event(output[1], e, formatter.format_context(context)) |
285 | 282 | check_summary_event(output[2]) |
286 | 283 |
|
287 | 284 | def test_two_events_for_same_context_only_produce_one_index_event(): |
@@ -682,15 +679,15 @@ def check_index_event(data, source: EventInput, context_json: Optional[dict] = N |
682 | 679 | assert data['creationDate'] == source.timestamp |
683 | 680 | assert data['context'] == (source.context.to_dict() if context_json is None else context_json) |
684 | 681 |
|
685 | | -def check_feature_event(data, source: EventInputEvaluation): |
| 682 | +def check_feature_event(data, source: EventInputEvaluation, context_json: Optional[dict] = None): |
686 | 683 | assert data['kind'] == 'feature' |
687 | 684 | assert data['creationDate'] == source.timestamp |
688 | 685 | assert data['key'] == source.key |
689 | 686 | assert data.get('version') == None if source.flag is None else source.flag.version |
690 | 687 | assert data.get('variation') == source.variation |
691 | 688 | assert data.get('value') == source.value |
692 | 689 | assert data.get('default') == source.default_value |
693 | | - assert data['contextKeys'] == make_context_keys(source.context) |
| 690 | + assert data['context'] == (source.context.to_dict() if context_json is None else context_json) |
694 | 691 | assert data.get('prereq_of') == None if source.prereq_of is None else source.prereq_of.key |
695 | 692 |
|
696 | 693 |
|
|
0 commit comments