Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBurchLog committed Jul 10, 2024
1 parent d24476c commit 0ea6750
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 26 deletions.
3 changes: 2 additions & 1 deletion brewtils/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-

from datetime import datetime
from enum import Enum

import pytz # noqa # not in requirements file
import six # noqa # not in requirements file
from datetime import datetime

from brewtils.errors import ModelError, _deprecate

Expand Down Expand Up @@ -465,6 +465,7 @@ def __repr__(self):
self.history,
)


class RequestFile(BaseModel):
schema = "RequestFileSchema"

Expand Down
13 changes: 8 additions & 5 deletions brewtils/schema_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def parse_topic(cls, topic, from_string=False, **kwargs):
return cls.parse(
topic, brewtils.models.Topic, from_string=from_string, **kwargs
)

@classmethod
def parse_status_info(cls, status_info, from_string=False, **kwargs):
"""Convert raw JSON string or dictionary to a status info model object
Expand All @@ -454,7 +454,7 @@ def parse_status_info(cls, status_info, from_string=False, **kwargs):
return cls.parse(
status_info, brewtils.models.StatusInfo, from_string=from_string, **kwargs
)

@classmethod
def parse_status_history(cls, status_history, from_string=False, **kwargs):
"""Convert raw JSON string or dictionary to a status history model object
Expand All @@ -468,7 +468,10 @@ def parse_status_history(cls, status_history, from_string=False, **kwargs):
A StatusHistory object
"""
return cls.parse(
status_history, brewtils.models.StatusHistory, from_string=from_string, **kwargs
status_history,
brewtils.models.StatusHistory,
from_string=from_string,
**kwargs
)

@classmethod
Expand Down Expand Up @@ -976,7 +979,7 @@ def serialize_topic(cls, topic, to_string=True, **kwargs):
schema_name=brewtils.models.Topic.schema,
**kwargs
)

@classmethod
def serialize_status_info(cls, status_info, to_string=True, **kwargs):
"""Convert a status info model into serialized form
Expand All @@ -996,7 +999,7 @@ def serialize_status_info(cls, status_info, to_string=True, **kwargs):
schema_name=brewtils.models.StatusInfo.schema,
**kwargs
)

@classmethod
def serialize_status_history(cls, status_history, to_string=True, **kwargs):
"""Convert a status history model into serialized form
Expand Down
12 changes: 6 additions & 6 deletions brewtils/test/comparable.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
RequestTemplate,
Resolvable,
Runner,
System,
StatusHistory,
StatusInfo,
Subscriber,
System,
Topic,
StatusHistory,
StatusInfo
)

__all__ = [
Expand Down Expand Up @@ -202,6 +202,7 @@ def _assert_wrapper(obj1, obj2, expected_type=None, do_raise=False, **kwargs):
assert_subscriber_equal = partial(_assert_wrapper, expected_type=Subscriber)
assert_status_history_equal = partial(_assert_wrapper, expected_type=StatusHistory)


def assert_status_info_equal(obj1, obj2, do_raise=False):
return _assert_wrapper(
obj1,
Expand All @@ -213,6 +214,7 @@ def assert_status_info_equal(obj1, obj2, do_raise=False):
do_raise=do_raise,
)


def assert_instance_equal(obj1, obj2, do_raise=False):
return _assert_wrapper(
obj1,
Expand All @@ -222,6 +224,7 @@ def assert_instance_equal(obj1, obj2, do_raise=False):
do_raise=do_raise,
)


def assert_connection_equal(obj1, obj2, do_raise=False):
return _assert_wrapper(
obj1,
Expand Down Expand Up @@ -438,6 +441,3 @@ def assert_topic_equal(obj1, obj2, do_raise=False):
},
do_raise=do_raise,
)



27 changes: 16 additions & 11 deletions brewtils/test/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
RequestTemplate,
Resolvable,
Runner,
StatusHistory,
StatusInfo,
Subscriber,
System,
Topic,
StatusHistory,
StatusInfo,
)


Expand Down Expand Up @@ -798,12 +798,13 @@ def bg_connection(connection_dict, bg_status_info):


@pytest.fixture
def bg_connection_publishing(connection_publishing_dict):
def bg_connection_publishing(connection_publishing_dict, bg_status_info):
"""An connection as a model."""
dict_copy = copy.deepcopy(connection_publishing_dict, bg_status_info)
dict_copy = copy.deepcopy(connection_publishing_dict)
dict_copy["status_info"] = bg_status_info
return Connection(**dict_copy)


@pytest.fixture
def status_history_dict(ts_epoch):
"""A status history as a dictionary"""
Expand All @@ -813,6 +814,7 @@ def status_history_dict(ts_epoch):
"heartbeat": ts_epoch,
}


@pytest.fixture
def bg_status_history(status_history_dict, ts_dt):
dict_copy = copy.deepcopy(status_history_dict)
Expand All @@ -824,10 +826,8 @@ def bg_status_history(status_history_dict, ts_dt):
def status_info_dict(ts_epoch, status_history_dict):
"""A status info as a dictionary"""

return {
"heartbeat": ts_epoch,
"history": [status_history_dict]
}
return {"heartbeat": ts_epoch, "history": [status_history_dict]}


@pytest.fixture
def bg_status_info(status_info_dict, ts_dt, bg_status_history):
Expand All @@ -836,8 +836,11 @@ def bg_status_info(status_info_dict, ts_dt, bg_status_history):
dict_copy["heartbeat"] = ts_dt
return StatusInfo(**dict_copy)


@pytest.fixture
def garden_dict(ts_epoch, system_dict, connection_dict, connection_publishing_dict, status_info_dict):
def garden_dict(
ts_epoch, system_dict, connection_dict, connection_publishing_dict, status_info_dict
):
"""A garden as a dictionary."""

return {
Expand All @@ -858,13 +861,15 @@ def garden_dict(ts_epoch, system_dict, connection_dict, connection_publishing_di


@pytest.fixture
def bg_garden(garden_dict, bg_system, bg_connection, bg_connection_publishing, bg_status_info):
def bg_garden(
garden_dict, bg_system, bg_connection, bg_connection_publishing, bg_status_info
):
"""An operation as a model."""
dict_copy = copy.deepcopy(garden_dict)
dict_copy["systems"] = [bg_system]
dict_copy["receiving_connections"] = [bg_connection]
dict_copy["publishing_connections"] = [bg_connection_publishing]
dict_copy["status_info"] = [bg_status_info]
dict_copy["status_info"] = bg_status_info
return Garden(**dict_copy)


Expand Down
83 changes: 80 additions & 3 deletions test/schema_parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@

import copy

import brewtils.models
import pytest
from marshmallow.exceptions import MarshmallowError
from pytest_lazyfixture import lazy_fixture

import brewtils.models
from brewtils.models import System
from brewtils.schema_parser import SchemaParser
from brewtils.test.comparable import (
Expand All @@ -28,12 +31,12 @@
assert_resolvable_equal,
assert_role_equal,
assert_runner_equal,
assert_status_history_equal,
assert_status_info_equal,
assert_subscriber_equal,
assert_system_equal,
assert_topic_equal,
)
from marshmallow.exceptions import MarshmallowError
from pytest_lazyfixture import lazy_fixture


class TestParse(object):
Expand Down Expand Up @@ -194,6 +197,18 @@ def test_no_modify(self, system_dict):
assert_topic_equal,
lazy_fixture("bg_topic"),
),
(
brewtils.models.StatusInfo,
lazy_fixture("status_info_dict"),
assert_status_info_equal,
lazy_fixture("bg_status_info"),
),
(
brewtils.models.StatusHistory,
lazy_fixture("status_history_dict"),
assert_status_history_equal,
lazy_fixture("bg_status_history"),
),
],
)
def test_single(self, model, data, assertion, expected):
Expand Down Expand Up @@ -340,6 +355,18 @@ def test_single_from_string(self):
assert_topic_equal,
lazy_fixture("bg_topic"),
),
(
"parse_status_info",
lazy_fixture("status_info_dict"),
assert_status_info_equal,
lazy_fixture("bg_status_info"),
),
(
"parse_status_history",
lazy_fixture("status_history_dict"),
assert_status_history_equal,
lazy_fixture("bg_status_history"),
),
],
)
def test_single_specific(self, method, data, assertion, expected):
Expand Down Expand Up @@ -479,6 +506,18 @@ def test_single_specific_from_string(self):
assert_topic_equal,
lazy_fixture("bg_topic"),
),
(
brewtils.models.StatusInfo,
lazy_fixture("status_info_dict"),
assert_status_info_equal,
lazy_fixture("bg_status_info"),
),
(
brewtils.models.StatusHistory,
lazy_fixture("status_history_dict"),
assert_status_history_equal,
lazy_fixture("bg_status_history"),
),
],
)
def test_many(self, model, data, assertion, expected):
Expand Down Expand Up @@ -611,6 +650,18 @@ def test_many(self, model, data, assertion, expected):
assert_topic_equal,
lazy_fixture("bg_topic"),
),
(
"parse_status_info",
lazy_fixture("status_info_dict"),
assert_status_info_equal,
lazy_fixture("bg_status_info"),
),
(
"parse_status_history",
lazy_fixture("status_history_dict"),
assert_status_history_equal,
lazy_fixture("bg_status_history"),
),
],
)
def test_many_specific(self, method, data, assertion, expected):
Expand Down Expand Up @@ -666,6 +717,8 @@ class TestSerialize(object):
(lazy_fixture("bg_resolvable"), lazy_fixture("resolvable_dict")),
(lazy_fixture("bg_subscriber"), lazy_fixture("subscriber_dict")),
(lazy_fixture("bg_topic"), lazy_fixture("topic_dict")),
(lazy_fixture("bg_status_info"), lazy_fixture("status_info_dict")),
(lazy_fixture("bg_status_history"), lazy_fixture("status_history_dict")),
],
)
def test_single(self, model, expected):
Expand Down Expand Up @@ -777,6 +830,16 @@ def test_single(self, model, expected):
lazy_fixture("bg_topic"),
lazy_fixture("topic_dict"),
),
(
"serialize_status_info",
lazy_fixture("bg_status_info"),
lazy_fixture("status_info_dict"),
),
(
"serialize_status_history",
lazy_fixture("bg_status_history"),
lazy_fixture("status_history_dict"),
),
],
)
def test_single_specific(self, method, data, expected):
Expand Down Expand Up @@ -807,6 +870,8 @@ def test_single_specific(self, method, data, expected):
(lazy_fixture("bg_resolvable"), lazy_fixture("resolvable_dict")),
(lazy_fixture("bg_subscriber"), lazy_fixture("subscriber_dict")),
(lazy_fixture("bg_topic"), lazy_fixture("topic_dict")),
(lazy_fixture("bg_status_info"), lazy_fixture("status_info_dict")),
(lazy_fixture("bg_status_history"), lazy_fixture("status_history_dict")),
],
)
def test_many(self, model, expected):
Expand Down Expand Up @@ -901,6 +966,16 @@ class TestRoundTrip(object):
lazy_fixture("bg_subscriber"),
),
(brewtils.models.Topic, assert_topic_equal, lazy_fixture("bg_topic")),
(
brewtils.models.StatusInfo,
assert_status_info_equal,
lazy_fixture("bg_status_info"),
),
(
brewtils.models.StatusHistory,
assert_status_history_equal,
lazy_fixture("bg_status_history"),
),
],
)
def test_parsed_start(self, model, assertion, data):
Expand Down Expand Up @@ -932,6 +1007,8 @@ def test_parsed_start(self, model, assertion, data):
(brewtils.models.Operation, lazy_fixture("operation_dict")),
(brewtils.models.Runner, lazy_fixture("runner_dict")),
(brewtils.models.Resolvable, lazy_fixture("resolvable_dict")),
(brewtils.models.StatusInfo, lazy_fixture("status_info_dict")),
(brewtils.models.StatusHistory, lazy_fixture("status_history_dict")),
],
)
def test_serialized_start(self, model, data):
Expand Down

0 comments on commit 0ea6750

Please sign in to comment.