Пример #1
0
def test_good_transaction():
    "successful runs automatically commit"
    dsi = DatabaseStandIn()
    database.run_with_transaction(dsi.successful)
    dsi.restore()
    assert dsi.successful_called
    assert dsi.committed
    assert dsi.ended
Пример #2
0
 def apply(self):
     return # see # 21
     access_tuple = patches.utils.parseDBAccessDirective()
     con = patches.utils.getPostgreSQLConnection(*access_tuple)
     cur = con.cursor()
     cur.execute("""alter table location add column city VARCHAR(40);""")
     con.commit()
     dburi = patches.utils.parseDBURI('dev.cfg').split('=')[1][1:-1]
     database.set_db_uri(dburi)
     database.run_with_transaction(add_cities)
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()
Пример #4
0
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()
Пример #5
0
def test_redirection():
    "Redirects count as successful runs, not failures"
    dsi = DatabaseStandIn()
    try:
        database.run_with_transaction(dsi.redirect)
    except cherrypy.HTTPRedirect:
        pass
    dsi.restore()
    assert dsi.redirect_called
    assert dsi.committed
    assert dsi.ended
Пример #6
0
def test_bad_transaction():
    "failed runs automatically rollback"
    dsi = DatabaseStandIn()
    try:
        database.run_with_transaction(dsi.failure)
        dsi.restore()
        assert False, "exception should have been raised"
    except:
        pass
    dsi.restore()
    assert dsi.failure_called
    assert dsi.rolled_back
    assert dsi.ended
Пример #7
0
def test_redirection():
    """Redirects count as successful runs, not failures"""
    dsi = DatabaseStandIn()
    database.hub_registry.add(dsi)
    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()
Пример #8
0
 def apply(self):
     # This is copied from patch #25
     access_tuple = patches.utils.parseDBAccessDirective()
     con = patches.utils.getPostgreSQLConnection(*access_tuple)
     cur = con.cursor()
     cur.execute("ALTER TABLE location ADD COLUMN is_region int DEFAULT 0")
     cur.execute("ALTER TABLE location add column in_region_id INTEGER CONSTRAINT in_region_id_exists REFERENCES location(id)")
     cur.execute("""alter table location add column city VARCHAR(40);""")
     con.commit()
     # end of patch # 25
     dburi = patches.utils.parseDBURI('dev.cfg').split('=')[1][1:-1]
     database.set_db_uri(dburi)
     database.run_with_transaction(setup_microsite_spaces)
     database.run_with_transaction(migrate)
Пример #9
0
def test_redirection():
    """Redirects count as successful runs, not failures"""
    dsi = DatabaseStandIn()
    database.hub_registry.add(dsi)
    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()
Пример #10
0
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_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()
Пример #12
0
 def expose(func, *args, **kw):
     request.tg_template_enginename = view.base._choose_engine(template)[2]
     accept = request.headers.get('Accept', "").lower()
     accept = tg_util.simplify_http_accept_header(accept)
     if not hasattr(func, "_expose"):
         _build_rules(func)
     try:
         if hasattr(request, "in_transaction"):
             output = func._expose(func, accept, func._allow_json,
                         *args, **kw)
         else:
             request.in_transaction = True
             output = database.run_with_transaction(
                     func._expose, func, accept, func._allow_json,
                     *args, **kw)
     except NoApplicableMethods, e:
         args = e.args # args from the last generic function call
         if (args and args[0] and isinstance(args[0], tuple)
                 and args[0][0] is func):
             # The error refers to our call above. This means that
             # no suitable controller method was found (probably due
             # to wrong parameters). So we will raise a "not found"
             # error unless a specific error status was already set
             # (e.g. "unauthorized" was set by the identity provider):
             status = cherrypy.response.status
             if status and status // 100 == 4:
                 raise cherrypy.HTTPError(status)
             raise cherrypy.NotFound
         # If the error was raised elsewhere inside the controller,
         # handle it like all other exceptions ("server error"):
         raise
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
Пример #14
0
 def apply(self):
     uri = capture_pg_uri()
     con = getPostgreSQLConnection(uri)
     cur = con.cursor()
     cur.execute("""
     ALTER TABLE tg_user ADD COLUMN rfid VARCHAR(40);
     ALTER TABLE location ADD COLUMN holidays BYTEA DEFAULT '%s';
     ALTER TABLE tg_user ADD COLUMN access_policies BYTEA DEFAULT '%s';
     ALTER TABLE tg_user ADD COLUMN disabled_policies BYTEA DEFAULT '%s';
     DROP TABLE open;
     ALTER TABLE location drop column opens RESTRICT,
     drop column closes RESTRICT;
     ALTER TABLE user_group add column id SERIAL PRIMARY KEY;
     ALTER TABLE resourcegroup add column group_type VARCHAR(40) DEFAULT 'member_calendar';
     ALTER TABLE location add column calendar_id INTEGER CONSTRAINT calendar_id_exists REFERENCES resource(id);
     """ %(empty_list_pickle, empty_list_pickle, empty_list_pickle))
     con.commit()
     database.set_db_uri(uri['pg_uri'])
     database.run_with_transaction(create_tables)
     database.run_with_transaction(update_locations)
Пример #15
0
 def expose(func, *args, **kw):
     accept = cherrypy.request.headers.get('Accept', "").lower()
     if not hasattr(func, "_expose"):
         _build_rules(func)
     if hasattr(cherrypy.request, "in_transaction"):
         output = func._expose(func, accept, func._allow_json,
                     *args, **kw)
     else:
         cherrypy.request.in_transaction = True
         output = database.run_with_transaction(
                 func._expose, func, accept, func._allow_json,
                 *args, **kw)
     return output
Пример #16
0
 def expose(func, *args, **kw):
     accept = request.headers.get('Accept', "").lower()
     accept = tg_util.simplify_http_accept_header(accept)
     if not hasattr(func, "_expose"):
         _build_rules(func)
     if hasattr(request, "in_transaction"):
         output = func._expose(func, accept, func._allow_json,
                               *args, **kw)
     else:
         request.in_transaction = True
         output = database.run_with_transaction(
             func._expose, func, accept, func._allow_json, *args,
             **kw)
     return output
Пример #17
0
 def expose(func, *args, **kw):
     accept = request.headers.get('Accept', "").lower()
     accept = tg_util.simplify_http_accept_header(accept)
     if not hasattr(func, "_expose"):
         _build_rules(func)
     if hasattr(request, "in_transaction"):
         output = func._expose(func, accept, func._allow_json,
                     *args, **kw)
     else:
         request.in_transaction = True
         output = database.run_with_transaction(
                 func._expose, func, accept, func._allow_json,
                 *args, **kw)
     return output
Пример #18
0
    def apply(self):
        # This is copied from patch #25
        access_tuple = patches.utils.parseDBAccessDirective()
        con = patches.utils.getPostgreSQLConnection(*access_tuple)
        dburi = patches.utils.parseDBURI('dev.cfg').split('=')[1][1:-1]

        database.set_db_uri(dburi)
       
        database.run_with_transaction(setup_listtable)
        
        cur = con.cursor()
        cur.execute("ALTER TABLE list_item ADD COLUMN list_id INTEGER CONSTRAINT list_id_exists REFERENCES list(id)")
        con.commit()
        
        database.run_with_transaction(migrate_lists)
        database.run_with_transaction(create_subpage_lists)
Пример #19
0
 def apply(self):
     # This is copied from patch #25
     dburi = patches.utils.parseDBURI("dev.cfg").split("=")[1][1:-1]
     database.set_db_uri(dburi)
     database.run_with_transaction(fix_users_without_object_references)
Пример #20
0
 def apply(self):
     access_tuple = patches.utils.parseDBAccessDirective()
     dburi = patches.utils.parseDBURI('dev.cfg').split('=')[1][1:-1]
     database.set_db_uri(dburi)
     database.run_with_transaction(sync_joinus_field)
Пример #21
0
def _run_with_transaction(accept, args, func, kw):
    return database.run_with_transaction(func._expose, func, accept,
                                         func._allow_json, *args, **kw)
Пример #22
0
def _run_with_transaction(accept, args, func, kw):
    return database.run_with_transaction(
             func._expose, func, accept, func._allow_json,
             *args, **kw)