示例#1
0
    def test_user_project_manager__logged_in_as_admin(self):
        httpretty.enable()

        from osmtm.models import User, DBSession
        import transaction

        userid = 5463
        username = u'simon_user'
        user = User(userid, username)
        DBSession.add(user)
        DBSession.flush()
        transaction.commit()

        httpretty.register_uri(
            httpretty.GET,
            "http://www.openstreetmap.org/api/0.6/user/%s" % userid,
            body='<?xml version="1.0" encoding="UTF-8"?>' +
            '<osm> <user display_name="%s"></user></osm>' % username,
            content_type='application/xml; charset=utf-8')

        headers = self.login_as_admin()
        res = self.testapp.get('/user/%d/project_manager' % userid,
                               headers=headers,
                               status=302)
        res2 = res.follow(headers=headers, status=200)
        self.failUnless('This user is a project manager' in res2.body)

        DBSession.delete(user)
        transaction.commit()
示例#2
0
    def test_user__username_change(self):
        httpretty.enable()

        from osmtm.models import User, DBSession
        import transaction

        userid = 11
        username = u'new_user'
        user = User(userid, username)
        DBSession.add(user)
        DBSession.flush()
        transaction.commit()

        new_username = username + '_changed'
        httpretty.register_uri(
            httpretty.GET,
            "http://www.openstreetmap.org/api/0.6/user/%s" % userid,
            body='<?xml version="1.0" encoding="UTF-8"?>' +
            '<osm> <user display_name="%s"></user></osm>' % new_username,
            content_type='application/xml; charset=utf-8')

        self.testapp.get('/user/%s' % username, status=302)

        user = DBSession.query(User).get(userid)
        self.assertEqual(user.username, new_username)

        DBSession.delete(user)
        transaction.commit()
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()
示例#4
0
    def test_user_admin__logged_in_as_admin(self):

        from osmtm.models import User, DBSession
        import transaction

        userid = 5463
        username = u'dude_user'
        user = User(userid, username, False)
        DBSession.add(user)
        DBSession.flush()
        transaction.commit()

        headers = self.login_as_admin()
        res = self.testapp.get('/user/%d/admin' % userid, headers=headers,
                               status=302)
        res2 = res.follow(headers=headers, status=200)
        self.failUnless('dude_user' in res2.body)
        self.failUnless('This user is an administrator' in res2.body)

        DBSession.delete(user)
        transaction.commit()
示例#5
0
    def test_user__username_with_accents(self):
        httpretty.enable()

        from osmtm.models import User, DBSession
        import transaction

        userid = 12
        username = u'new_user_éà'
        user = User(userid, username)
        DBSession.add(user)
        DBSession.flush()
        transaction.commit()

        httpretty.register_uri(
            httpretty.GET,
            "http://www.openstreetmap.org/api/0.6/user/%s" % userid,
            body='<?xml version="1.0" encoding="UTF-8"?>' +
            '<osm> <user display_name="%s"></user></osm>' % username,
            content_type='application/xml; charset=utf-8')

        headers = self.login_as_user(userid)
        self.testapp.get('/project/1/task/4/lock',
                         status=200,
                         headers=headers,
                         xhr=True)
        self.testapp.get('/project/1/task/4/done',
                         status=200,
                         headers=headers,
                         params={'comment': 'some_comment'},
                         xhr=True)

        self.testapp.get((u'/user/%s' % username).encode('utf8'), status=200)

        self.testapp.get('/project/1/task/4',
                         status=200,
                         headers=headers,
                         xhr=True)
        f.write(';\n')
f.close()

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: