Пример #1
0
    def _sp_outcome_test(self, spPrefix, sql):
        b, f = self.protocols()
        d = Deferred()
        b.transport.deferred = d

        # hack in a previous savepoint
        f.filter.savepoints = ['foo']

        def check(data):
            ss = f.filter.savepoints
            self.assertFalse(ss,
                             'Should have deleted FrontendFilter savepoint')

            m = messages.query(spPrefix + ' foo')
            self.assertEqual(data, m.serialize())

            self.assertEqual(
                b.filter.dropMessages, 'CZ',
                'backend should have been told to ignore the complete')
            return data

        d.addCallback(check)
        b.signalTest(True)
        f.messageReceived(messages.query(sql))
        return d
Пример #2
0
        def check(data):
            ss = f.filter.savepoints
            self.assertTrue(ss, 'FrontendFilter should have a savepoint')
            m = messages.query('SAVEPOINT %s' % ss[-1])
            self.assertEqual(data, m.serialize())

            self.assertEqual(
                b.filter.dropMessages, 'CZ', 
                'backend should have been told to ignore the savepoint complete')
            return data
Пример #3
0
        def check(data):
            ss = f.filter.savepoints
            self.assertTrue(ss, 'FrontendFilter should have a savepoint')
            m = messages.query('SAVEPOINT %s' % ss[-1])
            self.assertEqual(data, m.serialize())

            self.assertEqual(
                b.filter.dropMessages, 'CZ',
                'backend should have been told to ignore the savepoint complete'
            )
            return data
Пример #4
0
        def check(data):
            ss = f.filter.savepoints
            self.assertFalse(ss, 'Should have deleted FrontendFilter savepoint')

            m = messages.query(spPrefix+' foo')
            self.assertEqual(data, m.serialize())

            self.assertEqual(
                b.filter.dropMessages, 'CZ',
                'backend should have been told to ignore the complete')
            return data
Пример #5
0
        def check(data):
            ss = f.filter.savepoints
            self.assertFalse(ss,
                             'Should have deleted FrontendFilter savepoint')

            m = messages.query(spPrefix + ' foo')
            self.assertEqual(data, m.serialize())

            self.assertEqual(
                b.filter.dropMessages, 'CZ',
                'backend should have been told to ignore the complete')
            return data
Пример #6
0
    def test_normal_queries_work(self):
        b, f = self.protocols()
        q = messages.query('select 1;')

        def checkQuery(data):
            self.assertEqual(data, q.serialize())

        d = Deferred()
        d.addCallback(checkQuery)
        b.transport.deferred = d

        f.messageReceived(q)
        return d
Пример #7
0
    def test_normal_queries_work(self):
        b, f = self.protocols()
        q = messages.query('select 1;')

        def checkQuery(data):
            self.assertEqual(data, q.serialize())

        d = Deferred()
        d.addCallback(checkQuery)
        b.transport.deferred = d

        f.messageReceived(q)
        return d
Пример #8
0
    def _dropped_and_spoofed_test(self, sql, response_messages):
        b, f = self.protocols()
        b.transport.expectNothing()

        rdy = ''.join([m.serialize() for m in response_messages])
        def checkSpoofedResponse(data):
            self.assertEqual(data, rdy)
        
        d = Deferred()
        d.addCallback(checkSpoofedResponse)
        f.transport.deferred = d

        f.messageReceived(messages.query(sql))
        return d
Пример #9
0
    def _dropped_and_spoofed_test(self, sql, response_messages):
        b, f = self.protocols()
        b.transport.expectNothing()

        rdy = ''.join([m.serialize() for m in response_messages])

        def checkSpoofedResponse(data):
            self.assertEqual(data, rdy)

        d = Deferred()
        d.addCallback(checkSpoofedResponse)
        f.transport.deferred = d

        f.messageReceived(messages.query(sql))
        return d
Пример #10
0
    def _test_syntax_test(self, sql):
        b, f = self.protocols()

        # extract the rollback/begin
        s = sql.split(' ')[0]

        def checkBegin(data):
            msg = messages.query('%s; -- test name' % s)
            self.assertEqual(data.lower(), msg.serialize().lower())

        d = Deferred()
        d.addCallback(checkBegin)
        b.transport.deferred = d

        f.messageReceived(messages.query(sql))
        return d
Пример #11
0
    def _test_syntax_test(self, sql):
        b, f = self.protocols()

        # extract the rollback/begin
        s = sql.split(' ')[0]

        def checkBegin(data):
            msg = messages.query('%s; -- test name' % s)
            self.assertEqual(data.lower(), msg.serialize().lower())

        d = Deferred()
        d.addCallback(checkBegin)
        b.transport.deferred = d

        f.messageReceived(messages.query(sql))
        return d
Пример #12
0
    def test_release_savepoint_not_issued_error_in_transaction(self):
        b, f = self.protocols()
        b.setTransactionStatus('failed')
        b.transport.expectNothing()

        d = Deferred()
        f.transport.deferred = d

        def check(data):
            ms = FrontendFilter.transaction_aborted
            self.assertEqual(data, ''.join([m.serialize() for m in ms]))
            return data

        d.addCallback(check)
        b.signalTest(True)
        f.messageReceived(messages.query('end work;'))
        return d
Пример #13
0
    def test_release_savepoint_not_issued_error_in_transaction(self):
        b, f = self.protocols()
        b.setTransactionStatus('failed')
        b.transport.expectNothing()

        d = Deferred()
        f.transport.deferred = d
        
        def check(data):
            ms = FrontendFilter.transaction_aborted
            self.assertEqual(data, ''.join([m.serialize() for m in ms]))
            return data

        d.addCallback(check)
        b.signalTest(True)
        f.messageReceived(messages.query('end work;'))
        return d
Пример #14
0
    def test_begin_in_test_rewritten_to_savepoint(self):
        # Support transaction-ish behavior within tests by rewriting them 
        # to savepoints. 
        b, f = self.protocols()
        d = Deferred()
        b.transport.deferred = d

        def check(data):
            ss = f.filter.savepoints
            self.assertTrue(ss, 'FrontendFilter should have a savepoint')
            m = messages.query('SAVEPOINT %s' % ss[-1])
            self.assertEqual(data, m.serialize())

            self.assertEqual(
                b.filter.dropMessages, 'CZ', 
                'backend should have been told to ignore the savepoint complete')
            return data

        d.addCallback(check)

        b.signalTest(True)
        f.messageReceived(messages.query('BEGIN;'))
        return d
Пример #15
0
    def test_begin_in_test_rewritten_to_savepoint(self):
        # Support transaction-ish behavior within tests by rewriting them
        # to savepoints.
        b, f = self.protocols()
        d = Deferred()
        b.transport.deferred = d

        def check(data):
            ss = f.filter.savepoints
            self.assertTrue(ss, 'FrontendFilter should have a savepoint')
            m = messages.query('SAVEPOINT %s' % ss[-1])
            self.assertEqual(data, m.serialize())

            self.assertEqual(
                b.filter.dropMessages, 'CZ',
                'backend should have been told to ignore the savepoint complete'
            )
            return data

        d.addCallback(check)

        b.signalTest(True)
        f.messageReceived(messages.query('BEGIN;'))
        return d
Пример #16
0
    def _sp_outcome_test(self, spPrefix, sql):
        b, f = self.protocols()
        d = Deferred()
        b.transport.deferred = d
        
        # hack in a previous savepoint
        f.filter.savepoints = ['foo']

        def check(data):
            ss = f.filter.savepoints
            self.assertFalse(ss, 'Should have deleted FrontendFilter savepoint')

            m = messages.query(spPrefix+' foo')
            self.assertEqual(data, m.serialize())

            self.assertEqual(
                b.filter.dropMessages, 'CZ',
                'backend should have been told to ignore the complete')
            return data

        d.addCallback(check)
        b.signalTest(True)
        f.messageReceived(messages.query(sql))
        return d
Пример #17
0
 def test_query(self):
     m = messages.query('SELECT 1')
     self.assertEqual(m.type, 'Q')
     self.assertEqual(
         m.serialize(),
         'Q\x00\x00\x00\x0dSELECT 1\x00')
Пример #18
0
 def checkBegin(data):
     msg = messages.query('%s; -- test name' % s)
     self.assertEqual(data.lower(), msg.serialize().lower())
Пример #19
0
 def test_query(self):
     m = messages.query('SELECT 1')
     self.assertEqual(m.type, 'Q')
     self.assertEqual(m.serialize(), 'Q\x00\x00\x00\x0dSELECT 1\x00')
Пример #20
0
 def checkBegin(data):
     msg = messages.query('%s; -- test name' % s)
     self.assertEqual(data.lower(), msg.serialize().lower())