Skip to content

Commit

Permalink
Adding CommandPublishingBlocklist
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBurchLog committed Apr 16, 2024
1 parent 31edd1e commit d34a8ff
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Brewtils Changelog
==================

3.26.0
------
TBD

- Added new model for CommandPublishingBlocklist

3.25.0
------
4/5/2024
Expand Down
30 changes: 30 additions & 0 deletions brewtils/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<CommandPublishingBlocklist: namespace=%s, system=%s, command=%s, status=%s>" % (
self.namespace,
self.system,
self.command,
self.status
)

class Instance(BaseModel):
schema = "InstanceSchema"
Expand Down
37 changes: 37 additions & 0 deletions brewtils/schema_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
7 changes: 7 additions & 0 deletions brewtils/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"SystemSchema",
"InstanceSchema",
"CommandSchema",
"CommandPublishingBlocklistSchema",
"ParameterSchema",
"RequestSchema",
"RequestFileSchema",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -661,6 +667,7 @@ class UserListSchema(BaseSchema):
{
"Choices": ChoicesSchema,
"Command": CommandSchema,
"CommandPublishingBlocklist": CommandPublishingBlocklistSchema,
"Connection": ConnectionSchema,
"CronTrigger": CronTriggerSchema,
"DateTrigger": DateTriggerSchema,
Expand Down
2 changes: 2 additions & 0 deletions brewtils/test/comparable.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from brewtils.models import (
Choices,
Command,
CommandPublishingBlocklist,
Connection,
CronTrigger,
DateTrigger,
Expand Down Expand Up @@ -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):
Expand Down
16 changes: 16 additions & 0 deletions brewtils/test/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from brewtils.models import (
Choices,
Command,
CommandPublishingBlocklist,
Connection,
CronTrigger,
DateTrigger,
Expand Down Expand Up @@ -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):
Expand Down
36 changes: 35 additions & 1 deletion test/schema_parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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")),
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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")),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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")),
Expand Down

0 comments on commit d34a8ff

Please sign in to comment.