示例#1
0
class WhenPublishingJSONMessage(_BaseTestCase):
    __contexts__ = (('super', patch(mod + '.super', create=True)), )

    def configure(self):
        self.ctx.super.return_value = self.superclass = MagicMock()
        self.publisher = BlockingJSONPublisher(sentinel.broker)
        self.publisher._serialize = MagicMock(return_value=sentinel.body)
        self.publisher._channel = MagicMock(is_open=True)
        self.properties = MagicMock(content_type=None)

    def execute(self):
        self.publisher.publish(sentinel.exchange, sentinel.routing_key,
                               sentinel.payload, self.properties)

    def should_serialize_payload(self):
        self.publisher._serialize.assert_called_once_with(sentinel.payload)

    def should_call_super(self):
        self.ctx.super.assert_called_once_with(JSONPublisherMixin,
                                               self.publisher)

    def should_call_publish_on_superclass(self):
        self.superclass.publish.assert_called_once_with(
            sentinel.exchange, sentinel.routing_key, sentinel.body,
            self.properties)

    def should_set_content_type(self):
        self.assertEqual(self.properties.content_type, 'application/json')
示例#2
0
class WhenPublishingJSONMessage(_BaseTestCase):
    __contexts__ = (
        ('super', patch(mod + '.super', create=True)),
    )

    def configure(self):
        self.ctx.super.return_value = self.superclass = MagicMock()
        self.publisher = BlockingJSONPublisher(sentinel.broker)
        self.publisher._serialize = MagicMock(return_value=sentinel.body)
        self.publisher._channel = MagicMock(is_open=True)
        self.properties = MagicMock(content_type=None)

    def execute(self):
        self.publisher.publish(sentinel.exchange, sentinel.routing_key,
                               sentinel.payload, self.properties)

    def should_serialize_payload(self):
        self.publisher._serialize.assert_called_once_with(sentinel.payload)

    def should_call_super(self):
        self.ctx.super.assert_called_once_with(JSONPublisherMixin,
                                               self.publisher)

    def should_call_publish_on_superclass(self):
        self.superclass.publish.assert_called_once_with(sentinel.exchange,
                                                        sentinel.routing_key,
                                                        sentinel.body,
                                                        self.properties)

    def should_set_content_type(self):
        self.assertEqual(self.properties.content_type, 'application/json')
示例#3
0
 def execute(self):
     BlockingJSONPublisher(self.broker).publish(self.exchange,
                                                self.routing_key,
                                                self.payload)
示例#4
0
 def configure(self):
     self.ctx.super.return_value = self.superclass = MagicMock()
     self.publisher = BlockingJSONPublisher(sentinel.broker)
     self.publisher._serialize = MagicMock(return_value=sentinel.body)
     self.publisher._channel = MagicMock(is_open=True)
     self.properties = MagicMock(content_type=None)
示例#5
0
 def should_extend_BlockingPublisher(self):
     isinstance(BlockingJSONPublisher(sentinel.broker), BlockingPublisher)
示例#6
0
 def configure(self):
     self.ctx.super.return_value = self.superclass = MagicMock()
     self.publisher = BlockingJSONPublisher(sentinel.broker)
     self.publisher._serialize = MagicMock(return_value=sentinel.body)
     self.publisher._channel = MagicMock(is_open=True)
     self.properties = MagicMock(content_type=None)