def tearDown(self):
     """Clear database configuration and drop database.
     """
     try:
         session.expunge_all()
     except:
         session.clear()
     clear_mappers()
     metadata.drop_all()
     metadata.clear()
     set_db_uri(self.sa_dburi, 'sqlalchemy')
Exemplo n.º 2
0
def test_user_redirect():
    """If a controller redirects, transactions are committed."""
    cherrypy.root = MyRoot()
    create_request("/create_person?id=22&doerr=2")
    try: # should be done automatically, but just in case
        session.expunge_all()
    except AttributeError: # SQLAlchemy < 0.5.1
        session.clear()
    query = Person.query
    if ActiveMapper:
        query = query()
    assert query.get(22) is not None
Exemplo n.º 3
0
def test_user_exception():
    """If a controller raises an exception, transactions are rolled back."""
    cherrypy.root = MyRoot()
    create_request("/create_person?id=21&doerr=1")
    try: # should be done automatically, but just in case
        session.expunge_all()
    except AttributeError: # SQLAlchemy < 0.5.1
        session.clear()
    query = Person.query
    if ActiveMapper:
        query = query()
    assert query.get(21) is None
Exemplo n.º 4
0
def test_implicit_trans_no_error():
    """If a controller runs sucessfully, the transaction is commited."""
    capture_log("turbogears.database")
    cherrypy.root = MyRoot()
    create_request("/no_error?name=A.%20Dent")
    print_log()
    try:
        session.expunge_all()
    except AttributeError: # SQLAlchemy < 0.5.1
        session.clear()
    q = session.query(Person)
    arthur = q.filter_by(name="A. Dent").one()
Exemplo n.º 5
0
def test_user_redirect():
    """If a controller redirects, transactions are committed."""
    cherrypy.root = MyRoot()
    create_request("/create_person?id=22&doerr=2")
    try:  # should be done automatically, but just in case
        session.expunge_all()
    except AttributeError:  # SQLAlchemy < 0.5.1
        session.clear()
    query = Person.query
    if ActiveMapper:
        query = query()
    assert query.get(22) is not None
Exemplo n.º 6
0
def test_user_exception():
    """If a controller raises an exception, transactions are rolled back."""
    cherrypy.root = MyRoot()
    create_request("/create_person?id=21&doerr=1")
    try:  # should be done automatically, but just in case
        session.expunge_all()
    except AttributeError:  # SQLAlchemy < 0.5.1
        session.clear()
    query = Person.query
    if ActiveMapper:
        query = query()
    assert query.get(21) is None
Exemplo n.º 7
0
def test_implicit_trans_no_error():
    """If a controller runs sucessfully, the transaction is commited."""
    capture_log("turbogears.database")
    cherrypy.root = MyRoot()
    create_request("/no_error?name=A.%20Dent")
    print_log()
    try:
        session.expunge_all()
    except AttributeError:  # SQLAlchemy < 0.5.1
        session.clear()
    q = session.query(Person)
    arthur = q.filter_by(name="A. Dent").one()
Exemplo n.º 8
0
def test_active_mapper():
    p = Person(name="Ford Prefect")
    a = Address(address="1 West Guildford", city="Betelgeuse")
    p.addresses.append(a)
    session.flush()
    try:
        session.expunge_all()
    except AttributeError: # SQLAlchemy < 0.5.1
        session.clear()
    q = session.query(Person)
    ford = q.filter_by(name="Ford Prefect").one()
    assert ford is not p
    assert len(ford.addresses) == 1
Exemplo n.º 9
0
def test_active_mapper():
    p = Person(name="Ford Prefect")
    a = Address(address="1 West Guildford", city="Betelgeuse")
    p.addresses.append(a)
    session.flush()
    try:
        session.expunge_all()
    except AttributeError:  # SQLAlchemy < 0.5.1
        session.clear()
    q = session.query(Person)
    ford = q.filter_by(name="Ford Prefect").one()
    assert ford is not p
    assert len(ford.addresses) == 1
Exemplo n.º 10
0
 def setUp(self):
     # Create tables
     metadata.drop_all()
     metadata.create_all()
     user1 = User() 
     user1.user_name='bobvilla'
     user1.email_address='*****@*****.**'
     user1.display_name='Bob Villa'
     user1.password='******'   
     session.save(user1)
     u2 = User()
     u2.user_name='bobathome'
     u2.email_address='*****@*****.**'
     u2.display_name='Bob Villa'
     u2.password='******'
     session.save(u2) 
     session.flush()
     print 'UuUuUuU %s' % user1
     self.user1 = user1
     session.clear()
     session.close()
#!/usr/bin/python

import datetime
from turbogears.database import session
from bkr.server.util import load_config
from bkr.server.model import System


def check_reservations(system):
    if system.user is not None:
        assert system.reservations[0].finish_time is None
    if not system.reservations:
        return
    prev = system.reservations[0]
    if prev.finish_time:
        assert prev.start_time <= prev.finish_time, "%r is backwards" % prev
    for r in system.reservations[1:]:
        assert r.finish_time <= prev.start_time, "%r does not finish before %r" % (r, prev)
        assert r.start_time <= r.finish_time, "%r is backwards" % r
        prev = r


if __name__ == "__main__":
    load_config()
    for system_id in [s.id for s in System.query()]:
        system = System.query().get(system_id)
        check_reservations(system)
        session.clear()
#!/usr/bin/python

import datetime
from turbogears.database import session
from bkr.server.util import load_config
from bkr.server.model import System

def check_reservations(system):
    if system.user is not None:
        assert system.reservations[0].finish_time is None
    if not system.reservations: return
    prev = system.reservations[0]
    if prev.finish_time:
        assert prev.start_time <= prev.finish_time, \
                '%r is backwards' % prev
    for r in system.reservations[1:]:
        assert r.finish_time <= prev.start_time, \
                '%r does not finish before %r' % (r, prev)
        assert r.start_time <= r.finish_time, '%r is backwards' % r
        prev = r

if __name__ == '__main__':
    load_config()
    for system_id in [s.id for s in System.query()]:
        system = System.query().get(system_id)
        check_reservations(system)
        session.clear()