Exemplo n.º 1
0
def get_session(config_file, transactional=True):
    """Will return a database session based on the application
    configuration"""
    engine = get_engine(config_file)
    if transactional:
        DBSession.configure(bind=engine)
        return DBSession
    else:
        NTDBSession.configure(bind=engine)
        return NTDBSession
Exemplo n.º 2
0
Arquivo: db.py Projeto: reiterl/ringo
def get_session(config_file, transactional=True):
    """Will return a database session based on the application
    configuration"""
    engine = get_engine(config_file)
    if transactional:
        DBSession.configure(bind=engine)
        return DBSession
    else:
        NTDBSession.configure(bind=engine)
        return NTDBSession
Exemplo n.º 3
0
    def test_import_byname(self, import_item):
        from ringo.model.user import User
        from ringo.lib.imexport import JSONImporter
        from ringo.lib.sql import DBSession

        imported_items = JSONImporter(User).perform(json.dumps(import_item),
                                                    load_key="login")
        DBSession.flush()

        assert len(imported_items) == 1
        assert imported_items[0][1] == "CREATE"
        assert imported_items[0][0].login == import_item["login"]
Exemplo n.º 4
0
    def test_import(self, import_item):
        from ringo.model.user import User
        from ringo.lib.imexport import JSONImporter
        from ringo.lib.sql import DBSession
        from ringo.model.base import BaseFactory

        imported_items = JSONImporter(User).perform(json.dumps(import_item))
        DBSession.flush()

        assert len(imported_items) == 1
        assert imported_items[0][1] == "CREATE"
        assert (imported_items[0][0] is BaseFactory(User).load(
            imported_items[0][0].id))
Exemplo n.º 5
0
    def test_update_import_byid(self, import_item):
        from ringo.model.user import User
        from ringo.lib.imexport import JSONImporter
        from ringo.lib.sql import DBSession
        from ringo.model.base import BaseFactory

        imported_items = JSONImporter(User).perform(json.dumps(import_item),
                                                    load_key="id")
        DBSession.flush()

        assert len(imported_items) == 1
        assert imported_items[0][1] == "UPDATE"
        assert (BaseFactory(User).load(
            import_item["id"]).login == import_item["login"])
Exemplo n.º 6
0
def update_import_byuuid_item(import_item):
    from ringo.lib.sql import DBSession
    from ringo.model.user import User

    import_item["uuid"] = DBSession.query(
        User.uuid).filter(User.id == import_item["id"]).scalar()
    return import_item
Exemplo n.º 7
0
def load_user(login):
    """Will return the user with the given login
    name. If no user can be found with the given login "None" will be
    returned.

    :login: Login of the user as string
    :returns: User or None

    """
    return DBSession.query(User).filter_by(login=login).scalar()
Exemplo n.º 8
0
    def test_recursive_import(self, nested_import_item):
        from ringo.model.user import User
        from ringo.lib.imexport import JSONImporter
        from ringo.lib.sql import DBSession

        imported_items = JSONImporter(User).perform(
            json.dumps(nested_import_item))
        DBSession.flush()

        assert len(imported_items) == 1
        assert imported_items[0][1] == "CREATE"
        assert (imported_items[0][0].usergroup.name ==
                nested_import_item["usergroup"]["name"])
        assert (imported_items[0][0].profile[0].first_name ==
                nested_import_item["profile"][0]["first_name"])
        assert (len(imported_items[0][0].roles) == len(
            nested_import_item["roles"]))
        assert (imported_items[0][0].roles[0].name ==
                nested_import_item["roles"][0]["name"])
Exemplo n.º 9
0
def nested_import_items(nested_import_item):
    from ringo.lib.sql import DBSession
    from ringo.lib.imexport import JSONExporter
    from ringo.model.user import Usergroup, Role

    import_items = [nested_import_item, copy.deepcopy(nested_import_item)]
    import_items[1]["login"] = "******"

    # update-import relations of second item
    import_items[1]["usergroup"] = json.loads(
        JSONExporter(Usergroup, serialized=False).perform(
            DBSession.query(Usergroup).filter(
                Usergroup.name == 'users').one()))
    import_items[1]["roles"] = json.loads(
        JSONExporter(Role,
                     serialized=False).perform(DBSession.query(Role).all()))

    # Identifiable related object can appear multiple times
    import_items[0]["roles"][0]["uuid"] = str(uuid.uuid4())
    import_items[1]["roles"].append(import_items[0]["roles"][0])

    return import_items
Exemplo n.º 10
0
def load_user(login):
    """Will return the user with the given login
    name. If no user can be found with the given login "None" will be
    returned.

    :login: Login of the user as string
    :returns: User or None

    """
    try:
        return DBSession.query(User).filter_by(login=login).one()
    except NoResultFound:
        return None
Exemplo n.º 11
0
def load_user(login):
    """Will return the user with the given login
    name. If no user can be found with the given login "None" will be
    returned.

    :login: Login of the user as string
    :returns: User or None

    """
    try:
        return DBSession.query(User).filter_by(login=login).one()
    except NoResultFound:
        return None
Exemplo n.º 12
0
def import_model(clazzpath):
    """Will return the clazz defined by modul entry in the database of
    the given model. The clazzpath defines the base clazz which which
    defines the ID of the modul it belongs to.
    The function will first import the clazz and load the related modul
    entry for the model from the database. The we look for the clazzpath
    entry of the modul. If the moduls clazzpath is the same as the model
    clazzpath the return the imported model.
    If the clazzpath differs then import the model defined by the moduls
    clazzpath."""
    from ringo.model.modul import ModulItem
    orig_clazz = dynamic_import(clazzpath)
    # Load entry from the database for the given modul
    mid = orig_clazz._modul_id
    modul = DBSession.query(ModulItem).get(mid)
    if modul.clazzpath == clazzpath:
        return orig_clazz
    else:
        # TODO: Is this code ever reached? (ti) <2014-02-25 23:07>
        return import_model(modul.clazzpath)
Exemplo n.º 13
0
def import_model(clazzpath):
    """Will return the clazz defined by modul entry in the database of
    the given model. The clazzpath defines the base clazz which which
    defines the ID of the modul it belongs to.
    The function will first import the clazz and load the related modul
    entry for the model from the database. The we look for the clazzpath
    entry of the modul. If the moduls clazzpath is the same as the model
    clazzpath the return the imported model.
    If the clazzpath differs then import the model defined by the moduls
    clazzpath."""
    from ringo.model.modul import ModulItem
    orig_clazz = dynamic_import(clazzpath)
    # Load entry from the database for the given modul
    mid = orig_clazz._modul_id
    modul = DBSession.query(ModulItem).filter_by(id=mid).one()
    if modul.clazzpath == clazzpath:
        return orig_clazz
    else:
        # TODO: Is this code ever reached? (ti) <2014-02-25 23:07>
        return import_model(modul.clazzpath)
Exemplo n.º 14
0
    def test_recursive_import_multiple(self, nested_import_items):
        from ringo.model.user import User, Usergroup, Role
        from ringo.lib.imexport import JSONImporter
        from ringo.lib.sql import DBSession

        group_count = DBSession.query(Usergroup).count()
        role_count = DBSession.query(Role).count()
        imported_items = JSONImporter(User).perform(
            json.dumps(nested_import_items))
        DBSession.flush()

        assert len(imported_items) == 2
        assert all(i[1] == "CREATE" for i in imported_items)
        # plus automatically created and one imported (not updated) groups:
        assert (DBSession.query(Usergroup).count() == group_count +
                len(nested_import_items) + 1)
        # plus imported (not updated) groups:
        assert (DBSession.query(Role).count() == role_count +
                len(nested_import_items[0]["roles"]))
Exemplo n.º 15
0
Arquivo: auth.py Projeto: toirl/ringo
def is_login_unique(field, data):
    """Validator function as helper for formbar validators"""
    users = DBSession.query(User).filter_by(login=data[field]).all()
    return len(users) == 0
Exemplo n.º 16
0
def is_login_unique(field, data):
    """Validator function as helper for formbar validators"""
    users = DBSession.query(User).filter_by(login=data[field]).all()
    return len(users) == 0