コード例 #1
0
def setup_function(function):
    if db_session.bind.driver == 'pysqlite':

        @event.listens_for(Engine, "connect")
        def set_sqlite_pragma(dbapi_connection, connection_record):
            cursor = dbapi_connection.cursor()
            cursor.execute("PRAGMA foreign_keys=ON")
            cursor.close()

    from taskplus.apps.rest import models
    Base.metadata.reflect(engine)
    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)

    creator_role = models.UserRole(name='creator_role')
    doer_role = models.UserRole(name='doer_role')

    db_session.add(creator_role)
    db_session.add(doer_role)
    db_session.commit()

    creator = models.User(name='creator',
                          roles=[doer_role],
                          id=1,
                          password='******')
    db_session.add(creator)
    db_session.commit()
コード例 #2
0
def setup_function(function):
    if db_session.bind.driver == 'pysqlite':

        @event.listens_for(Engine, "connect")
        def set_sqlite_pragma(dbapi_connection, connection_record):
            cursor = dbapi_connection.cursor()
            cursor.execute("PRAGMA foreign_keys=ON")
            cursor.close()

    with mock.patch('taskplus.apps.rest.models.User._hash_password',
                    side_effect=lambda x: x):
        from taskplus.apps.rest import models
        Base.metadata.reflect(engine)
        Base.metadata.drop_all(engine)
        Base.metadata.create_all(engine)

        creator_role = models.UserRole(name='creator_role')
        doer_role = models.UserRole(name='doer_role')

        db_session.add(creator_role)
        db_session.add(doer_role)
        db_session.commit()

        creator = models.User(name='creator',
                              roles=[creator_role],
                              password='******')
        doer = models.User(name='doer', roles=[doer_role], password='******')

        db_session.add(creator)
        db_session.add(doer)
        db_session.commit()

        status_new = models.TaskStatus(id=Statuses.NEW, name='new')
        status_in_progress = models.TaskStatus(id=Statuses.IN_PROGRESS,
                                               name='in progress')

        db_session.add(status_new)
        db_session.add(status_in_progress)
        db_session.commit()

        task = models.Task(name='example task 1',
                           content='lorem ipsum',
                           status_id=status_new.id,
                           creator_id=creator.id,
                           doer_id=doer.id)
        task2 = models.Task(name='example task 2',
                            content='lorem ipsum 2',
                            status_id=status_new.id,
                            creator_id=creator.id,
                            doer_id=doer.id)

        db_session.add(task)
        db_session.add(task2)
        db_session.commit()
コード例 #3
0
def setup_function(function):
    if db_session.bind.driver == 'pysqlite':

        @event.listens_for(Engine, "connect")
        def set_sqlite_pragma(dbapi_connection, connection_record):
            cursor = dbapi_connection.cursor()
            cursor.execute("PRAGMA foreign_keys=ON")
            cursor.close()

    from taskplus.apps.rest import models
    Base.metadata.reflect(engine)
    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)

    creator_role = models.UserRole(name='creator')
    doer_role = models.UserRole(name='doer')
    admin_role = models.UserRole(name='admin')
    unused_role = models.UserRole(name='dummy')

    db_session.add(creator_role)
    db_session.add(doer_role)
    db_session.add(admin_role)
    db_session.add(unused_role)
    db_session.commit()

    creator = models.User(name='creator',
                          roles=[creator_role],
                          password='******')
    doer = models.User(name='doer', roles=[doer_role], password='******')
    super_user = models.User(name='super',
                             roles=[creator_role, doer_role, admin_role],
                             password='******')

    db_session.add(creator)
    db_session.add(doer)
    db_session.add(super_user)
    db_session.commit()

    status_new = models.TaskStatus(id=Statuses.NEW, name='new')
    status_in_progress = models.TaskStatus(id=Statuses.IN_PROGRESS,
                                           name='in progress')
    status_completed = models.TaskStatus(id=Statuses.COMPLETED,
                                         name='completed')
    status_canceled = models.TaskStatus(id=Statuses.CANCELED, name='canceled')

    db_session.add(status_new)
    db_session.add(status_in_progress)
    db_session.add(status_completed)
    db_session.add(status_canceled)
    db_session.commit()

    user = users_repository.one(3)
    authorization_manager.user = user
コード例 #4
0
def setup_function(function):
    user_ = namedtuple('user_', ['id', 'name', 'role_id', 'role_name'])
    creator_ = user_(id=1, name='creator', role_id=1, role_name='creator_role')
    doer_ = user_(id=2, name='doer', role_id=2, role_name='doer_role')

    if db_session.bind.driver == 'pysqlite':

        @event.listens_for(Engine, "connect")
        def set_sqlite_pragma(dbapi_connection, connection_record):
            cursor = dbapi_connection.cursor()
            cursor.execute("PRAGMA foreign_keys=ON")
            cursor.close()

    with mock.patch('taskplus.apps.rest.models.User._hash_password',
                    side_effect=lambda x: x):
        from taskplus.apps.rest import models
        Base.metadata.reflect(engine)
        Base.metadata.drop_all(engine)
        Base.metadata.create_all(engine)

        creator_role = models.UserRole(name=creator_.role_name,
                                       id=creator_.role_id)
        doer_role = models.UserRole(name=doer_.role_name, id=doer_.role_id)

        db_session.add(creator_role)
        db_session.add(doer_role)
        db_session.commit()

        creator = models.User(name=creator_.name,
                              roles=[creator_role],
                              id=creator_.id,
                              password='******')
        doer = models.User(name=doer_.name,
                           roles=[doer_role],
                           id=doer_.id,
                           password='******')

        db_session.add(creator)
        db_session.add(doer)
        db_session.commit()
コード例 #5
0
def setup_function(function):
    if db_session.bind.driver == 'pysqlite':

        @event.listens_for(Engine, "connect")
        def set_sqlite_pragma(dbapi_connection, connection_record):
            cursor = dbapi_connection.cursor()
            cursor.execute("PRAGMA foreign_keys=ON")
            cursor.close()

    from taskplus.apps.rest import models
    Base.metadata.reflect(engine)
    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)

    creator_role = models.UserRole(name='creator')
    doer_role = models.UserRole(name='doer')
    admin_role = models.UserRole(name='admin')
    unused_role = models.UserRole(name='dummy')

    db_session.add(creator_role)
    db_session.add(doer_role)
    db_session.add(admin_role)
    db_session.add(unused_role)
    db_session.commit()

    creator = models.User(name='creator',
                          roles=[creator_role],
                          password='******')
    doer = models.User(name='doer', roles=[doer_role], password='******')
    super_user = models.User(name='super',
                             roles=[creator_role, doer_role, admin_role],
                             password='******')

    db_session.add(creator)
    db_session.add(doer)
    db_session.add(super_user)
    db_session.commit()

    user = user_repository.one(3)
    authorization_manager.user = user
コード例 #6
0
def setup_function(function):
    if db_session.bind.driver == 'pysqlite':

        @event.listens_for(Engine, "connect")
        def set_sqlite_pragma(dbapi_connection, connection_record):
            cursor = dbapi_connection.cursor()
            cursor.execute("PRAGMA foreign_keys=ON")
            cursor.close()

    from taskplus.apps.rest import models
    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)

    status_new = models.TaskStatus(id=Statuses.NEW, name='new')
    status_in_progress = models.TaskStatus(id=Statuses.IN_PROGRESS,
                                           name='in progress')
    status_completed = models.TaskStatus(id=Statuses.COMPLETED,
                                         name='completed')
    status_canceled = models.TaskStatus(id=Statuses.CANCELED, name='canceled')

    db_session.add(status_new)
    db_session.add(status_in_progress)
    db_session.add(status_canceled)
    db_session.add(status_completed)
    db_session.commit()

    creator_role = models.UserRole(name='creator', id=1)
    db_session.add(creator_role)
    db_session.commit()

    creator = models.User(name='creator',
                          roles=[creator_role],
                          id=1,
                          password='******')

    db_session.add(creator)
    db_session.commit()

    task = models.Task(name='example task 1',
                       content='lorem ipsum',
                       status_id=2,
                       creator_id=creator.id,
                       doer_id=None)

    db_session.add(task)
    db_session.commit()
コード例 #7
0
def setup_function(function):
    if db_session.bind.driver == 'pysqlite':

        @event.listens_for(Engine, "connect")
        def set_sqlite_pragma(dbapi_connection, connection_record):
            cursor = dbapi_connection.cursor()
            cursor.execute("PRAGMA foreign_keys=ON")
            cursor.close()

    from taskplus.apps.rest import models
    Base.metadata.reflect(engine)
    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)

    roles = [
        models.UserRole(name=role.name, id=role.id) for role in user.roles
    ]

    for role in roles:
        db_session.add(role)

    db_session.commit()

    db_session.add(
        models.User(id=user.id, name=user.name, roles=roles, password='******'))

    db_session.add(
        models.User(id=user2.id,
                    name=user2.name,
                    roles=roles,
                    password='******'))

    db_session.commit()

    user_ = users_repository.one(1)
    authorization_manager.user = user_
コード例 #8
0
def create_db():
    # turn on foreign keys
    if db_session.bind.driver == 'pysqlite':

        @event.listens_for(Engine, "connect")
        def set_sqlite_pragma(dbapi_connection, connection_record):
            cursor = dbapi_connection.cursor()
            cursor.execute("PRAGMA foreign_keys=ON")
            cursor.close()

    from taskplus.apps.rest import models
    Base.metadata.reflect(engine)
    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)

    creator_role = models.UserRole(name='creator')
    doer_role = models.UserRole(name='doer')
    admin_role = models.UserRole(name='admin')

    db_session.add(creator_role)
    db_session.add(doer_role)
    db_session.add(admin_role)
    db_session.commit()

    creator = models.User(name='creator',
                          roles=[creator_role],
                          password='******')
    doer = models.User(name='doer', roles=[doer_role], password='******')
    super_user = models.User(name='super',
                             roles=[creator_role, doer_role, admin_role],
                             password='******')

    db_session.add(creator)
    db_session.add(doer)
    db_session.add(super_user)
    db_session.commit()

    status_new = models.TaskStatus(id=Statuses.NEW, name='new')
    status_in_progress = models.TaskStatus(id=Statuses.IN_PROGRESS,
                                           name='in progress')
    status_completed = models.TaskStatus(id=Statuses.COMPLETED,
                                         name='completed')
    status_canceled = models.TaskStatus(id=Statuses.CANCELED, name='canceled')

    db_session.add(status_new)
    db_session.add(status_in_progress)
    db_session.add(status_completed)
    db_session.add(status_canceled)
    db_session.commit()

    task = models.Task(name='example task 1',
                       content='lorem ipsum',
                       status_id=status_new.id,
                       creator_id=creator.id,
                       doer_id=doer.id)

    task2 = models.Task(name='example task 2',
                        content='lorem ipsum2',
                        status_id=status_completed.id,
                        creator_id=creator.id,
                        doer_id=doer.id)

    task3 = models.Task(name='example task 3',
                        content='lorem ipsum',
                        status_id=status_new.id,
                        creator_id=creator.id)

    db_session.add(task)
    db_session.add(task2)
    db_session.add(task3)
    db_session.commit()
コード例 #9
0
def setup_function(function):
    if db_session.bind.driver == 'pysqlite':

        @event.listens_for(Engine, "connect")
        def set_sqlite_pragma(dbapi_connection, connection_record):
            cursor = dbapi_connection.cursor()
            cursor.execute("PRAGMA foreign_keys=ON")
            cursor.close()

    from taskplus.apps.rest import models
    Base.metadata.reflect(engine)
    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)

    roles = [
        models.UserRole(name=role.name, id=role.id) for role in user.roles
    ]

    for role in roles:
        db_session.add(role)

    db_session.commit()

    db_session.add(
        models.User(id=user.id, name=user.name, roles=roles, password='******'))

    db_session.add(
        models.User(id=user2.id,
                    name=user2.name,
                    roles=roles,
                    password='******'))

    db_session.commit()

    status_new = models.TaskStatus(id=Statuses.NEW, name='new')
    status_in_progress = models.TaskStatus(id=Statuses.IN_PROGRESS,
                                           name='in progress')
    status_completed = models.TaskStatus(id=Statuses.COMPLETED,
                                         name='completed')
    status_canceled = models.TaskStatus(id=Statuses.CANCELED, name='canceled')

    db_session.add(status_new)
    db_session.add(status_in_progress)
    db_session.add(status_completed)
    db_session.add(status_canceled)
    db_session.commit()

    db_session.add(
        models.Task(id=task.id,
                    name=task.name,
                    content=task.content,
                    status_id=task.status.id,
                    creator_id=task.creator.id,
                    doer_id=task.doer.id))

    db_session.add(
        models.Task(id=task2.id,
                    name=task2.name,
                    content=task2.content,
                    status_id=task2.status.id,
                    creator_id=task2.creator.id,
                    doer_id=task2.doer.id))

    db_session.add(
        models.Task(
            id=task3.id,
            name=task3.name,
            content=task3.content,
            status_id=task3.status.id,
            creator_id=task3.creator.id,
        ))

    db_session.commit()

    user_ = users_repository.one(1)
    authorization_manager.user = user_