-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add default topic for PublishClient (#432)
- Loading branch information
1 parent
79a8116
commit 31fcc4e
Showing
4 changed files
with
108 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import pytest | ||
from mock import Mock | ||
|
||
import brewtils.rest | ||
from brewtils.errors import BrewtilsException | ||
from brewtils.models import Event, Events, Request | ||
from brewtils.rest.publish_client import PublishClient | ||
from brewtils.schema_parser import SchemaParser | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def easy_client(monkeypatch): | ||
mock = Mock(name="easy_client") | ||
mock.publish_event.return_value = True | ||
|
||
monkeypatch.setattr( | ||
brewtils.rest.publish_client, "EasyClient", Mock(return_value=mock) | ||
) | ||
|
||
return mock | ||
|
||
|
||
@pytest.fixture | ||
def client(): | ||
return PublishClient(bg_host="localhost", bg_port=3000) | ||
|
||
|
||
class TestPublishClient(object): | ||
def setup_config(self): | ||
brewtils.plugin.CONFIG.namespace = "foo" | ||
brewtils.plugin.CONFIG.name = "foo" | ||
brewtils.plugin.CONFIG.version = "1.0.0" | ||
brewtils.plugin.CONFIG.instance_name = "foo" | ||
brewtils.plugin.CONFIG.bg_host = "localhost" | ||
brewtils.plugin.CONFIG.bg_port = "3000" | ||
|
||
def test_publish(self, client): | ||
assert client.publish(_topic="topic") | ||
|
||
def test_missing_topic(self, client): | ||
with pytest.raises(BrewtilsException): | ||
assert client.publish(not_topic="topic") | ||
|
||
def test_missing_topic_found(self, client, easy_client): | ||
self.setup_config() | ||
assert client.publish(no_topic="topic") | ||
|
||
easy_client.publish_event.assert_called() | ||
called_event = easy_client.publish_event.call_args.args[0] | ||
|
||
assert called_event.metadata["topic"] == "foo.foo.1.0.0.foo" | ||
|
||
def test_verify_generated_request(self, client, easy_client): | ||
assert client.publish( | ||
_topic="topic", _comment="_comment", _parent=None, value="test" | ||
) | ||
|
||
event = Event( | ||
name=Events.REQUEST_TOPIC_PUBLISH.name, | ||
metadata={ | ||
"topic": "topic", | ||
"propagate": False, | ||
"regex_only": False, | ||
}, | ||
payload=Request( | ||
comment="_comment", | ||
output_type=None, | ||
parent=None, | ||
metadata={"_topic": "topic"}, | ||
parameters={"value": "test"}, | ||
), | ||
payload_type="Request", | ||
) | ||
|
||
easy_client.publish_event.assert_called() | ||
called_event = easy_client.publish_event.call_args.args[0] | ||
assert SchemaParser.serialize_event( | ||
called_event | ||
) == SchemaParser.serialize_event(event) |