Skip to content

Commit

Permalink
Fixes Message.create mutating properties #92 (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
eandersson committed Mar 16, 2021
1 parent 12bc088 commit 587bb66
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
@@ -1,6 +1,10 @@
Changelog
=========

Version 2.8.4
-------------
- Fixed a bug in Message.create where it would mutate the properties dict [#92] - Thanks Killerama.

Version 2.8.3
-------------
- Fixed pip sdist circular dependency [#88] - Thanks Jay Hogg.
Expand Down
4 changes: 4 additions & 0 deletions README.rst
Expand Up @@ -20,6 +20,10 @@ Additional documentation is available on `amqpstorm.io <https://www.amqpstorm.io
Changelog
=========

Version 2.8.4
-------------
- Fixed a bug in Message.create where it would mutate the properties dict [#92] - Thanks Killerama.

Version 2.8.3
-------------
- Fixed pip sdist circular dependency [#88] - Thanks Jay Hogg.
Expand Down
2 changes: 1 addition & 1 deletion amqpstorm/__init__.py
@@ -1,5 +1,5 @@
"""AMQPStorm."""
__version__ = '2.8.3' # noqa
__version__ = '2.8.4' # noqa
__author__ = 'eandersson' # noqa

import logging
Expand Down
2 changes: 1 addition & 1 deletion amqpstorm/message.py
Expand Up @@ -52,7 +52,7 @@ def create(channel, body, properties=None):
:rtype: Message
"""
properties = properties or {}
properties = dict(properties or {})
if 'correlation_id' not in properties:
properties['correlation_id'] = str(uuid.uuid4())
if 'message_id' not in properties:
Expand Down
21 changes: 21 additions & 0 deletions amqpstorm/tests/unit/message_tests.py
Expand Up @@ -44,6 +44,27 @@ def test_message_default_properties(self):
self.assertIsInstance(message.correlation_id, str)
self.assertIsInstance(message.timestamp, datetime)

def test_message_create_does_not_mutate_properties(self):
properties = {
'content_type': 'application/json',
'headers': {'key': 'value'}
}

message1 = Message.create(None, self.message, properties)
message2 = Message.create(None, self.message, properties)

self.assertNotIn('correlation_id', properties)
self.assertNotIn('message_id', properties)
self.assertNotIn('timestamp', properties)

self.assertIsNotNone(message1.message_id)
self.assertIsNotNone(message1.correlation_id)
self.assertIsNotNone(message1.timestamp)

self.assertNotEqual(message1.message_id, message2.message_id)
self.assertNotEqual(message1.correlation_id, message2.correlation_id)
self.assertNotEqual(message1.timestamp, message2.timestamp)

def test_message_app_id_custom_value(self):
app_id = 'my-app'

Expand Down

0 comments on commit 587bb66

Please sign in to comment.