Пример #1
0
 def test_assert_right_proto_type(self):
     'should return True if the msg if matched the reg of  given proto'
     with patch.dict(Protocol.PROTOCOL_TABLE, {
        'proto' : 'content'
         }, clear=True):
         msg = 'content'
         self.assertTrue(Protocol.assert_protocol_type(msg, 'proto'))
Пример #2
0
 def test_protocol_regular_in_table(self):
     'should return the proto regular if in protocol table'
     with patch.dict(Protocol.PROTOCOL_TABLE, {
        'proto' : 'content'
         }, clear=True):
         self.assertEqual(Protocol.protocol_regular('proto'), 
         	re.compile('content'))
Пример #3
0
 def test_nonexist_proto(self):
     'should return False if proto not in table'
     with patch.dict(Protocol.PROTOCOL_TABLE, {
         'proto' : 'content'
           }, clear=True):
         msg = 'content'
         self.assertFalse(Protocol.assert_protocol_type(msg, 'nonexist'))        
Пример #4
0
 def test_not_matched(self):
     'should return the un-matched part of message'
     with patch.dict(Protocol.PROTOCOL_TABLE, {
         'proto' : 'content'
           }, clear=True):
         msg = 'content_not_matched'
         self.assertEqual(Protocol.not_matched('proto', msg), '_not_matched')
Пример #5
0
 def test_assert_wrong_proto_type(self):
     'should return False if msg not matched the reg of given proto'
     with patch.dict(Protocol.PROTOCOL_TABLE, {
         'proto' : 'content'
           }, clear=True):
         msg = 'somemsg'
         self.assertFalse(Protocol.assert_protocol_type(msg, 'proto'))
Пример #6
0
 def test_not_matched(self):
     'should return the un-matched part of message'
     with patch.dict(Protocol.PROTOCOL_TABLE, {'proto': 'content'},
                     clear=True):
         msg = 'content_not_matched'
         self.assertEqual(Protocol.not_matched('proto', msg),
                          '_not_matched')
Пример #7
0
    def _process_info(self, info):
        '''\
        process server infomation message;

        Params:
        =====
        info: nats server information
        '''
        server_info = json.loads(info)
        if server_info["auth_required"]:
            conn_opts = self.conn.get_connection_options()
            self.conn.send_command(Protocol.connect_command(conn_opts), True)
Пример #8
0
    def _process_info(self, info):
        '''\
        process server infomation message;

        Params:
        =====
        info: nats server information
        '''
        server_info = json.loads(info)
        if server_info["auth_required"]:
            conn_opts = self.conn.get_connection_options()
            self.conn.send_command(Protocol.connect_command(conn_opts),
                True)
Пример #9
0
 def test_protocol_regular_in_table(self):
     'should return the proto regular if in protocol table'
     with patch.dict(Protocol.PROTOCOL_TABLE, {'proto': 'content'},
                     clear=True):
         self.assertEqual(Protocol.protocol_regular('proto'),
                          re.compile('content'))
Пример #10
0
 def test_version(self):
     'should return the protocol version'
     #with patch.dict(Protocol, PROTOCOL_VERSION='0-0-0-0'):
     version = Protocol.version()
     self.assertEqual(version, '0.5.0.beta.12')
Пример #11
0
 def test_connect_command(self):
     'should return the connect command'
     opts = {'user': '******', 'pass': '******'}
     self.assertEqual(Protocol.connect_command(opts),
                      'CONNECT {"user": "******", "pass": "******"}\r\n')
Пример #12
0
 def test_pong_response(self):
     'should return the pong protocol'
     self.assertEqual(Protocol.pong_response(), 'PONG\r\n')
Пример #13
0
 def test_pong_response(self):
     'should return the pong protocol'
     self.assertEqual(Protocol.pong_response(), 'PONG\r\n')
Пример #14
0
 def on_ping_request(self):
     'handler when ping request received'
     self.pings += 1
     self.conn.send_command(Protocol.pong_response())
Пример #15
0
 def test_nonexist_proto(self):
     'should return False if proto not in table'
     with patch.dict(Protocol.PROTOCOL_TABLE, {'proto': 'content'},
                     clear=True):
         msg = 'content'
         self.assertFalse(Protocol.assert_protocol_type(msg, 'nonexist'))
Пример #16
0
 def test_assert_right_proto_type(self):
     'should return True if the msg if matched the reg of  given proto'
     with patch.dict(Protocol.PROTOCOL_TABLE, {'proto': 'content'},
                     clear=True):
         msg = 'content'
         self.assertTrue(Protocol.assert_protocol_type(msg, 'proto'))
Пример #17
0
 def test_connect_command(self):
     'should return the connect command'
     opts = {'user' : 'a', 'pass' : 'b'}
     self.assertEqual(Protocol.connect_command(opts), 
      	'CONNECT {"user": "******", "pass": "******"}\r\n')
Пример #18
0
 def test_version(self):
     'should return the protocol version' 
     #with patch.dict(Protocol, PROTOCOL_VERSION='0-0-0-0'):
     version = Protocol.version()
     self.assertEqual(version, '0.5.0.beta.12')
Пример #19
0
 def test_assert_wrong_proto_type(self):
     'should return False if msg not matched the reg of given proto'
     with patch.dict(Protocol.PROTOCOL_TABLE, {'proto': 'content'},
                     clear=True):
         msg = 'somemsg'
         self.assertFalse(Protocol.assert_protocol_type(msg, 'proto'))
Пример #20
0
 def send_ping(self):
     "send ping request to nats server"
     self.pings_outstanding += 1
     self.conn.send_command(Protocol.ping_request())
     self.queue_server_rt(self.process_pong)
     self.conn.flush_pending()
Пример #21
0
 def on_ping_request(self):
     'handler when ping request received'
     self.pings += 1
     self.conn.send_command(Protocol.pong_response())
Пример #22
0
 def queue_server_rt(self, blk):
     'queue server response'
     if not blk:
         return None
     self.pongs.put(blk)
     self.conn.send_command(Protocol.ping_request())
Пример #23
0
 def send_ping(self):
     "send ping request to nats server"
     self.pings_outstanding += 1
     self.conn.send_command(Protocol.ping_request())
     self.queue_server_rt(self.process_pong)
     self.conn.flush_pending()
Пример #24
0
 def test_ping_request(self):
     'should return the ping protocol'
     self.assertEqual(Protocol.ping_request(), 'PING\r\n')
Пример #25
0
 def queue_server_rt(self, blk):
     'queue server response'
     if not blk:
         return None
     self.pongs.put(blk)
     self.conn.send_command(Protocol.ping_request())
Пример #26
0
 def test_ping_request(self):
     'should return the ping protocol'
     self.assertEqual(Protocol.ping_request(), 'PING\r\n')