示例#1
0
 def test_normal_generic_message_with_extra(self):
     m = FrontendMessage()
     done, extra = m.consume('Q\x00\x00\x00\x05Nfoo')
     self.assertTrue(done)
     self.assertEqual(extra, 'foo')
     self.assertEqual(m.length, 6)
     self.assertEqual(m.type, 'Q')
     self.assertEqual(m.data, 'N')
示例#2
0
 def test_normal_generic_message_with_extra(self):
     m = FrontendMessage()
     done, extra = m.consume('Q\x00\x00\x00\x05Nfoo')
     self.assertTrue(done)
     self.assertEqual(extra, 'foo')
     self.assertEqual(m.length, 6)
     self.assertEqual(m.type, 'Q')
     self.assertEqual(m.data, 'N')
示例#3
0
 def test_separate_packets(self):
     m = FrontendMessage()
     done, _ = m.consume('Q\x00')
     self.assertFalse(done)
     done, extra = m.consume('\x00\x00\x05Nfoo')
     self.assertEqual(extra, 'foo')
     self.assertEqual(m.length, 6)
     self.assertEqual(m.type, 'Q')
     self.assertEqual(m.data, 'N')
示例#4
0
 def test_separate_packets(self):
     m = FrontendMessage()
     done, _ = m.consume('Q\x00')
     self.assertFalse(done)
     done, extra = m.consume('\x00\x00\x05Nfoo')
     self.assertEqual(extra, 'foo')
     self.assertEqual(m.length, 6)
     self.assertEqual(m.type, 'Q')
     self.assertEqual(m.data, 'N')
示例#5
0
 def test_CancelRequest(self):
     msg = ('\x00\x00\x00\x10'
            '\x80\x87\x71\x02'
            '\xde\xad\xbe\xef'
            '\xfe\xed\xbe\xef'
            'extra')
     m = FrontendMessage()
     self.assertEqual((True, 'extra'), m.consume(msg))
     self.assertEqual(m.type, 'Cancel')
     self.assertEqual(m.length, 16)
     self.assertEqual(m.pid, 0xdeadbeef)
     self.assertEqual(m.key, 0xfeedbeef)
示例#6
0
 def test_CancelRequest(self):
     msg = ('\x00\x00\x00\x10'
            '\x80\x87\x71\x02'
            '\xde\xad\xbe\xef'
            '\xfe\xed\xbe\xef'
            'extra')
     m = FrontendMessage()
     self.assertEqual((True, 'extra'), m.consume(msg))
     self.assertEqual(m.type, 'Cancel')
     self.assertEqual(m.length, 16)
     self.assertEqual(m.pid, 0xdeadbeef)
     self.assertEqual(m.key, 0xfeedbeef)
示例#7
0
    def test_serialize(self):
        # test a special message
        msg = ('\x00\x00\x00\x26'
               '\x00\x03\x00\x00'
               'user\x00postgres\x00'
               'database\x00master\x00'
               'foobar baz \x00 goo')
        m = FrontendMessage()
        m.consume(msg)
        self.assertEqual(
            m.serialize(), '\x00\x00\x00\x26'
            '\x00\x03\x00\x00'
            'user\x00postgres\x00'
            'database\x00master\x00')

        # test a normal message
        m = FrontendMessage()
        m.consume('S\x00\x00\x00\x05NX')
        self.assertEqual(m.serialize(), 'S\x00\x00\x00\x05N')
示例#8
0
    def test_Startup(self):
        msg = ('\x00\x00\x00\x26'   # length
               '\x00\x03\x00\x00'   # protocol version

               # fields
               'user\x00postgres\x00'
               'database\x00master\x00'
               
               # extra data
               'foobar baz \x00 goo')

        m = FrontendMessage()
        done, extra = m.consume(msg)
        self.assertTrue(done)
        self.assertEqual(extra, 'foobar baz \x00 goo')
        self.assertEqual(m.length, 0x26)
        self.assertEqual(m.type, 'Startup')
        self.assertEqual(
            m.parameters, 
            {'user': '******', 'database': 'master'})
示例#9
0
    def test_Startup(self):
        msg = (
            '\x00\x00\x00\x26'  # length
            '\x00\x03\x00\x00'  # protocol version

            # fields
            'user\x00postgres\x00'
            'database\x00master\x00'

            # extra data
            'foobar baz \x00 goo')

        m = FrontendMessage()
        done, extra = m.consume(msg)
        self.assertTrue(done)
        self.assertEqual(extra, 'foobar baz \x00 goo')
        self.assertEqual(m.length, 0x26)
        self.assertEqual(m.type, 'Startup')
        self.assertEqual(m.parameters, {
            'user': '******',
            'database': 'master'
        })
示例#10
0
    def test_serialize(self):
        # test a special message
        msg = ('\x00\x00\x00\x26' 
               '\x00\x03\x00\x00' 
               'user\x00postgres\x00'
               'database\x00master\x00'
               'foobar baz \x00 goo')
        m = FrontendMessage()
        m.consume(msg)
        self.assertEqual(
            m.serialize(),
            '\x00\x00\x00\x26' 
            '\x00\x03\x00\x00' 
            'user\x00postgres\x00'
            'database\x00master\x00')

        # test a normal message
        m = FrontendMessage()
        m.consume('S\x00\x00\x00\x05NX')
        self.assertEqual(m.serialize(), 'S\x00\x00\x00\x05N')
示例#11
0
 def test_not_enough_data(self):
     m = FrontendMessage()
     done, extra = m.consume('R\x00\x00\x00\x07')
     self.assertEqual(m.length, 8)
     self.assertFalse(done)
     self.assertFalse(extra)
示例#12
0
 def test_not_enough_data(self):
     m = FrontendMessage()
     done, extra = m.consume('R\x00\x00\x00\x07')
     self.assertEqual(m.length, 8)
     self.assertFalse(done)
     self.assertFalse(extra)
示例#13
0
 def assertUnknown(self, msg):
     m = FrontendMessage()
     try:
         m.consume(msg)
     except ValueError, e:
         self.assertTrue(e.message.startswith('Unknown '))
示例#14
0
 def test_SSLRequest(self):
     m = FrontendMessage()
     done, _ = m.consume('\x00\x00\x00\x08\x80\x87\x71\x03')
     self.assertTrue(done)
     self.assertEqual(m.type, 'SSLRequest')
示例#15
0
 def test_sub_header_length(self):
     m = FrontendMessage()
     done, extra = m.consume('R')
     self.assertFalse(done)
     self.assertFalse(extra)
示例#16
0
 def test_sub_header_length(self):
     m = FrontendMessage()
     done, extra = m.consume('R')
     self.assertFalse(done)
     self.assertFalse(extra)
示例#17
0
 def test_SSLRequest(self):
     m = FrontendMessage()
     done, _ = m.consume('\x00\x00\x00\x08\x80\x87\x71\x03')
     self.assertTrue(done)
     self.assertEqual(m.type, 'SSLRequest')
示例#18
0
 def assertUnknown(self, msg):
     m = FrontendMessage()
     try:
         m.consume(msg)
     except ValueError, e:
         self.assertTrue(e.message.startswith('Unknown '))