Esempio n. 1
0
def get_constants(name: str) -> models.JsonifiableCollection:
    for source, constants in csts.CONSTANTS.items():
        for element in constants:
            if element.get_name() == name:
                with core.get_data_source(source).session() as sess:
                    return models.JsonifiableCollection(
                        sess.query(element.get_class_source()))
Esempio n. 2
0
def authenticate_user(email: str, password: str) \
        -> typing.Tuple[models.User, str, typing.List[str]]:
    # Todo: Ensure to generate the right token
    user, token, sources = None, None, []
    with (core.get_data_source().session()) as pec_sess:
        user = (pec_sess.query(
            models.User).filter(models.User.email == email).one_or_none())
        if user:
            if not user.check_passwd(password):
                return user
Esempio n. 3
0
def create_global_data_source():
    test_ds = core.get_data_source(is_test=True)

    # In order to avoid having many test files for different database
    # We decided to keep the same files but clean them everytime we relaunch this test
    base.Base.metadata.drop_all(bind=test_ds.engine())

    # Create tables
    core.setup_db()

    # Return
    return test_ds
Esempio n. 4
0
def authenticate_token(token):
    # We should return also from which source the user is comming from to ensure that we are able to connect the user
    with core.get_data_source().session() as sess:
        return sess.query(models.User).first()
Esempio n. 5
0
def add_user(email: str, password: str):
    with (core.get_data_source().session()) as sess:
        user = models.User(email=email)
        user.password = '******'
        sess.add(user)
        return user
Esempio n. 6
0
def get_faqs():
    with core.get_data_source().session() as sess:
        return sess.query(models.Faq).all()