-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a severity to messages #48
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -22,11 +22,44 @@ | |
import jsonschema | ||
import mock | ||
|
||
from fedora_messaging import message | ||
from fedora_messaging import message, exceptions | ||
|
||
|
||
class GetMessageTests(unittest.TestCase): | ||
"""Tests for the :func:`fedora_messaging.message.get_message` function.""" | ||
|
||
def test_missing_severity(self): | ||
"""Assert the default severity is INFO if it's not in the headers.""" | ||
msg = message.Message(severity=message.ERROR) | ||
del msg._headers["fedora_messaging_severity"] | ||
|
||
recv_msg = message.get_message("", msg._properties, b"{}") | ||
self.assertEqual(recv_msg.severity, message.INFO) | ||
|
||
def test_invalid_severity(self): | ||
"""Assert the invalid severity fails validation.""" | ||
msg = message.Message() | ||
msg._headers["fedora_messaging_severity"] = 42 | ||
|
||
self.assertRaises( | ||
exceptions.ValidationError, message.get_message, "", msg._properties, b"{}" | ||
) | ||
|
||
def test_missing_headers(self): | ||
"""Assert missing headers results in a default message.""" | ||
msg = message.Message() | ||
msg._headers = None | ||
expected_message = message.Message() | ||
expected_message.id = msg.id | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't seem to be using this variable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, good eye |
||
|
||
received_msg = message.get_message( | ||
msg._encoded_routing_key, msg._properties, msg._encoded_body | ||
) | ||
self.assertIsInstance(received_msg, message.Message) | ||
|
||
|
||
class MessageTests(unittest.TestCase): | ||
"""Tests for the :mod:`fedora_messaging.message` module.""" | ||
"""Tests for the :class:`fedora_messaging.message.Message` class.""" | ||
|
||
def test_summary(self): | ||
"""Assert message summaries default to the message topic.""" | ||
|
@@ -99,6 +132,18 @@ def test_headers(self): | |
"fedora_messaging.message:Message", | ||
) | ||
|
||
def test_severity_default_header_set(self): | ||
"""Assert the default severity is placed in the header if unspecified.""" | ||
self.assertEqual(message.Message.severity, message.INFO) | ||
msg = message.Message() | ||
self.assertEqual(msg._headers["fedora_messaging_severity"], message.INFO) | ||
|
||
def test_severity_custom_header_set(self): | ||
"""Assert custom severity setting is placed in the header.""" | ||
self.assertEqual(message.Message.severity, message.INFO) | ||
msg = message.Message(severity=message.ERROR) | ||
self.assertEqual(msg._headers["fedora_messaging_severity"], message.ERROR) | ||
|
||
def test_sent_at(self): | ||
"""Assert a timestamp is inserted and contains explicit timezone information.""" | ||
mock_datetime = mock.Mock() | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're doing this so people don't override the base schemas too much? Are you thinking of a specific use case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking that for the headers, it'd be good to validate we added the expected schema, timestamp, etc. keys and the easiest way would be to add it to the schema, but then I wanted people to have the ability to expand upon it. With the body I think it's reasonable to demand all messages be an object, so this makes it enforced.
I can't really think of a use-case for users to actually add headers at the moment so maybe that should all be an internal thing, though.