Example #1
0
 def test_inbound_header__empty_body(self):
     m = Message()
     m.properties = {}
     buf = pack(b'>HxxQ', m.CLASS_ID, 0)
     buf += m._serialize_properties()
     assert m.inbound_header(buf, offset=0) == 12
     assert m.ready
 def test_inbound_header__empty_body(self):
     m = Message()
     m.properties = {}
     buf = pack(b'>HxxQ', m.CLASS_ID, 0)
     buf += m._serialize_properties()
     self.assertEqual(m.inbound_header(buf, offset=0), 12)
     self.assertTrue(m.ready)
 def test_load_properties(self):
     m = Message()
     m.properties = {
         'content_type': 'application/json',
         'content_encoding': 'utf-8',
         'application_headers': {
             'foo': 1,
             'id': 'id#1',
         },
         'delivery_mode': 1,
         'priority': 255,
         'correlation_id': 'df31-142f-34fd-g42d',
         'reply_to': 'cosmo',
         'expiration': '2015-12-23',
         'message_id': '3312',
         'timestamp': 3912491234,
         'type': 'generic',
         'user_id': 'george',
         'app_id': 'vandelay',
         'cluster_id': 'NYC',
     }
     s = m._serialize_properties()
     m2 = Message()
     m2._load_properties(m2.CLASS_ID, s)
     self.assertDictEqual(m2.properties, m.properties)
Example #4
0
 def test_load_properties(self):
     m = Message()
     m.properties = {
         'content_type': 'application/json',
         'content_encoding': 'utf-8',
         'application_headers': {
             'foo': 1,
             'id': 'id#1',
         },
         'delivery_mode': 1,
         'priority': 255,
         'correlation_id': 'df31-142f-34fd-g42d',
         'reply_to': 'cosmo',
         'expiration': '2015-12-23',
         'message_id': '3312',
         'timestamp': 3912491234,
         'type': 'generic',
         'user_id': 'george',
         'app_id': 'vandelay',
         'cluster_id': 'NYC',
     }
     s = m._serialize_properties()
     m2 = Message()
     m2._load_properties(m2.CLASS_ID, s)
     assert m2.properties == m.properties
Example #5
0
 def test_inbound_header__empty_body(self):
     m = Message()
     m.properties = {}
     buf = pack('>HxxQ', m.CLASS_ID, 0)
     buf += m._serialize_properties()
     assert m.inbound_header(buf, offset=0) == 12
     assert m.ready
Example #6
0
 def test_inbound_header__empty_body(self):
     m = Message()
     m.properties = {}
     buf = pack(">HxxQ", m.CLASS_ID, 0)
     buf += m._serialize_properties()
     self.assertEqual(m.inbound_header(buf, offset=0), 12)
     self.assertTrue(m.ready)
Example #7
0
 def test_inbound_header(self):
     m = Message()
     m.properties = {"content_type": "application/json", "content_encoding": "utf-8"}
     body = "the quick brown fox"
     buf = b"\0" * 30 + pack(">HxxQ", m.CLASS_ID, len(body))
     buf += m._serialize_properties()
     self.assertEqual(m.inbound_header(buf, offset=30), 42)
     self.assertEqual(m.body_size, len(body))
     self.assertEqual(m.properties["content_type"], "application/json")
     self.assertFalse(m.ready)
Example #8
0
 def test_inbound_header(self):
     m = Message()
     m.properties = {
         'content_type': 'application/json',
         'content_encoding': 'utf-8',
     }
     body = 'the quick brown fox'
     buf = b'\0' * 30 + pack(b'>HxxQ', m.CLASS_ID, len(body))
     buf += m._serialize_properties()
     self.assertEqual(m.inbound_header(buf, offset=30), 42)
     self.assertEqual(m.body_size, len(body))
     self.assertEqual(m.properties['content_type'], 'application/json')
     self.assertFalse(m.ready)
 def test_inbound_header(self):
     m = Message()
     m.properties = {
         'content_type': 'application/json',
         'content_encoding': 'utf-8',
     }
     body = 'the quick brown fox'
     buf = b'\0' * 30 + pack(b'>HxxQ', m.CLASS_ID, len(body))
     buf += m._serialize_properties()
     self.assertEqual(m.inbound_header(buf, offset=30), 42)
     self.assertEqual(m.body_size, len(body))
     self.assertEqual(m.properties['content_type'], 'application/json')
     self.assertFalse(m.ready)
Example #10
0
 def test_inbound_header(self):
     m = Message()
     m.properties = {
         'content_type': 'application/json',
         'content_encoding': 'utf-8',
     }
     body = 'the quick brown fox'
     buf = b'\0' * 30 + pack('>HxxQ', m.CLASS_ID, len(body))
     buf += m._serialize_properties()
     assert m.inbound_header(buf, offset=30) == 42
     assert m.body_size == len(body)
     assert m.properties['content_type'] == 'application/json'
     assert not m.ready
Example #11
0
 def test_inbound_header(self):
     m = Message()
     m.properties = {
         'content_type': 'application/json',
         'content_encoding': 'utf-8',
     }
     body = 'the quick brown fox'
     buf = b'\0' * 30 + pack(b'>HxxQ', m.CLASS_ID, len(body))
     buf += m._serialize_properties()
     assert m.inbound_header(buf, offset=30) == 42
     assert m.body_size == len(body)
     assert m.properties['content_type'] == 'application/json'
     assert not m.ready
Example #12
0
 def test_load_properties__some_missing(self):
     m = Message()
     m.properties = {
         'content_type': 'application/json',
         'content_encoding': 'utf-8',
         'delivery_mode': 1,
         'correlation_id': 'df31-142f-34fd-g42d',
         'reply_to': 'cosmo',
         'expiration': '2015-12-23',
         'message_id': '3312',
         'type': None,
         'app_id': None,
         'cluster_id': None,
     }
     s = m._serialize_properties()
     m2 = Message()
     m2._load_properties(m2.CLASS_ID, s)
Example #13
0
 def test_load_properties__some_missing(self):
     m = Message()
     m.properties = {
         'content_type': 'application/json',
         'content_encoding': 'utf-8',
         'delivery_mode': 1,
         'correlation_id': 'df31-142f-34fd-g42d',
         'reply_to': 'cosmo',
         'expiration': '2015-12-23',
         'message_id': '3312',
         'type': None,
         'app_id': None,
         'cluster_id': None,
     }
     s = m._serialize_properties()
     m2 = Message()
     m2._load_properties(m2.CLASS_ID, s)
Example #14
0
 def test_load_properties__some_missing(self):
     m = Message()
     m.properties = {
         "content_type": "application/json",
         "content_encoding": "utf-8",
         "delivery_mode": 1,
         "correlation_id": "df31-142f-34fd-g42d",
         "reply_to": "cosmo",
         "expiration": "2015-12-23",
         "message_id": "3312",
         "type": None,
         "app_id": None,
         "cluster_id": None,
     }
     s = m._serialize_properties()
     m2 = Message()
     m2._load_properties(m2.CLASS_ID, s)
Example #15
0
    def test_header_message_empty_body(self):
        assert not self.g((1, 1, pack('>HH', *spec.Basic.Deliver)))
        self.callback.assert_not_called()

        with pytest.raises(UnexpectedFrame):
            self.g((1, 1, pack('>HH', *spec.Basic.Deliver)))

        m = Message()
        m.properties = {}
        buf = pack('>HxxQ', m.CLASS_ID, 0)
        buf += m._serialize_properties()
        assert self.g((2, 1, buf))

        self.callback.assert_called()
        msg = self.callback.call_args[0][3]
        self.callback.assert_called_with(
            1, msg.frame_method, msg.frame_args, msg,
        )
Example #16
0
    def test_header_message_content(self):
        assert not self.g((1, 1, pack('>HH', *spec.Basic.Deliver)))
        self.callback.assert_not_called()

        m = Message()
        m.properties = {}
        buf = pack('>HxxQ', m.CLASS_ID, 16)
        buf += m._serialize_properties()
        assert not self.g((2, 1, buf))
        self.callback.assert_not_called()

        assert not self.g((3, 1, b'thequick'))
        self.callback.assert_not_called()

        assert self.g((3, 1, b'brownfox'))
        self.callback.assert_called()
        msg = self.callback.call_args[0][3]
        self.callback.assert_called_with(
            1, msg.frame_method, msg.frame_args, msg,
        )
        assert msg.body == b'thequickbrownfox'
Example #17
0
 def test_load_properties(self):
     m = Message()
     m.properties = {
         "content_type": "application/json",
         "content_encoding": "utf-8",
         "application_headers": {"foo": 1, "id": "id#1"},
         "delivery_mode": 1,
         "priority": 255,
         "correlation_id": "df31-142f-34fd-g42d",
         "reply_to": "cosmo",
         "expiration": "2015-12-23",
         "message_id": "3312",
         "timestamp": 3912491234,
         "type": "generic",
         "user_id": "george",
         "app_id": "vandelay",
         "cluster_id": "NYC",
     }
     s = m._serialize_properties()
     m2 = Message()
     m2._load_properties(m2.CLASS_ID, s)
     self.assertDictEqual(m2.properties, m.properties)