Esempio n. 1
0
 def test_mpub(self):
     '''Appropriately sends mpub'''
     self.connection.mpub('foo', 'hello', 'howdy')
     expected = ''.join((
         constants.MAGIC_V2, constants.MPUB, ' foo',
         constants.NL, util.pack(['hello', 'howdy'])))
     self.assertEqual(self.read(len(expected)), expected)
Esempio n. 2
0
 def test_send_message(self):
     '''Appropriately sends packed data with message'''
     with self.identify():
         self.client.identify({})
         expected = ''.join(
             (constants.IDENTIFY, constants.NL, util.pack('{}')))
         self.assertEqual(self.read(len(expected)), expected)
Esempio n. 3
0
 def test_send_message(self):
     '''Appropriately sends packed data with message'''
     self.socket.read()
     self.connection.identify({})
     self.connection.flush()
     expected = ''.join((constants.IDENTIFY, constants.NL, util.pack('{}')))
     self.assertEqual(self.socket.read(), expected)
Esempio n. 4
0
 def test_pub(self):
     '''Appropriately sends pub'''
     with self.identify():
         self.client.pub('foo', 'hello')
         expected = ''.join(
             (constants.PUB, ' foo', constants.NL, util.pack('hello')))
         self.assertEqual(self.read(len(expected)), expected)
Esempio n. 5
0
 def test_identify(self):
     '''The connection sends the identify commands'''
     expected = ''.join([
         constants.MAGIC_V2, constants.IDENTIFY, constants.NL,
         util.pack(json.dumps(self.connection._identify_options))
     ])
     self.assertEqual(self.socket.read(), expected)
Esempio n. 6
0
 def test_identify(self):
     '''The connection sends the identify commands'''
     expected = ''.join([
         constants.MAGIC_V2,
         constants.IDENTIFY,
         constants.NL,
         util.pack(json.dumps(self.connection._identify_options))])
     self.assertEqual(self.socket.read(), expected)
Esempio n. 7
0
 def test_send_message(self):
     '''Appropriately sends packed data with message'''
     self.socket.read()
     self.connection.identify({})
     self.connection.flush()
     expected = ''.join(
         (constants.IDENTIFY, constants.NL, util.pack('{}')))
     self.assertEqual(self.socket.read(), expected)
Esempio n. 8
0
 def test_mpub_binary(self):
     '''Publishes messages with binary fine'''
     with self.patched_post() as post:
         post.return_value.content = 'OK'
         messages = map(str, range(10))
         self.client.mpub('topic', messages)
         post.assert_called_with(
             '/mpub',
             params={'topic': 'topic', 'binary': True},
             data=pack(messages)[4:])
Esempio n. 9
0
 def test_mpub_binary(self):
     '''Publishes messages with binary fine'''
     with self.patched_post() as post:
         post.return_value.content = 'OK'
         messages = map(str, range(10))
         self.client.mpub('topic', messages)
         post.assert_called_with(
             'mpub',
             params={'topic': 'topic', 'binary': True},
             data=pack(messages)[4:])
Esempio n. 10
0
 def test_mpub_binary(self):
     '''Publishes messages with binary fine'''
     with self.patched_post() as post:
         post.return_value.content = b'OK'
         messages = [six.text_type(n).encode() for n in range(10)]
         self.client.mpub('topic', messages)
         post.assert_called_with('mpub',
                                 params={
                                     'topic': 'topic',
                                     'binary': True
                                 },
                                 data=pack(messages)[4:])
Esempio n. 11
0
 def test_auth(self):
     '''Appropriately send auth'''
     expected = ''.join((constants.AUTH, constants.NL, util.pack('hello')))
     self.assertSent(expected, self.connection.auth, 'hello')
Esempio n. 12
0
 def test_pub(self):
     '''Appropriately sends pub'''
     expected = ''.join(
         (constants.PUB, ' foo', constants.NL, util.pack('hello')))
     self.assertSent(expected, self.connection.pub, 'foo', 'hello')
Esempio n. 13
0
 def test_mpub(self):
     '''Appropriately sends mpub'''
     expected = ''.join((
         constants.MPUB, ' foo', constants.NL,
         util.pack(['hello', 'howdy'])))
     self.assertSent(expected, self.connection.mpub, 'foo', 'hello', 'howdy')
Esempio n. 14
0
 def test_mpub(self):
     '''Appropriately sends mpub'''
     expected = ''.join((constants.MPUB, ' foo', constants.NL,
                         util.pack(['hello', 'howdy'])))
     self.assertSent(expected, self.connection.mpub, 'foo', 'hello',
                     'howdy')
Esempio n. 15
0
 def test_pub(self):
     '''Appropriately sends pub'''
     expected = ''.join(
         (constants.PUB, ' foo', constants.NL, util.pack('hello')))
     self.assertSent(expected, self.connection.pub, 'foo', 'hello')
Esempio n. 16
0
 def test_auth(self):
     '''Appropriately send auth'''
     expected = ''.join((constants.AUTH, constants.NL, util.pack('hello')))
     self.assertSent(expected, self.connection.auth, 'hello')
Esempio n. 17
0
 def test_string(self):
     '''Give it a low-ball test'''
     message = 'hello'
     self.assertEqual(util.pack(message), struct.pack('>l5s', 5, message))
Esempio n. 18
0
 def test_iterable(self):
     '''Make sure it handles iterables'''
     messages = ['hello'] * 10
     packed = struct.pack('>l5s', 5, 'hello')
     expected = struct.pack('>ll90s', 94, 10, packed * 10)
     self.assertEqual(util.pack(messages), expected)
Esempio n. 19
0
 def test_string(self):
     '''Give it a low-ball test'''
     message = 'hello'
     self.assertEqual(util.pack(message), struct.pack('>l5s', 5, message))
Esempio n. 20
0
 def test_iterable(self):
     '''Make sure it handles iterables'''
     messages = ['hello'] * 10
     packed = struct.pack('>l5s', 5, 'hello')
     expected = struct.pack('>ll90s', 94, 10, packed * 10)
     self.assertEqual(util.pack(messages), expected)