Пример #1
0
def populate_db():
    import geoalchemy2
    import shapely

    testing.setUp()
    config = ConfigParser.ConfigParser()
    config.read(local_settings_path)
    db_url = config.get('app:main', 'sqlalchemy.url')
    engine = create_engine(db_url)
    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)
    DBSession.configure(bind=engine)

    # those users are immutables ie. they're not suppose to change during tests
    user = User(USER1_ID, u'user1')
    DBSession.add(user)

    user = User(USER2_ID, u'user2')
    DBSession.add(user)

    user = User(ADMIN_USER_ID, u'admin_user')
    user.role = User.role_admin
    DBSession.add(user)

    user = User(PROJECT_MANAGER_USER_ID, u'project_manager_user')
    user.role = User.role_project_manager
    DBSession.add(user)

    license = License()
    license.name = u'LicenseBar'
    license.description = u'the_description_for_license_bar'
    license.plain_text = u'the_plain_text_for_license_bar'
    DBSession.add(license)

    shape = shapely.geometry.Polygon([(7.23, 41.25), (7.23, 41.12),
                                      (7.41, 41.20)])
    geometry = geoalchemy2.shape.from_shape(shape, 4326)
    area = Area(geometry)
    project = Project(u'test project')
    project.area = area
    project.auto_fill(12)
    project.status = Project.status_published
    DBSession.add(project)

    transaction.commit()
    DBSession.remove()
Пример #2
0
def populate_db():
    import geoalchemy2
    import shapely

    config = ConfigParser.ConfigParser()
    config.read(local_settings_path)
    db_url = config.get('app:main', 'sqlalchemy.url')
    engine = create_engine(db_url)
    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)

    DBSession.configure(bind=engine)

    # those users are immutables ie. they're not suppose to change during tests
    user = User(USER1_ID, u'user1')
    DBSession.add(user)

    user = User(USER2_ID, u'user2')
    DBSession.add(user)

    user = User(ADMIN_USER_ID, u'admin_user')
    user.role = User.role_admin
    DBSession.add(user)

    user = User(PROJECT_MANAGER_USER_ID, u'project_manager_user')
    user.role = User.role_project_manager
    DBSession.add(user)

    license = License()
    license.name = u'LicenseBar'
    license.description = u'the_description_for_license_bar'
    license.plain_text = u'the_plain_text_for_license_bar'
    DBSession.add(license)

    shape = shapely.geometry.Polygon(
        [(7.23, 41.25), (7.23, 41.12), (7.41, 41.20)])
    geometry = geoalchemy2.shape.from_shape(shape, 4326)
    area = Area(geometry)
    project = Project(u'test project')
    project.area = area
    project.auto_fill(12)
    project.status = Project.status_published
    DBSession.add(project)

    transaction.commit()
    DBSession.remove()
Пример #3
0
print "%d users found" % len(users)

header("Importing users in v2")
# inverting users mapping, key is now id
users_by_id = {v: k for k, v in users.items()}

users_count = 0
with transaction.manager:
    for id in users_by_id:
        username = users_by_id[id].decode('utf-8')
        if id != -1:
            user = User(id, username)
            v1_user = session_v1.query(users_table).filter(users_table.c.username == username).one()
            if v1_user.admin:
                user.role = user.role_project_manager

            session_v2.add(user)
            users_count += 1
    session_v2.flush()

success("%d users - successfully imported" % (users_count))

header("Importing licenses")
with transaction.manager:
    query = session_v1.query(licenses).all()
    for l in query:
        license = License()
        license.id = l.id
        license.name = l.name
        license.description = l.description
Пример #4
0
print "%d users found" % len(users)

header("Importing users in v2")
# inverting users mapping, key is now id
users_by_id = {v: k for k, v in users.items()}

users_count = 0
with transaction.manager:
    for id in users_by_id:
        username = users_by_id[id].decode('utf-8')
        if id != -1:
            user = User(id, username)
            v1_user = session_v1.query(users_table).filter(
                users_table.c.username == username).one()
            if v1_user.admin:
                user.role = user.role_project_manager

            session_v2.add(user)
            users_count += 1
    session_v2.flush()

success("%d users - successfully imported" % (users_count))

header("Importing licenses")
with transaction.manager:
    query = session_v1.query(licenses).all()
    for l in query:
        license = License()
        license.id = l.id
        license.name = l.name
        license.description = l.description
Пример #5
0
def populate_db():
    import geoalchemy2
    import shapely

    testing.setUp()
    config = ConfigParser.ConfigParser()
    config.read(local_settings_path)
    db_url = config.get('app:main', 'sqlalchemy.url')
    engine = create_engine(db_url)
    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)
    DBSession.configure(bind=engine)

    # those users are immutables ie. they're not suppose to change during tests
    user = User(USER1_ID, u'user1')
    DBSession.add(user)

    user = User(USER2_ID, u'user2')
    DBSession.add(user)

    user = User(ADMIN_USER_ID, u'admin_user')
    user.role = User.role_admin
    DBSession.add(user)

    user = User(PROJECT_MANAGER_USER_ID, u'project_manager_user')
    user.role = User.role_project_manager
    DBSession.add(user)

    user = User(VALIDATOR_ID, u'user_validator')
    user.role = User.role_validator
    DBSession.add(user)

    user = User(EXPERIENCED_MAPPER_ID, u'user_experienced_mapper')
    user.role = User.role_experienced_mapper
    DBSession.add(user)

    license = License()
    license.name = u'LicenseBar'
    license.description = u'the_description_for_license_bar'
    license.plain_text = u'the_plain_text_for_license_bar'
    DBSession.add(license)

    label0 = Label()
    label0.name = u'bar'
    label0.color = u'#ff0000'
    DBSession.add(label0)

    label1 = Label()
    label1.name = u'dude label'
    label1.color = u'#ff0000'
    DBSession.add(label1)

    shape = shapely.geometry.Polygon(
        [(7.23, 41.25), (7.23, 41.12), (7.41, 41.20)])
    geometry = geoalchemy2.shape.from_shape(shape, 4326)
    area = Area(geometry)
    project = Project(u'test project')
    project.short_description = u'lorem ipsum description'
    project.area = area
    project.auto_fill(12)
    project.status = Project.status_published
    project.labels = [label0, label1]
    DBSession.add(project)

    transaction.commit()
    DBSession.remove()