diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f5bff0fa..bd39e1cc 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,12 @@ Brewtils Changelog ================== +3.26.0 +------ +TBD + +- Added new model for CommandPublishingBlocklist + 3.25.0 ------ 4/5/2024 diff --git a/brewtils/models.py b/brewtils/models.py index 7bfbcbef..cc11888c 100644 --- a/brewtils/models.py +++ b/brewtils/models.py @@ -214,6 +214,36 @@ def has_different_parameters(self, parameters): return False +class CommandPublishingBlocklist(BaseModel): + schema = "CommandPublishingBlocklistSchema" + + def __init__( + self, + namespace, + system, + command, + status + ): + self.namespace = namespace + self.system = system + self.command = command + self.status = status + + def __str__(self): + return "%s_%s_%s_%s" % ( + self.namespace, + self.system, + self.command, + self.status + ) + + def __repr__(self): + return "" % ( + self.namespace, + self.system, + self.command, + self.status + ) class Instance(BaseModel): schema = "InstanceSchema" diff --git a/brewtils/schema_parser.py b/brewtils/schema_parser.py index cdbc21f4..5e8aafe3 100644 --- a/brewtils/schema_parser.py +++ b/brewtils/schema_parser.py @@ -23,6 +23,7 @@ class SchemaParser(object): _models = { "ChoicesSchema": brewtils.models.Choices, "CommandSchema": brewtils.models.Command, + "CommandPublishingBlocklistSchema": brewtils.models.CommandPublishingBlocklist, "ConnectionSchema": brewtils.models.Connection, "CronTriggerSchema": brewtils.models.CronTrigger, "DateTriggerSchema": brewtils.models.DateTrigger, @@ -104,6 +105,22 @@ def parse_command(cls, command, from_string=False, **kwargs): return cls.parse( command, brewtils.models.Command, from_string=from_string, **kwargs ) + + @classmethod + def parse_command_publishing_blocklist(cls, command_publishing_blocklist, from_string=False, **kwargs): + """Convert raw JSON string or dictionary to a command_publishing_blocklist model object + + Args: + command_publishing_blocklist: The raw input + from_string: True if input is a JSON string, False if a dictionary + **kwargs: Additional parameters to be passed to the Schema (e.g. many=True) + + Returns: + A CommandPublishingBlocklist object + """ + return cls.parse( + command_publishing_blocklist, brewtils.models.CommandPublishingBlocklist, from_string=from_string, **kwargs + ) @classmethod def parse_connection(cls, connection, from_string=False, **kwargs): @@ -546,6 +563,26 @@ def serialize_command(cls, command, to_string=True, **kwargs): schema_name=brewtils.models.Command.schema, **kwargs ) + + @classmethod + def serialize_command_publishing_blocklist(cls, command_publishing_blocklist, to_string=True, **kwargs): + """Convert a commandcommand_publishing_blocklist into serialized form + + Args: + command_publishing_blocklist: The command object(s) to be serialized + to_string: True to generate a JSON-formatted string, False to generate a + dictionary + **kwargs: Additional parameters to be passed to the Schema (e.g. many=True) + + Returns: + Serialized representation of command_publishing_blocklist + """ + return cls.serialize( + command_publishing_blocklist, + to_string=to_string, + schema_name=brewtils.models.CommandPublishingBlocklist.schema, + **kwargs + ) @classmethod def serialize_connection(cls, connection, to_string=True, **kwargs): diff --git a/brewtils/schemas.py b/brewtils/schemas.py index 6bfe08c1..3d3e7a3d 100644 --- a/brewtils/schemas.py +++ b/brewtils/schemas.py @@ -14,6 +14,7 @@ "SystemSchema", "InstanceSchema", "CommandSchema", + "CommandPublishingBlocklistSchema", "ParameterSchema", "RequestSchema", "RequestFileSchema", @@ -228,6 +229,11 @@ class CommandSchema(BaseSchema): topics = fields.List(fields.Str(), allow_none=True) allow_any_kwargs = fields.Boolean(allow_none=True) +class CommandPublishingBlocklistSchema(BaseSchema): + namespace = fields.Str(allow_none=True) + system = fields.Str(allow_none=True) + command = fields.Str(allow_none=True) + status = fields.Str(allow_none=True) class InstanceSchema(BaseSchema): id = fields.Str(allow_none=True) @@ -661,6 +667,7 @@ class UserListSchema(BaseSchema): { "Choices": ChoicesSchema, "Command": CommandSchema, + "CommandPublishingBlocklist": CommandPublishingBlocklistSchema, "Connection": ConnectionSchema, "CronTrigger": CronTriggerSchema, "DateTrigger": DateTriggerSchema, diff --git a/brewtils/test/comparable.py b/brewtils/test/comparable.py index 1dda4a73..5e965623 100644 --- a/brewtils/test/comparable.py +++ b/brewtils/test/comparable.py @@ -16,6 +16,7 @@ from brewtils.models import ( Choices, Command, + CommandPublishingBlocklist, Connection, CronTrigger, DateTrigger, @@ -198,6 +199,7 @@ def _assert_wrapper(obj1, obj2, expected_type=None, do_raise=False, **kwargs): assert_resolvable_equal = partial(_assert_wrapper, expected_type=Resolvable) assert_connection_equal = partial(_assert_wrapper, expected_type=Connection) assert_subscriber_equal = partial(_assert_wrapper, expected_type=Subscriber) +assert_command_publishing_blocklist_equal = partial(_assert_wrapper, expected_type=CommandPublishingBlocklist) def assert_command_equal(obj1, obj2, do_raise=False): diff --git a/brewtils/test/fixtures.py b/brewtils/test/fixtures.py index 6cb362fc..249009e4 100644 --- a/brewtils/test/fixtures.py +++ b/brewtils/test/fixtures.py @@ -9,6 +9,7 @@ from brewtils.models import ( Choices, Command, + CommandPublishingBlocklist, Connection, CronTrigger, DateTrigger, @@ -202,6 +203,21 @@ def bg_command_2(command_dict_2, bg_parameter, system_id): dict_copy["parameters"] = [bg_parameter] return Command(**dict_copy) +@pytest.fixture +def command_publishing_blocklist_dict(): + """A Command Publishing Blocklist represented as a dictionary.""" + + return { + "namespace":"namespace", + "system": "system", + "command":"command", + "status":"status", + } + +@pytest.fixture +def bg_command_publishing_blocklist(command_publishing_blocklist_dict): + return CommandPublishingBlocklist(**command_publishing_blocklist_dict) + @pytest.fixture def instance_dict(ts_epoch): diff --git a/test/schema_parser_test.py b/test/schema_parser_test.py index 9246dba2..85af8b74 100644 --- a/test/schema_parser_test.py +++ b/test/schema_parser_test.py @@ -11,6 +11,7 @@ from brewtils.schema_parser import SchemaParser from brewtils.test.comparable import ( assert_command_equal, + assert_command_publishing_blocklist_equal, assert_connection_equal, assert_event_equal, assert_garden_equal, @@ -79,13 +80,19 @@ def test_no_modify(self, system_dict): lazy_fixture("instance_dict"), assert_instance_equal, lazy_fixture("bg_instance"), - ), + ), ( brewtils.models.Command, lazy_fixture("command_dict"), assert_command_equal, lazy_fixture("bg_command"), ), + ( + brewtils.models.CommandPublishingBlocklist, + lazy_fixture("command_publishing_blocklist_dict"), + assert_command_publishing_blocklist_equal, + lazy_fixture("bg_command_publishing_blocklist"), + ), ( brewtils.models.Connection, lazy_fixture("connection_dict"), @@ -220,6 +227,12 @@ def test_single_from_string(self): assert_instance_equal, lazy_fixture("bg_instance"), ), + ( + "parse_command_publishing_blocklist", + lazy_fixture("command_publishing_blocklist_dict"), + assert_command_publishing_blocklist_equal, + lazy_fixture("bg_command_publishing_blocklist"), + ), ( "parse_command", lazy_fixture("command_dict"), @@ -371,6 +384,12 @@ def test_single_specific_from_string(self): assert_command_equal, lazy_fixture("bg_command"), ), + ( + brewtils.models.CommandPublishingBlocklist, + lazy_fixture("command_publishing_blocklist_dict"), + assert_command_publishing_blocklist_equal, + lazy_fixture("bg_command_publishing_blocklist"), + ), ( brewtils.models.Connection, lazy_fixture("connection_dict"), @@ -509,6 +528,12 @@ def test_many(self, model, data, assertion, expected): assert_command_equal, lazy_fixture("bg_command"), ), + ( + "parse_command_publishing_blocklist", + lazy_fixture("command_publishing_blocklist_dict"), + assert_command_publishing_blocklist_equal, + lazy_fixture("bg_command_publishing_blocklist"), + ), ( "parse_connection", lazy_fixture("connection_dict"), @@ -648,6 +673,7 @@ class TestSerialize(object): (lazy_fixture("bg_system"), lazy_fixture("system_dict")), (lazy_fixture("bg_instance"), lazy_fixture("instance_dict")), (lazy_fixture("bg_command"), lazy_fixture("command_dict")), + (lazy_fixture("bg_command_publishing_blocklist"), lazy_fixture("command_publishing_blocklist_dict")), (lazy_fixture("bg_connection"), lazy_fixture("connection_dict")), (lazy_fixture("bg_parameter"), lazy_fixture("parameter_dict")), (lazy_fixture("bg_request"), lazy_fixture("request_dict")), @@ -689,6 +715,11 @@ def test_single(self, model, expected): lazy_fixture("bg_command"), lazy_fixture("command_dict"), ), + ( + "serialize_command_publishing_blocklist", + lazy_fixture("bg_command_publishing_blocklist"), + lazy_fixture("command_publishing_blocklist_dict"), + ), ( "serialize_connection", lazy_fixture("bg_connection"), @@ -789,6 +820,7 @@ def test_single_specific(self, method, data, expected): (lazy_fixture("bg_system"), lazy_fixture("system_dict")), (lazy_fixture("bg_instance"), lazy_fixture("instance_dict")), (lazy_fixture("bg_command"), lazy_fixture("command_dict")), + (lazy_fixture("bg_command_publishing_blocklist"), lazy_fixture("command_publishing_blocklist_dict")), (lazy_fixture("bg_connection"), lazy_fixture("connection_dict")), (lazy_fixture("bg_parameter"), lazy_fixture("parameter_dict")), (lazy_fixture("bg_request"), lazy_fixture("request_dict")), @@ -856,6 +888,7 @@ class TestRoundTrip(object): lazy_fixture("bg_instance"), ), (brewtils.models.Command, assert_command_equal, lazy_fixture("bg_command")), + (brewtils.models.CommandPublishingBlocklist, assert_command_publishing_blocklist_equal, lazy_fixture("bg_command_publishing_blocklist")), ( brewtils.models.Connection, assert_connection_equal, @@ -917,6 +950,7 @@ def test_parsed_start(self, model, assertion, data): (brewtils.models.System, lazy_fixture("system_dict")), (brewtils.models.Instance, lazy_fixture("instance_dict")), (brewtils.models.Command, lazy_fixture("command_dict")), + (brewtils.models.CommandPublishingBlocklist, lazy_fixture("command_publishing_blocklist_dict")), (brewtils.models.Connection, lazy_fixture("connection_dict")), (brewtils.models.Parameter, lazy_fixture("parameter_dict")), (brewtils.models.Request, lazy_fixture("request_dict")),