コード例 #1
0
ファイル: test_unit.py プロジェクト: PyHUBKyiv/python-nats
 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
ファイル: test_unit.py プロジェクト: PyHUBKyiv/python-nats
 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
ファイル: test_unit.py プロジェクト: PyHUBKyiv/python-nats
 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
ファイル: test_unit.py プロジェクト: PyHUBKyiv/python-nats
 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
ファイル: test_unit.py プロジェクト: PyHUBKyiv/python-nats
 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
ファイル: test_unit.py プロジェクト: eodreports/python-nats
 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
ファイル: client.py プロジェクト: eodreports/python-nats
    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
ファイル: client.py プロジェクト: PyHUBKyiv/python-nats
    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
ファイル: test_unit.py プロジェクト: eodreports/python-nats
 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
ファイル: test_unit.py プロジェクト: eodreports/python-nats
 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
ファイル: test_unit.py プロジェクト: eodreports/python-nats
 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
ファイル: test_unit.py プロジェクト: eodreports/python-nats
 def test_pong_response(self):
     'should return the pong protocol'
     self.assertEqual(Protocol.pong_response(), 'PONG\r\n')
コード例 #13
0
ファイル: test_unit.py プロジェクト: PyHUBKyiv/python-nats
 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
ファイル: test_unit.py プロジェクト: eodreports/python-nats
 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
ファイル: test_unit.py プロジェクト: eodreports/python-nats
 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
ファイル: test_unit.py プロジェクト: PyHUBKyiv/python-nats
 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
ファイル: test_unit.py プロジェクト: PyHUBKyiv/python-nats
 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
ファイル: test_unit.py プロジェクト: eodreports/python-nats
 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
ファイル: heartbeat.py プロジェクト: PyHUBKyiv/python-nats
 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
ファイル: heartbeat.py プロジェクト: PyHUBKyiv/python-nats
 def on_ping_request(self):
     'handler when ping request received'
     self.pings += 1
     self.conn.send_command(Protocol.pong_response())
コード例 #22
0
ファイル: heartbeat.py プロジェクト: PyHUBKyiv/python-nats
 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
ファイル: test_unit.py プロジェクト: eodreports/python-nats
 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
ファイル: test_unit.py プロジェクト: PyHUBKyiv/python-nats
 def test_ping_request(self):
     'should return the ping protocol'
     self.assertEqual(Protocol.ping_request(), 'PING\r\n')