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
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
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
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
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
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
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
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
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
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
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
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
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')
def checkBegin(data): msg = messages.query('%s; -- test name' % s) self.assertEqual(data.lower(), msg.serialize().lower())
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')