def test_rollback(self): fdo = mock() fdo.rowid = 42 fdo.x = "foo" transaction = Transaction(self.connection) instances = {42: fdo} transaction._map[object] = instances when(self.factory.mock).new(transaction=transaction, x="foo").thenReturn(fdo) transaction.rollback() verify(fdo).rollback()
def test_select(self): x = object() def iterx(): yield x transaction = Transaction(self.connection) when(self.factory.mock).new(transaction=transaction, rowid=42, insert=None, x="foo").thenReturn(iterx()) fdo = transaction.select(self.factory, rowid=42, x="foo") self.assertTrue(fdo is x) verify(self.connection.mock, atleast=1).__enter__() verify(self.connection.mock, atleast=1).__exit__(any(), any(), any())
def test_commit(self): fdo = mock() fdo.rowid = 42 fdo.x = "foo" transaction = Transaction(self.connection) instances = {42: fdo} transaction._map[object] = instances when(self.factory.mock).new(transaction=transaction, x="foo").thenReturn(fdo) transaction.commit() verify(self.connection.mock, atleast=1).__enter__() verify(fdo).commit() verify(self.connection.mock, atleast=1).__exit__(None, None, None)
def test_select_all(self): x = object() def iterx(): yield x transaction = Transaction(self.connection) when(self.factory.mock).new(transaction=transaction, insert=None, x="foo").thenReturn(iterx()) f = transaction.select_all(self.factory, insert=None, x="foo") fdo = next(f) self.assertEqual([], list(f)) self.assertTrue(fdo is x) verify(self.connection.mock, atleast=1).__enter__() verify(self.connection.mock, atleast=1).__exit__(any(), any(), any())