示例#1
0
    def __init__(self):

        # establish connection with sql server
        self.engine = create_sqlalchemy_engine()
        # create a session
        self.Session = sessionmaker(bind=self.engine, expire_on_commit=True)
        self.otpObj = OTP()
示例#2
0
def get_user_by_phone_and_serial_number(phone_number, handset_serial_number):
    # establish connection with sql server
    engine = create_sqlalchemy_engine()
    # create a session
    Session = sessionmaker(bind=engine)
    session = Session()
    user = session.query(db_model.User).filter(
        db_model.User.phone_number == phone_number,
        db_model.User.handset_serial_number == handset_serial_number).one()

    return user
示例#3
0
def clear_up_db():
    # establish connection with sql server
    engine = create_sqlalchemy_engine()
    # create table from ORM models
    db_model.create_model(engine)
    # create a session
    Session = sessionmaker(bind=engine)
    session = Session()

    try:
        session.query(db_model.Complain).delete()
        session.query(db_model.User).delete()
        session.query(db_model.Service).delete()
        session.query(db_model.Category).delete()

        session.commit()
    except Exception as e:
        ret = "ERROR: " + str(e.__dict__)
        print(ret)
        session.rollback()
示例#4
0
def add_row_in_database(row_object):
    # establish connection with sql server
    engine = create_sqlalchemy_engine()
    # create a session
    Session = sessionmaker(bind=engine)
    session = Session()

    try:
        session.add(row_object)
        session.commit()
        session.refresh(row_object)

    except IntegrityError as ie:
        ret = "ERROR: " + ie.detail
        print(ret)
        session.rollback()
    except Exception as e:
        ret = "ERROR: " + e.__traceback__.__str__()
        print(ret)
        session.rollback()
    finally:
        engine.dispose()
示例#5
0
 def setUp(self):
     # establish connection with sql server
     self.engine = create_sqlalchemy_engine()
     # create a session
     self.Session = sessionmaker(bind=self.engine)