Esempio n. 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'))
Esempio n. 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'))
Esempio n. 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'))        
Esempio n. 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')
Esempio n. 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'))
Esempio n. 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')
Esempio n. 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)
Esempio n. 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)
Esempio n. 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'))
Esempio n. 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')
Esempio n. 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')
Esempio n. 12
0
 def test_pong_response(self):
     'should return the pong protocol'
     self.assertEqual(Protocol.pong_response(), 'PONG\r\n')
Esempio n. 13
0
 def test_pong_response(self):
     'should return the pong protocol'
     self.assertEqual(Protocol.pong_response(), 'PONG\r\n')
Esempio n. 14
0
 def on_ping_request(self):
     'handler when ping request received'
     self.pings += 1
     self.conn.send_command(Protocol.pong_response())
Esempio n. 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'))
Esempio n. 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'))
Esempio n. 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')
Esempio 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')
Esempio n. 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'))
Esempio n. 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()
Esempio n. 21
0
 def on_ping_request(self):
     'handler when ping request received'
     self.pings += 1
     self.conn.send_command(Protocol.pong_response())
Esempio n. 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())
Esempio n. 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()
Esempio n. 24
0
 def test_ping_request(self):
     'should return the ping protocol'
     self.assertEqual(Protocol.ping_request(), 'PING\r\n')
Esempio 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())
Esempio n. 26
0
 def test_ping_request(self):
     'should return the ping protocol'
     self.assertEqual(Protocol.ping_request(), 'PING\r\n')