How to use transaction - 10 common examples

To help you get started, we’ve selected a few transaction examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fizyk / pyramid_fullauth / tests / cases / test_integration / test_view_reset.py View on Github external
def test_reset_proceed_wrong(self, base_app):
        '''Reset test for reseting pasword with notmatched passwords'''
        self.create_user()
        user = self.read_user(self.user_data['email'])
        user.set_reset()
        transaction.commit()

        user = self.read_user(self.user_data['email'])
        res = base_app.app.get(str('/password/reset/' + user.reset_key))
        assert 'Recover your password - choose new password' in res

        post_data = {
            'password':
            self.user_data['password'],
            'confirm_password':
            self.user_data['password'] + u'sasasa',
            'csrf_token':
            self.get_token('/password/reset', base_app.app)
        }
        res = base_app.app.post(str('/password/reset/' + user.reset_key), post_data)
        assert 'Error! Password doesn\'t match' in HTMLParser().unescape(res.body)
github zopefoundation / Zope / lib / python / Testing / ZopeTestCase / zopedoctest / functional.py View on Github external
@savestate
def http(request_string, handle_errors=True):
    """Execute an HTTP request string via the publisher

    This is used for HTTP doc tests.
    """
    import urllib
    import rfc822
    from cStringIO import StringIO
    from ZPublisher.Response import Response
    from ZPublisher.Test import publish_module

    # Commit work done by previous python code.
    transaction.commit()

    # Discard leading white space to make call layout simpler
    request_string = request_string.lstrip()

    # Split off and parse the command line
    l = request_string.find('\n')
    command_line = request_string[:l].rstrip()
    request_string = request_string[l+1:]
    method, path, protocol = command_line.split()
    path = urllib.unquote(path)

    instream = StringIO(request_string)

    env = {"HTTP_HOST": 'localhost',
           "HTTP_REFERER": 'localhost',
           "REQUEST_METHOD": method,
github fizyk / pyramid_fullauth / tests / views / test_email.py View on Github external
"""Change email with valid data."""
    app = default_app

    authenticate(app)
    email = DEFAULT_USER['email']
    new_email = 'email@email.com'

    user = db_session.query(User).filter(User.email == email).one()

    res = app.get('/email/change')
    form = res.form
    form['email'] = new_email
    res = form.submit()
    assert res

    transaction.commit()

    user = db_session.query(User).filter(User.email == email).one()
    assert user.new_email == new_email
    assert user.email == email
    assert user.email_change_key is not None
github mgedmin / zodbbrowser / src / zodbbrowser / ftests / test_standalone.py View on Github external
def createTestDataForBrowsing(cls, root_folder):
        # set up data that browsing.txt expects
        root_folder['browsing'] = Folder()
        transaction.get().note(u"createTestDataForBrowsing")
        transaction.commit()
github zopefoundation / zope.sqlalchemy / src / zope / sqlalchemy / tests.py View on Github external
def setUp(self):
        self.mappers = setup_mappers()
        metadata.drop_all(engine)
        metadata.create_all(engine)
        self.tm1 = transaction.TransactionManager()
        self.tm2 = transaction.TransactionManager()
        # With psycopg2 you might supply isolation_level='SERIALIZABLE' here,
        # unfortunately that is not supported by cx_Oracle.
        e1 = sa.create_engine(TEST_DSN)
        e2 = sa.create_engine(TEST_DSN)
        self.s1 = orm.sessionmaker(bind=e1, twophase=TEST_TWOPHASE)()
        tx.register(self.s1, transaction_manager=self.tm1)
        self.s2 = orm.sessionmaker(bind=e2, twophase=TEST_TWOPHASE)()
        tx.register(self.s2, transaction_manager=self.tm2)
        self.tm1.begin()
        self.s1.add(User(id=1, firstname="udo", lastname="juergens"))
        self.tm1.commit()
github serverdensity / sd-agent / tests / core / test_proxy.py View on Github external
def test_proxy(self):
        config = {
            "endpoints": {"https://app.datadoghq.com": ["foo"]},
            "proxy_settings": {
                "host": "localhost",
                "port": PROXY_PORT,
                "user": None,
                "password": None
            }
        }

        app = Application()
        app.skip_ssl_validation = True
        app._agentConfig = config

        trManager = TransactionManager(MAX_WAIT_FOR_REPLAY, MAX_QUEUE_SIZE, THROTTLING_DELAY)
        trManager._flush_without_ioloop = True  # Use blocking API to emulate tornado ioloop
        CustomAgentTransaction.set_tr_manager(trManager)
        app.use_simple_http_client = False # We need proxy capabilities
        app.agent_dns_caching = False
        # _test is the instance of this class. It is needed to call the method stop() and deal with the asynchronous
        # calls as described here : http://www.tornadoweb.org/en/stable/testing.html
        CustomAgentTransaction._test = self
        CustomAgentTransaction.set_application(app)
        CustomAgentTransaction.set_endpoints(config['endpoints'])

        CustomAgentTransaction('body', {}, "") # Create and flush the transaction
        self.wait()
        del CustomAgentTransaction._test
        access_log = self.docker_client.exec_start(
            self.docker_client.exec_create(CONTAINER_NAME, 'cat /var/log/squid/access.log')['Id'])
        self.assertTrue("CONNECT" in access_log) # There should be an entry in the proxy access log
github TurboGears / tg2 / tests / test_configuration.py View on Github external
def test(self):
                self.attempts.append(True)
                if len(self.attempts) == 3:
                    return 'HI!'
                raise TransientError()
github zopefoundation / zope.sqlalchemy / src / zope / sqlalchemy / tests.py View on Github external
def tearDown(self):
        transaction.abort()
        bound_metadata1.drop_all()
        bound_metadata2.drop_all()
        orm.clear_mappers()
github Pylons / acidfs / tests / test_functional.py View on Github external
def cleanup():
        transaction.abort()
        shutil.rmtree(tmp)
github TurboGears / tg2 / tests / test_configuration.py View on Github external
response.status = 403
                return 'FORBIDDEN'

            @expose()
            def notfound(self):
                response.status = 404
                return 'NOTFOUND'

        def custom_commit_veto(environ, status, headers):
            if status.startswith('404'):
                return True
            return False

        fake_transaction = FakeTransaction()
        import transaction
        prev_transaction_manager = transaction.manager
        transaction.manager = fake_transaction

        package = PackageWithModel()
        conf = AppConfig(minimal=True, root_controller=RootController())
        conf['package'] = package
        conf['model'] = package.model
        conf['use_sqlalchemy'] = True
        conf['tm.enabled'] = True
        conf['tm.commit_veto'] = custom_commit_veto
        conf['sqlalchemy.url'] = 'sqlite://'

        app = conf.make_wsgi_app()
        app = TestApp(app)
        assert hasattr(conf, 'use_transaction_manager') is False

        app.get('/test')