diff --git a/b2/_internal/console_tool.py b/b2/_internal/console_tool.py index 7074050a..ade898cc 100644 --- a/b2/_internal/console_tool.py +++ b/b2/_internal/console_tool.py @@ -4269,16 +4269,16 @@ class BucketNotificationRuleBase(BucketNotificationRuleWarningMixin, Command): {BucketNotificationRuleWarningMixin} - For more information on each subcommand, use ``{NAME} notification-rule SUBCOMMAND --help``. + For more information on each subcommand, use ``{NAME} bucket notification-rule SUBCOMMAND --help``. Examples: .. code-block:: - {NAME} notification-rule create b2://bucketName/optionalSubPath/ ruleName --event-type "b2:ObjectCreated:*" --webhook-url https://example.com/webhook - {NAME} notification-rule list b2://bucketName - {NAME} notification-rule update b2://bucketName/newPath/ ruleName --disable --event-type "b2:ObjectCreated:*" --event-type "b2:ObjectHidden:*" - {NAME} notification-rule delete b2://bucketName ruleName + {NAME} bucket notification-rule create b2://bucketName/optionalSubPath/ ruleName --event-type "b2:ObjectCreated:*" --webhook-url https://example.com/webhook + {NAME} bucket notification-rule list b2://bucketName + {NAME} bucket notification-rule update b2://bucketName/newPath/ ruleName --disable --event-type "b2:ObjectCreated:*" --event-type "b2:ObjectHidden:*" + {NAME} bucket notification-rule delete b2://bucketName ruleName """ subcommands_registry = ClassRegistry(attr_name='COMMAND_NAME') diff --git a/test/unit/console_tool/test_notification_rules.py b/test/unit/console_tool/test_notification_rules.py index bd5c3ecf..4fd236f8 100644 --- a/test/unit/console_tool/test_notification_rules.py +++ b/test/unit/console_tool/test_notification_rules.py @@ -11,8 +11,6 @@ import pytest -COMMANDS = (["bucket", "notification-rule"], ["notification-rules"]) - @pytest.fixture() def bucket_notification_rule(b2_cli, bucket): @@ -47,15 +45,15 @@ def bucket_notification_rule(b2_cli, bucket): return actual_rule -def test_notification_rules__list_all(b2_cli, bucket, bucket_notification_rule): - for command in COMMANDS: - _, stdout, _ = b2_cli.run([ - *command, - "list", - f"b2://{bucket}", - ]) - assert ( - stdout == f"""\ +@pytest.mark.parametrize("command", [["bucket", "notification-rule"], ["notification-rules"]]) +def test_notification_rules__list_all(b2_cli, bucket, bucket_notification_rule, command): + _, stdout, _ = b2_cli.run([ + *command, + "list", + f"b2://{bucket}", + ]) + assert ( + stdout == f"""\ Notification rules for b2://{bucket}/ : - name: test-rule eventTypes: @@ -68,80 +66,82 @@ def test_notification_rules__list_all(b2_cli, bucket, bucket_notification_rule): targetType: webhook url: https://example.com/webhook """ - ) + ) + +@pytest.mark.parametrize("command", [["bucket", "notification-rule"], ["notification-rules"]]) +def test_notification_rules__list_all_json(b2_cli, bucket, bucket_notification_rule, command): + _, stdout, _ = b2_cli.run([ + *command, + "list", + "--json", + f"b2://{bucket}", + ]) + assert json.loads(stdout) == [bucket_notification_rule] -def test_notification_rules__list_all_json(b2_cli, bucket, bucket_notification_rule): - for command in COMMANDS: - _, stdout, _ = b2_cli.run([ + +@pytest.mark.parametrize("command", [["bucket", "notification-rule"], ["notification-rules"]]) +def test_notification_rules__update(b2_cli, bucket, bucket_notification_rule, command): + bucket_notification_rule["isEnabled"] = False + _, stdout, _ = b2_cli.run( + [ *command, - "list", + "update", "--json", f"b2://{bucket}", - ]) - assert json.loads(stdout) == [bucket_notification_rule] - - -def test_notification_rules__update(b2_cli, bucket, bucket_notification_rule): - for command in COMMANDS: - bucket_notification_rule["isEnabled"] = False - _, stdout, _ = b2_cli.run( - [ - *command, - "update", - "--json", - f"b2://{bucket}", - bucket_notification_rule["name"], - "--disable", - "--custom-header", - "X-Custom-Header=value=1", - ], - ) - bucket_notification_rule["targetConfiguration"]["customHeaders"] = { - "X-Custom-Header": "value=1" - } - assert json.loads(stdout) == bucket_notification_rule + bucket_notification_rule["name"], + "--disable", + "--custom-header", + "X-Custom-Header=value=1", + ], + ) + bucket_notification_rule["targetConfiguration"]["customHeaders"] = { + "X-Custom-Header": "value=1" + } + assert json.loads(stdout) == bucket_notification_rule -def test_notification_rules__update__no_such_rule(b2_cli, bucket, bucket_notification_rule): - for command in COMMANDS: - b2_cli.run( - [ - *command, - "update", - f"b2://{bucket}", - f'{bucket_notification_rule["name"]}-unexisting', - "--disable", - ], - expected_stderr=( - "ERROR: rule with name 'test-rule-unexisting' does not exist on bucket " - "'my-bucket', available rules: ['test-rule']\n" - ), - expected_status=1, - ) +@pytest.mark.parametrize("command", [["bucket", "notification-rule"], ["notification-rules"]]) +def test_notification_rules__update__no_such_rule( + b2_cli, bucket, bucket_notification_rule, command +): + b2_cli.run( + [ + *command, + "update", + f"b2://{bucket}", + f'{bucket_notification_rule["name"]}-unexisting', + "--disable", + ], + expected_stderr=( + "ERROR: rule with name 'test-rule-unexisting' does not exist on bucket " + "'my-bucket', available rules: ['test-rule']\n" + ), + expected_status=1, + ) +@pytest.mark.parametrize("command", [["bucket", "notification-rule"], ["notification-rules"]]) def test_notification_rules__update__custom_header_malformed( - b2_cli, bucket, bucket_notification_rule + b2_cli, bucket, bucket_notification_rule, command ): - for command in COMMANDS: - bucket_notification_rule["isEnabled"] = False - _, stdout, _ = b2_cli.run( - [ - *command, - "update", - "--json", - f"b2://{bucket}", - bucket_notification_rule["name"], - "--disable", - "--custom-header", - "X-Custom-Header: value", - ], - ) - bucket_notification_rule["targetConfiguration"]["customHeaders"] = { - "X-Custom-Header: value": "" - } - assert json.loads(stdout) == bucket_notification_rule + bucket_notification_rule["isEnabled"] = False + _, stdout, _ = b2_cli.run( + [ + *command, + "update", + "--json", + f"b2://{bucket}", + bucket_notification_rule["name"], + "--disable", + "--custom-header", + "X-Custom-Header: value", + ], + ) + bucket_notification_rule["targetConfiguration"]["customHeaders"] = { + "X-Custom-Header: value": "" + } + assert json.loads(stdout) == bucket_notification_rule def test_notification_rules__delete(b2_cli, bucket, bucket_notification_rule): @@ -157,21 +157,21 @@ def test_notification_rules__delete(b2_cli, bucket, bucket_notification_rule): assert stdout == "Rule 'test-rule' has been deleted from b2://my-bucket/\n" -def test_notification_rules__delete_no_such_rule(b2_cli, bucket, bucket_notification_rule): - for command in COMMANDS: - b2_cli.run( - [ - *command, - "delete", - f"b2://{bucket}", - f'{bucket_notification_rule["name"]}-unexisting', - ], - expected_stderr=( - "ERROR: no such rule to delete: 'test-rule-unexisting', available rules: ['test-rule'];" - " No rules have been deleted.\n" - ), - expected_status=1, - ) +@pytest.mark.parametrize("command", [["bucket", "notification-rule"], ["notification-rules"]]) +def test_notification_rules__delete_no_such_rule(b2_cli, bucket, bucket_notification_rule, command): + b2_cli.run( + [ + *command, + "delete", + f"b2://{bucket}", + f'{bucket_notification_rule["name"]}-unexisting', + ], + expected_stderr=( + "ERROR: no such rule to delete: 'test-rule-unexisting', available rules: ['test-rule'];" + " No rules have been deleted.\n" + ), + expected_status=1, + ) @pytest.mark.parametrize( @@ -183,36 +183,35 @@ def test_notification_rules__delete_no_such_rule(b2_cli, bucket, bucket_notifica ], ) def test_notification_rules__no_rules(b2_cli, bucket, args, expected_stdout): - for command in COMMANDS: - b2_cli.run( - [*command, "list", f"b2://{bucket}", *args], - expected_stdout=expected_stdout, - ) + b2_cli.run( + ["bucket", "notification-rule", "list", f"b2://{bucket}", *args], + expected_stdout=expected_stdout, + ) -def test_notification_rules__disable_enable(b2_cli, bucket, bucket_notification_rule): - for command in COMMANDS: - _, stdout, _ = b2_cli.run( - [ - *command, - "disable", - "--json", - f"b2://{bucket}", - bucket_notification_rule["name"], - ], - ) - assert json.loads(stdout) == {**bucket_notification_rule, "isEnabled": False} +@pytest.mark.parametrize("command", [["bucket", "notification-rule"], ["notification-rules"]]) +def test_notification_rules__disable_enable(b2_cli, bucket, bucket_notification_rule, command): + _, stdout, _ = b2_cli.run( + [ + *command, + "disable", + "--json", + f"b2://{bucket}", + bucket_notification_rule["name"], + ], + ) + assert json.loads(stdout) == {**bucket_notification_rule, "isEnabled": False} - _, stdout, _ = b2_cli.run( - [ - *command, - "enable", - "--json", - f"b2://{bucket}", - bucket_notification_rule["name"], - ], - ) - assert json.loads(stdout) == {**bucket_notification_rule, "isEnabled": True} + _, stdout, _ = b2_cli.run( + [ + *command, + "enable", + "--json", + f"b2://{bucket}", + bucket_notification_rule["name"], + ], + ) + assert json.loads(stdout) == {**bucket_notification_rule, "isEnabled": True} @pytest.mark.parametrize( @@ -220,53 +219,56 @@ def test_notification_rules__disable_enable(b2_cli, bucket, bucket_notification_ ["disable", "enable"], ) def test_notification_rules__disable_enable__no_such_rule( - b2_cli, bucket, bucket_notification_rule, subcommand + b2_cli, + bucket, + bucket_notification_rule, + subcommand, ): - for command in COMMANDS: - b2_cli.run( - [ - *command, - subcommand, - f"b2://{bucket}", - f'{bucket_notification_rule["name"]}-unexisting', - ], - expected_stderr=( - "ERROR: rule with name 'test-rule-unexisting' does not exist on bucket " - "'my-bucket', available rules: ['test-rule']\n" - ), - expected_status=1, - ) + b2_cli.run( + [ + "bucket", + "notification-rule", + subcommand, + f"b2://{bucket}", + f'{bucket_notification_rule["name"]}-unexisting', + ], + expected_stderr=( + "ERROR: rule with name 'test-rule-unexisting' does not exist on bucket " + "'my-bucket', available rules: ['test-rule']\n" + ), + expected_status=1, + ) -def test_notification_rules__sign_secret(b2_cli, bucket, bucket_notification_rule): - for command in COMMANDS: - b2_cli.run( - [ - *command, - "update", - "--json", - f"b2://{bucket}", - bucket_notification_rule["name"], - "--sign-secret", - "new-secret", - ], - expected_status=2, - ) +@pytest.mark.parametrize("command", [["bucket", "notification-rule"], ["notification-rules"]]) +def test_notification_rules__sign_secret(b2_cli, bucket, bucket_notification_rule, command): + b2_cli.run( + [ + *command, + "update", + "--json", + f"b2://{bucket}", + bucket_notification_rule["name"], + "--sign-secret", + "new-secret", + ], + expected_status=2, + ) - _, stdout, _ = b2_cli.run( - [ - *command, - "update", - "--json", - f"b2://{bucket}", - bucket_notification_rule["name"], - "--sign-secret", - "7" * 32, - ], - ) - bucket_notification_rule["targetConfiguration"]["hmacSha256SigningSecret"] = "7" * 32 - assert json.loads(stdout) == bucket_notification_rule + _, stdout, _ = b2_cli.run( + [ + *command, + "update", + "--json", + f"b2://{bucket}", + bucket_notification_rule["name"], + "--sign-secret", + "7" * 32, + ], + ) + bucket_notification_rule["targetConfiguration"]["hmacSha256SigningSecret"] = "7" * 32 + assert json.loads(stdout) == bucket_notification_rule - assert json.loads(b2_cli.run([*command, "list", "--json", f"b2://{bucket}"],)[1]) == [ - bucket_notification_rule - ] + assert json.loads(b2_cli.run([*command, "list", "--json", f"b2://{bucket}"],)[1]) == [ + bucket_notification_rule + ] diff --git a/test/unit/test_console_tool.py b/test/unit/test_console_tool.py index 8e510f30..99192533 100644 --- a/test/unit/test_console_tool.py +++ b/test/unit/test_console_tool.py @@ -655,7 +655,7 @@ def test_buckets(self): self._run_command(['bucket', 'delete', 'your-bucket'], expected_stdout, '', 0) - def test_deprecated_buckets(self): + def test_deprecated_bucket_commands(self): self._authorize_account() # Make a bucket with an illegal name