예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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:])
예제 #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:])
예제 #10
0
파일: test_nsqd.py 프로젝트: lambdaq/nsq-py
 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:])
예제 #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')
예제 #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')
예제 #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')
예제 #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')
예제 #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')
예제 #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')
예제 #17
0
 def test_string(self):
     '''Give it a low-ball test'''
     message = 'hello'
     self.assertEqual(util.pack(message), struct.pack('>l5s', 5, message))
예제 #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)
예제 #19
0
 def test_string(self):
     '''Give it a low-ball test'''
     message = 'hello'
     self.assertEqual(util.pack(message), struct.pack('>l5s', 5, message))
예제 #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)