Skip to content

Commit a7f1364

Browse files
Fix event notification tests
1 parent f968d7b commit a7f1364

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix event notification tests when introducing new keys in API outputs.

test/helpers.py

+19
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,22 @@ def b2_uri_args_v4(bucket_name, path=_MISSING):
3232
if path is _MISSING:
3333
path = ''
3434
return [f'b2://{bucket_name}/{path}']
35+
36+
37+
def deep_cast_dict(actual, expected):
38+
"""
39+
For composite objects `actual` and `expected`, return a copy of `actual` (with all dicts and lists deeply copied)
40+
with all keys of dicts not appearing in `expected` (comparing dicts on any level) removed. Useful for assertions
41+
in tests ignoring extra keys.
42+
"""
43+
if isinstance(expected, dict) and isinstance(actual, dict):
44+
return {k: deep_cast_dict(actual[k], expected[k]) for k in expected if k in actual}
45+
46+
elif isinstance(expected, list) and isinstance(actual, list):
47+
return [deep_cast_dict(a, e) for a, e in zip(actual, expected)]
48+
49+
return actual
50+
51+
52+
def assert_dict_equal_ignore_extra(actual, expected):
53+
assert deep_cast_dict(actual, expected) == expected

test/integration/test_b2_command_line.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
)
4747
from b2._internal.console_tool import current_time_millis
4848

49-
from ..helpers import skip_on_windows
49+
from ..helpers import assert_dict_equal_ignore_extra, skip_on_windows
5050
from .helpers import (
5151
ONE_DAY_MILLIS,
5252
ONE_HOUR_MILLIS,
@@ -3465,7 +3465,7 @@ def test_notification_rules(b2_tool, bucket_name):
34653465
expected_stderr_pattern=private_preview_pattern
34663466
)
34673467
expected_rules = [{**notification_rule, "isSuspended": False, "suspensionReason": ""}]
3468-
assert created_rule == expected_rules[0]
3468+
assert_dict_equal_ignore_extra(created_rule, expected_rules[0])
34693469

34703470
# modify rule
34713471
secret = "0testSecret000000000000000000032"
@@ -3485,13 +3485,16 @@ def test_notification_rules(b2_tool, bucket_name):
34853485
)
34863486
expected_rules[0].update({"objectNamePrefix": "prefix", "isEnabled": False})
34873487
expected_rules[0]["targetConfiguration"]["hmacSha256SigningSecret"] = secret
3488-
assert modified_rule == expected_rules[0]
3488+
assert_dict_equal_ignore_extra(modified_rule, expected_rules[0])
34893489

34903490
# read updated rules
3491-
assert b2_tool.should_succeed_json(
3492-
["bucket", "notification-rule", "list", f"b2://{bucket_name}", "--json"],
3493-
expected_stderr_pattern=private_preview_pattern
3494-
) == expected_rules
3491+
assert_dict_equal_ignore_extra(
3492+
b2_tool.should_succeed_json(
3493+
["bucket", "notification-rule", "list", f"b2://{bucket_name}", "--json"],
3494+
expected_stderr_pattern=private_preview_pattern
3495+
),
3496+
expected_rules,
3497+
)
34953498

34963499
# delete rule by name
34973500
assert b2_tool.should_succeed(

0 commit comments

Comments
 (0)