def test_good_transaction(): """successful runs automatically commit""" dsi = DatabaseStandIn() database.hub_registry.add(dsi) try: database.run_with_transaction(dsi.successful) assert dsi.successful_called assert dsi.committed assert dsi.ended finally: database.hub_registry.clear()
def test_bad_transaction(): """failed runs automatically rollback""" dsi = DatabaseStandIn() database.hub_registry.add(dsi) try: try: database.run_with_transaction(dsi.failure) assert False, "exception should have been raised" except: pass assert dsi.failure_called assert dsi.rolled_back assert dsi.ended finally: database.hub_registry.clear()
def test_redirection(): """Redirects count as successful runs, not failures""" dsi = DatabaseStandIn() database.hub_registry.add(dsi) #The real cherrypy redirect is only available within a request, # so monkey-patch in this dummy. _http_redirect = cherrypy.HTTPRedirect cherrypy.HTTPRedirect = DummyRedirect try: try: database.run_with_transaction(dsi.redirect) except cherrypy.HTTPRedirect: pass assert dsi.redirect_called assert dsi.committed assert dsi.ended finally: database.hub_registry.clear() cherrypy.HTTPRedirect = _http_redirect