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)
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)
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)
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)
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)
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)
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)
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:])
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:])
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:])
def test_auth(self): '''Appropriately send auth''' expected = ''.join((constants.AUTH, constants.NL, util.pack('hello'))) self.assertSent(expected, self.connection.auth, 'hello')
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')
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')
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')
def test_string(self): '''Give it a low-ball test''' message = 'hello' self.assertEqual(util.pack(message), struct.pack('>l5s', 5, message))
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)