How to use the transaction.commit function in transaction

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 pyjobs / web / pyjobs_web / pyjobsweb / model / sqlalchemy_model / job.py View on Github external
def update_last_sync(cls, job_id, timestamp):
        transaction.begin()
        DBSession.query(cls) \
            .filter(cls.id == job_id) \
            .update({'last_sync': timestamp,
                     'last_modified': cls.last_modified})
        DBSession.query(cls) \
            .filter(cls.id == job_id) \
            .filter(cls.last_modified < timestamp) \
            .update({'last_modified': timestamp})
        transaction.commit()
github socialplanning / opencore / Products / OpenPlans / Extensions / Install.py View on Github external
def migrateATDocToOpenPage(portal, out):
    print >> out, 'Migrating ATDocument type to OpenPage'
    if not 'migrate_atdoc_openpage' in portal.objectIds():
        portal.manage_addProduct['ExternalMethod'].manage_addExternalMethod(
            'migrate_atdoc_openpage', '', 'OpenPlans.migrate_atdoc_openpage',
            'migrate_atdoc_openpage')

    import transaction as txn
    txn.commit(1)
    print >> out, portal.migrate_atdoc_openpage(portal)
    portal.manage_delObjects(ids=['migrate_atdoc_openpage'])
github castlecms / castle.cms / castle / cms / tasks / files.py View on Github external
def _file_edited(obj):
    try:
        if not obj.file:
            return _clean_aws(obj)
    except AttributeError:
        return
    if obj.portal_type == 'Video':
        video.process(obj)
        transaction.commit()

    if obj.portal_type not in ('Video', 'Audio', 'File'):
        return _clean_aws(obj)

    if 'pdf' in obj.file.contentType:
        # we also aren't moving pdfs out of here
        return _clean_aws(obj)

    registry = getUtility(IRegistry)
    if registry.get('castle.aws_s3_key', None) is None:
        return

    max_size_mb = registry.get('castle.max_file_size', 50)
    max_size = max_size_mb * 1024 * 1024
    if obj.file.getSize() > max_size:
        aws.move_file(obj)
github joliebig / featurehouse / fstmerge / examples / SpamBayes / rev3103-3133 / right-branch-3133 / spambayes / storage.py View on Github external
def store(self):
        '''Place state into persistent store'''
        try:
            import ZODB
            import ZODB.Transaction
        except ImportError:
            import transaction
            commit = transaction.commit
            abort = transaction.abort
        else:
            commit = ZODB.Transaction.get_transaction().commit
            abort = ZODB.Transaction.get_transaction().abort
        from ZODB.POSException import ConflictError
        try:
            from ZODB.POSException import TransactionFailedError
        except:
            from ZODB.POSException import TransactionError as TransactionFailedError
        from ZODB.POSException import ReadOnlyError
        assert not self.closed, "Can't store a closed database"
        if options["globals", "verbose"]:
            print >> sys.stderr, 'Persisting', self.db_name, 'state in database'
        try:
            commit()
        except ConflictError:
github sayoun / pyvac / pyvac / bin / replay.py View on Github external
print('need to insert request')
                req_to_add.append(req.id)

    for req_id in set(req_to_add):
        req = Request.by_id(session, req_id)
        print(('processing', req.id, req.summarycal, req.date_from, req.date_to))
        ics_url = addToCal(caldav_url,
                           req.date_from,
                           req.date_to,
                           req.summarycal)
        # save ics url in request
        req.ics_url = ics_url
        session.add(req)

    session.flush()
    transaction.commit()